aboutsummaryrefslogtreecommitdiffstats
path: root/test
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
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')
-rw-r--r--test/framework.py17
-rw-r--r--test/test_bfd.py4
-rw-r--r--test/vpp_papi_provider.py2
-rw-r--r--test/vpp_pg_interface.py6
4 files changed, 21 insertions, 8 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'):
diff --git a/test/test_bfd.py b/test/test_bfd.py
index a450a335527..7b474228eb6 100644
--- a/test/test_bfd.py
+++ b/test/test_bfd.py
@@ -1065,7 +1065,7 @@ class BFD4TestCase(VppTestCase):
/ USEC_IN_SEC
count = 0
for dummy in range(self.test_session.detect_mult * 2):
- time.sleep(transmit_time)
+ self.sleep(transmit_time)
self.test_session.send_packet(demand)
try:
p = wait_for_bfd_packet(self, timeout=0)
@@ -1448,7 +1448,7 @@ class BFD4TestCase(VppTestCase):
/ USEC_IN_SEC
count = 0
for dummy in range(self.test_session.detect_mult * 2):
- time.sleep(transmit_time)
+ self.sleep(transmit_time)
self.test_session.send_packet(demand)
try:
p = wait_for_bfd_packet(self, timeout=0)
diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py
index 37f63c060d4..fca57c37880 100644
--- a/test/vpp_papi_provider.py
+++ b/test/vpp_papi_provider.py
@@ -303,7 +303,7 @@ class VppPapiProvider(object):
self.test_class.logger.debug("Returning event %s:%s" %
(name, e))
return e
- time.sleep(0) # yield
+ self.test_class.sleep(0) # yield
raise Exception("Event did not occur within timeout")
def __call__(self, name, event):
diff --git a/test/vpp_pg_interface.py b/test/vpp_pg_interface.py
index 1300f1f1f00..b22a93388a6 100644
--- a/test/vpp_pg_interface.py
+++ b/test/vpp_pg_interface.py
@@ -285,7 +285,7 @@ class VppPGInterface(VppInterface):
while time.time() < deadline:
if os.path.isfile(self.out_path):
break
- time.sleep(0) # yield
+ self._test.sleep(0) # yield
if os.path.isfile(self.out_path):
self.test.logger.debug("Capture file appeared after %fs" %
(time.time() - (deadline - timeout)))
@@ -353,7 +353,7 @@ class VppPGInterface(VppInterface):
self.test.logger.debug("Polling for packet")
while time.time() < deadline or poll:
if not self.verify_enough_packet_data_in_pcap():
- time.sleep(0) # yield
+ self._test.sleep(0) # yield
poll = False
continue
p = self._pcap_reader.recv()
@@ -367,7 +367,7 @@ class VppPGInterface(VppInterface):
"Packet received after %fs" %
(time.time() - (deadline - timeout)))
return p
- time.sleep(0) # yield
+ self._test.sleep(0) # yield
poll = False
self.test.logger.debug("Timeout - no packets received")
raise CaptureTimeoutError("Packet didn't arrive within timeout")