Commit 735b840
test: sequence the cancellation test with events, not sleeps
The test raced. It relied on a fixed `time.sleep(0.3)` in the worker outlasting an
`await asyncio.sleep(0.05)` before `task.cancel()`. On a loaded runner the conversion
could finish first, leaving nothing to cancel, and the test would fail with
"DID NOT RAISE" -- a spurious failure rather than a real one.
Now sequenced with three `threading.Event` handshakes: the worker signals that it has
entered the conversion, the test cancels only after that, and only then releases the
worker, so completion is necessarily post-cancellation. A spy on
`_discard_elements_file` signals that cleanup ran, so the assertion waits on the
actual event rather than polling the filesystem on a timer. The `wait` timeouts are
deadlock guards, never a duration anything waits out.
Also drops the 0.02s x 200 polling loop, so the test now takes ~0.15s instead of
~0.5s, and reports "cleanup never ran" instead of a bare assertion when it fails.
Still confirmed to fail against the plain awaited to_thread. Ran 20x clean, and 10x
clean under eight busy cores.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 19ca812 commit 735b840
1 file changed
Lines changed: 28 additions & 10 deletions
Lines changed: 28 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
| |||
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
| |||
763 | 765 | | |
764 | 766 | | |
765 | 767 | | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
766 | 773 | | |
767 | 774 | | |
768 | 775 | | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
769 | 780 | | |
| 781 | + | |
770 | 782 | | |
771 | | - | |
772 | | - | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
773 | 786 | | |
774 | 787 | | |
775 | | - | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
776 | 794 | | |
777 | 795 | | |
778 | 796 | | |
779 | 797 | | |
780 | 798 | | |
781 | | - | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
782 | 802 | | |
783 | 803 | | |
784 | 804 | | |
785 | 805 | | |
786 | | - | |
787 | | - | |
788 | | - | |
789 | | - | |
790 | | - | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
791 | 809 | | |
792 | 810 | | |
793 | 811 | | |
| |||
0 commit comments