diff options
author | Pavel Zhukov <pavel@zhukoff.net> | 2022-08-26 10:40:30 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-08-31 12:21:17 +0100 |
commit | c5fcdd804d422f959a189b270d72123a50e74da6 (patch) | |
tree | c94cf9126b4f586ece3ec24d2139266800ba0783 /lib/bb/tests/fetch.py | |
parent | 0361ecf7eb82c386a9842cf1f3cb706c0a112e77 (diff) | |
download | bitbake-c5fcdd804d422f959a189b270d72123a50e74da6.tar.gz |
tests: Add Timeout class
The class and exception aim to test rare cases there deadlocks are
possible.
Can be used in context managers:
with Timeout(<value>):
do_deadlock()
Signed-off-by: Pavel Zhukov <pavel@zhukoff.net>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/bb/tests/fetch.py')
-rw-r--r-- | lib/bb/tests/fetch.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py index 7fcf57e7e..e69b4b05f 100644 --- a/lib/bb/tests/fetch.py +++ b/lib/bb/tests/fetch.py @@ -11,6 +11,7 @@ import hashlib import tempfile import collections import os +import signal import tarfile from bb.fetch2 import URI from bb.fetch2 import FetchMethod @@ -22,6 +23,24 @@ def skipIfNoNetwork(): return unittest.skip("network test") return lambda f: f +class TestTimeout(Exception): + pass + +class Timeout(): + + def __init__(self, seconds): + self.seconds = seconds + + def handle_timeout(self, signum, frame): + raise TestTimeout("Test failed: timeout reached") + + def __enter__(self): + signal.signal(signal.SIGALRM, self.handle_timeout) + signal.alarm(self.seconds) + + def __exit__(self, exc_type, exc_val, exc_tb): + signal.alarm(0) + class URITest(unittest.TestCase): test_uris = { "http://www.google.com/index.html" : { |