diff options
author | Pavel Zhukov <pavel@zhukoff.net> | 2022-08-26 10:40:30 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-09-01 10:07:00 +0100 |
commit | 492ec14a372f6504ad232f60334823af27366cef (patch) | |
tree | f1cedb4f0843bda87175fd79ea6da2aca6a34199 /bitbake/lib/bb/tests/fetch.py | |
parent | 0abd64b3afd7e649831bfbcb46299939ec4aceaa (diff) | |
download | poky-492ec14a372f6504ad232f60334823af27366cef.tar.gz |
bitbake: 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()
(Bitbake rev: c5fcdd804d422f959a189b270d72123a50e74da6)
Signed-off-by: Pavel Zhukov <pavel@zhukoff.net>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/tests/fetch.py')
-rw-r--r-- | bitbake/lib/bb/tests/fetch.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py index 7fcf57e7ea..e69b4b05f3 100644 --- a/bitbake/lib/bb/tests/fetch.py +++ b/bitbake/lib/bb/tests/fetch.py | |||
@@ -11,6 +11,7 @@ import hashlib | |||
11 | import tempfile | 11 | import tempfile |
12 | import collections | 12 | import collections |
13 | import os | 13 | import os |
14 | import signal | ||
14 | import tarfile | 15 | import tarfile |
15 | from bb.fetch2 import URI | 16 | from bb.fetch2 import URI |
16 | from bb.fetch2 import FetchMethod | 17 | from bb.fetch2 import FetchMethod |
@@ -22,6 +23,24 @@ def skipIfNoNetwork(): | |||
22 | return unittest.skip("network test") | 23 | return unittest.skip("network test") |
23 | return lambda f: f | 24 | return lambda f: f |
24 | 25 | ||
26 | class TestTimeout(Exception): | ||
27 | pass | ||
28 | |||
29 | class Timeout(): | ||
30 | |||
31 | def __init__(self, seconds): | ||
32 | self.seconds = seconds | ||
33 | |||
34 | def handle_timeout(self, signum, frame): | ||
35 | raise TestTimeout("Test failed: timeout reached") | ||
36 | |||
37 | def __enter__(self): | ||
38 | signal.signal(signal.SIGALRM, self.handle_timeout) | ||
39 | signal.alarm(self.seconds) | ||
40 | |||
41 | def __exit__(self, exc_type, exc_val, exc_tb): | ||
42 | signal.alarm(0) | ||
43 | |||
25 | class URITest(unittest.TestCase): | 44 | class URITest(unittest.TestCase): |
26 | test_uris = { | 45 | test_uris = { |
27 | "http://www.google.com/index.html" : { | 46 | "http://www.google.com/index.html" : { |