@@ -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" : {
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> --- lib/bb/tests/fetch.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)