From f1e9cc2559ce9e163484a9a80f5e3a1044306e26 Mon Sep 17 00:00:00 2001 From: J08nY Date: Mon, 11 Aug 2025 13:29:15 +0200 Subject: Add no-wait futures.as_completed. --- test/misc/test_utils.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'test') 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 -- cgit v1.2.3-70-g09d2