Commit fc288ad
Fix flaky sync client recreate tests by joining the recreate thread (#214)
The synchronous client's fire-and-forget recreate thread signals
`_recreate_done_event` from inside `_run_recreate`'s `finally` block, so
the event becomes set while the thread is still alive.
`_schedule_recreate` single-flights on `existing.is_alive()` and its early
return sits *before* `_recreate_done_event.clear()`. A trigger issued in
that window is therefore dropped and the event is left set from the
previous recreate, so the next `wait()` returns immediately off the stale
signal and assertions about the following recreate fail.
Two tests chained recreates through this pattern and were intermittently
flaky under CPU contention:
- test_sync_client_close_closes_all_retired_sdk_channels_immediately
- test_sync_client_recreate_cooldown_prevents_immediate_repeated_recreation
Add an `await_sync_recreate` helper that waits on the event and then joins
the recreate thread, so `is_alive()` is deterministically False before the
next trigger is issued, and use it at all five wait sites.
This is a test-synchronization defect only; the production single-flight
behaviour is correct and intentional, so no production code changes. The
async client is unaffected -- it gates on `asyncio.Task.done()`.
Fixes #212
Co-authored-by: Bernd Verst <beverst@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 677577fc-869c-463f-9243-0f4802a9f0401 parent 2269c44 commit fc288ad
1 file changed
Lines changed: 31 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
217 | | - | |
218 | | - | |
219 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
220 | 221 | | |
221 | 222 | | |
222 | 223 | | |
| |||
241 | 242 | | |
242 | 243 | | |
243 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
244 | 267 | | |
245 | 268 | | |
246 | 269 | | |
| |||
669 | 692 | | |
670 | 693 | | |
671 | 694 | | |
672 | | - | |
| 695 | + | |
673 | 696 | | |
674 | 697 | | |
675 | | - | |
| 698 | + | |
676 | 699 | | |
677 | 700 | | |
678 | 701 | | |
| |||
912 | 935 | | |
913 | 936 | | |
914 | 937 | | |
915 | | - | |
| 938 | + | |
916 | 939 | | |
917 | 940 | | |
918 | 941 | | |
919 | 942 | | |
920 | 943 | | |
921 | 944 | | |
922 | 945 | | |
923 | | - | |
| 946 | + | |
924 | 947 | | |
925 | 948 | | |
926 | 949 | | |
927 | 950 | | |
928 | 951 | | |
929 | | - | |
| 952 | + | |
930 | 953 | | |
931 | 954 | | |
932 | 955 | | |
| |||
0 commit comments