aboutsummaryrefslogtreecommitdiffstats
path: root/test/framework.py
diff options
context:
space:
mode:
authorPaul Vinciguerra <pvinci@vinciconsulting.com>2019-03-10 09:10:54 -0700
committerOle Trøan <otroan@employees.org>2019-03-11 08:10:34 +0000
commit0f6602cb246894ea98253e16aae198094bf78694 (patch)
tree7fd7839f18ba701fe390308e17e035eb6850348b /test/framework.py
parentd3a9be2ca0b527bfeac808a822319e69e0d7fe76 (diff)
Tests: fix time.sleep(0) # yield. Reduce sleep related log messages.
Reduce the incidence of: 20:04:23,606 unexpected time.sleep() result - slept for 2.187967e-03s instead of ~6.837845e-04s! Change-Id: Ic576fda7f75e571c9019111588a6a936ee2cf5c2 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
Diffstat (limited to 'test/framework.py')
-rw-r--r--test/framework.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/test/framework.py b/test/framework.py
index 778832f401d..2c1c8291ed1 100644
--- a/test/framework.py
+++ b/test/framework.py
@@ -390,7 +390,7 @@ class VppTestCase(unittest.TestCase):
if os.path.exists(cls.stats_sock):
ok = True
break
- time.sleep(0.8)
+ cls.sleep(0.8)
if not ok:
cls.logger.critical("Couldn't stat : {}".format(cls.stats_sock))
@@ -951,13 +951,26 @@ class VppTestCase(unittest.TestCase):
@classmethod
def sleep(cls, timeout, remark=None):
+
+ # /* Allow sleep(0) to maintain win32 semantics, and as decreed
+ # * by Guido, only the main thread can be interrupted.
+ # */
+ # https://github.com/python/cpython/blob/6673decfa0fb078f60587f5cb5e98460eea137c2/Modules/timemodule.c#L1892 # noqa
+ if timeout == 0:
+ # yield quantum
+ if hasattr(os, 'sched_yield'):
+ os.sched_yield()
+ else:
+ time.sleep(0)
+ return
+
if hasattr(cls, 'logger'):
cls.logger.debug("Starting sleep for %es (%s)", timeout, remark)
before = time.time()
time.sleep(timeout)
after = time.time()
if hasattr(cls, 'logger') and after - before > 2 * timeout:
- cls.logger.error("unexpected time.sleep() result - "
+ cls.logger.error("unexpected self.sleep() result - "
"slept for %es instead of ~%es!",
after - before, timeout)
if hasattr(cls, 'logger'):