Skip to content

Commit e3d8f58

Browse files
committed
Race safety in handle tests
1 parent 7a420aa commit e3d8f58

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

tests/test_handles.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import threading
2-
import time
32

43
import pytest
54

@@ -40,15 +39,15 @@ def _test_ack(
4039

4140
def do_ack() -> None:
4241
start.wait()
43-
time.sleep(0.001)
4442
with cond:
4543
handle.ack = ack # type: ignore[assignment]
4644
cond.notify_all()
4745
thread = threading.Thread(target=do_ack)
4846
thread.start()
4947

50-
start.set()
51-
assert handle.wait_for_ack(timeout=0.01) == ack
48+
with cond:
49+
start.set()
50+
assert handle.wait_for_ack(timeout=0.01) == ack
5251

5352
thread.join()
5453

@@ -65,16 +64,16 @@ def _test_exc(
6564

6665
def do_ack() -> None:
6766
start.wait()
68-
time.sleep(0.001)
6967
with cond:
7068
handle.exc = ValueError("TEST")
7169
cond.notify_all()
7270
thread = threading.Thread(target=do_ack)
7371
thread.start()
7472

75-
start.set()
76-
with pytest.raises(ValueError, match="TEST"):
77-
handle.wait_for_ack(timeout=0.01)
73+
with cond:
74+
start.set()
75+
with pytest.raises(ValueError, match="TEST"):
76+
handle.wait_for_ack(timeout=0.01)
7877

7978
thread.join()
8079

0 commit comments

Comments
 (0)