Skip to content

Commit 3c786f7

Browse files
rwgkcursoragent
andcommitted
[ci skip] fix(tests): make async callback test deterministic
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>
1 parent 44a0cd2 commit 3c786f7

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tests/test_callbacks.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,11 @@ def gen_f():
179179
# do some work async
180180
work = [1, 2, 3, 4]
181181
m.test_async_callback(gen_f(), work)
182-
# wait until work is done
183-
from time import sleep
184-
185-
sleep(0.5)
182+
# Wait for all detached worker threads to finish.
183+
deadline = time.monotonic() + 5.0
184+
while len(res) < len(work) and time.monotonic() < deadline:
185+
time.sleep(0.01)
186+
assert len(res) == len(work), f"Timed out waiting for callbacks: res={res!r}"
186187
assert sum(res) == sum(x + 3 for x in work)
187188

188189

0 commit comments

Comments
 (0)