Commit 8a19e53
authored
test: Fix flaky
`test_lifecycle_on_platform_without_websocket` pointed the events
WebSocket URL at a hard-coded `ws://localhost:56565` and asserted that
the connection is refused. That port sits inside the OS ephemeral range
(32768-60999 on Linux, 49152-65535 on Windows), so any `bind(host, 0)`
elsewhere in the parallel suite can be handed exactly that port, and
this test file alone starts three such servers. When a sibling xdist
worker got 56565, the connection succeeded and the test failed with `DID
NOT RAISE RuntimeError`, as in [this Windows
run](https://github.com/apify/apify-sdk-python/actions/runs/34123143315/job/101745572277).
Attempt 2 of the same run passed on the same commit.
The test now reserves a port instead of guessing one. A new
`_unreachable_ws_url` helper binds `('127.0.0.1', 0)` and holds the
socket open without calling `listen()`. Holding it keeps the OS from
handing the port to anyone else, and a bound socket that never listens
refuses every connect with `ECONNREFUSED`, which is the `OSError` the
test asserts as the cause. The assertions themselves are unchanged.
Running a real WebSocket server on `127.0.0.1:56565` reproduces the CI
failure exactly, which gives a before/after: 20/20 runs failed before
the fix, 0/100 after. The fixed test also survived 0/25 whole-file runs
under `--numprocesses=auto` with that port occupied, and 0/60 runs with
a background process holding ~400 rotating ephemeral listeners.
*✍️ Drafted by Claude Code*test_lifecycle_on_platform_without_websocket (#1121)1 parent 8532389 commit 8a19e53
1 file changed
Lines changed: 22 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
181 | 197 | | |
182 | 198 | | |
183 | 199 | | |
| |||
284 | 300 | | |
285 | 301 | | |
286 | 302 | | |
287 | | - | |
288 | | - | |
| 303 | + | |
| 304 | + | |
289 | 305 | | |
290 | | - | |
291 | | - | |
292 | | - | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
293 | 309 | | |
294 | 310 | | |
295 | 311 | | |
| |||
0 commit comments