mirror of
https://git.yoctoproject.org/poky
synced 2026-09-19 18:49:32 +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:
committed by
Richard Purdie
parent
0abd64b3af
commit
492ec14a37
@@ -11,6 +11,7 @@ import hashlib
|
|||||||
import tempfile
|
import tempfile
|
||||||
import collections
|
import collections
|
||||||
import os
|
import os
|
||||||
|
import signal
|
||||||
import tarfile
|
import tarfile
|
||||||
from bb.fetch2 import URI
|
from bb.fetch2 import URI
|
||||||
from bb.fetch2 import FetchMethod
|
from bb.fetch2 import FetchMethod
|
||||||
@@ -22,6 +23,24 @@ def skipIfNoNetwork():
|
|||||||
return unittest.skip("network test")
|
return unittest.skip("network test")
|
||||||
return lambda f: f
|
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):
|
class URITest(unittest.TestCase):
|
||||||
test_uris = {
|
test_uris = {
|
||||||
"http://www.google.com/index.html" : {
|
"http://www.google.com/index.html" : {
|
||||||
|
|||||||
Reference in New Issue
Block a user