summaryrefslogtreecommitdiff
path: root/testing/embedding
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2019-10-15 11:24:19 +0200
committerArmin Rigo <arigo@tunes.org>2019-10-15 11:24:19 +0200
commit3f3e8e2db85dd6299aaf0a60d8dd6858ecb99fd0 (patch)
treea6726502d93d056dc3bbe71c6b8877d0e4850526 /testing/embedding
parent2e1c8e4f059b1ae7cc06a1f45f40bbbf9d08f5d0 (diff)
downloadcffi-3f3e8e2db85dd6299aaf0a60d8dd6858ecb99fd0.tar.gz
Windows fix: sometimes, time.sleep() doesn't sleep apparently
Diffstat (limited to 'testing/embedding')
-rw-r--r--testing/embedding/add1.py6
-rw-r--r--testing/embedding/test_thread.py26
2 files changed, 20 insertions, 12 deletions
diff --git a/testing/embedding/add1.py b/testing/embedding/add1.py
index e5b3de1..6f89ae9 100644
--- a/testing/embedding/add1.py
+++ b/testing/embedding/add1.py
@@ -11,7 +11,11 @@ ffi.embedding_init_code(r"""
sys.stdout.write("preparing")
for i in range(3):
sys.stdout.flush()
- time.sleep(0.2)
+ # Windows: sometimes time.sleep() doesn't sleep at all.
+ # This appears to occur on recent versions of python only.
+ t_end = time.time() + 0.19
+ while time.time() < t_end:
+ time.sleep(0.2)
sys.stdout.write(".")
sys.stdout.write("\n")
diff --git a/testing/embedding/test_thread.py b/testing/embedding/test_thread.py
index 1895076..9a5936d 100644
--- a/testing/embedding/test_thread.py
+++ b/testing/embedding/test_thread.py
@@ -21,17 +21,21 @@ class TestThread(EmbeddingTests):
add1_cffi = self.prepare_module('add1')
add2_cffi = self.prepare_module('add2')
self.compile('thread2-test', [add1_cffi, add2_cffi], threads=True)
- output = self.execute('thread2-test')
- output = self._take_out(output, "preparing")
- output = self._take_out(output, ".")
- output = self._take_out(output, ".")
- # at least the 3rd dot should be after everything from ADD2
- assert output == ("starting\n"
- "prepADD2\n"
- "adding 1000 and 200 and 30\n"
- ".\n"
- "adding 40 and 2\n"
- "done\n")
+ for i in range(3):
+ output = self.execute('thread2-test')
+ print('='*79)
+ print(output)
+ print('='*79)
+ output = self._take_out(output, "preparing")
+ output = self._take_out(output, ".")
+ output = self._take_out(output, ".")
+ # at least the 3rd dot should be after everything from ADD2
+ assert output == ("starting\n"
+ "prepADD2\n"
+ "adding 1000 and 200 and 30\n"
+ ".\n"
+ "adding 40 and 2\n"
+ "done\n")
def test_alt_issue(self):
add1_cffi = self.prepare_module('add1')