mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
[ci skip] fix(tests): make async callback test deterministic (#5986)
Replace the fixed sleep in test_async_callbacks with a bounded wait for all expected callback results, so detached worker scheduling no longer causes sporadic CI failures. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
committed by
GitHub
parent
ac286c932f
commit
1a863647c5
@@ -179,10 +179,11 @@ def test_async_callbacks():
|
||||
# do some work async
|
||||
work = [1, 2, 3, 4]
|
||||
m.test_async_callback(gen_f(), work)
|
||||
# wait until work is done
|
||||
from time import sleep
|
||||
|
||||
sleep(0.5)
|
||||
# Wait for all detached worker threads to finish.
|
||||
deadline = time.monotonic() + 5.0
|
||||
while len(res) < len(work) and time.monotonic() < deadline:
|
||||
time.sleep(0.01)
|
||||
assert len(res) == len(work), f"Timed out waiting for callbacks: res={res!r}"
|
||||
assert sum(res) == sum(x + 3 for x in work)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user