aboutsummaryrefslogtreecommitdiff
path: root/test/misc/test_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/misc/test_utils.py')
-rw-r--r--test/misc/test_utils.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/test/misc/test_utils.py b/test/misc/test_utils.py
index 72ce711..d4409ed 100644
--- a/test/misc/test_utils.py
+++ b/test/misc/test_utils.py
@@ -1,4 +1,4 @@
-
+import time
from pyecsca.misc.utils import TaskExecutor
@@ -6,6 +6,11 @@ def run(a, b):
return a + b
+def wait(a, b):
+ time.sleep(1)
+ return a + b
+
+
def test_executor():
with TaskExecutor(max_workers=2) as pool:
for i in range(10):
@@ -15,3 +20,16 @@ def test_executor():
for i, future in pool.as_completed():
res = future.result()
assert res == i + 5
+
+
+def test_executor_no_wait():
+ with TaskExecutor(max_workers=2) as pool:
+ for i in range(2):
+ pool.submit_task(i,
+ wait,
+ i, 5)
+ futures = list(pool.as_completed(wait=False))
+ assert len(futures) == 0
+ time.sleep(2.5)
+ futures = list(pool.as_completed(wait=False))
+ assert len(futures) == 2