mirror of
git://git.yoctoproject.org/poky.git
synced 2025-07-19 12:59:02 +02:00
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>
This commit is contained in:
parent
0abd64b3af
commit
492ec14a37
|
@ -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" : {
|
||||
|
|
Loading…
Reference in New Issue
Block a user