forked from avocado-framework/avocado
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit introduces a new timeout feature, which adds the possibility to set a specific timeout for a block of code with context manager like this: with self.wait_max(3): #code which should take max 3 seconds ... The `wait_max` method will send `SIGTERM` if the code doesn't end within 3 seconds. This signal will be caught by avocado-instrumented runner, which will interrupt the test, the same way as with a regular timeout. Reference: avocado-framework#5994 Signed-off-by: Jan Richter <[email protected]>
- Loading branch information
Showing
5 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import time | ||
|
||
from avocado import Test | ||
|
||
|
||
class TimeoutTest(Test): | ||
""" | ||
Functional test for avocado. Throw a TestTimeoutError. | ||
:param sleep_time: How long should the test sleep | ||
""" | ||
|
||
def test(self): | ||
""" | ||
This should throw a TestTimeoutError. | ||
""" | ||
with self.wait_max(3): | ||
sleep_time = float(self.params.get("sleep_time", default=5.0)) | ||
self.log.info( | ||
"Sleeping for %.2f seconds (2 more than the timeout)", sleep_time | ||
) | ||
time.sleep(sleep_time) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters