Skip to content

fix(tests): make the sim backoff test deterministic across platforms - #177

Open
dieterolson wants to merge 1 commit into
open-flight:mainfrom
dieterolson:fix/tests-sim-backoff-deterministic
Open

fix(tests): make the sim backoff test deterministic across platforms#177
dieterolson wants to merge 1 commit into
open-flight:mainfrom
dieterolson:fix/tests-sim-backoff-deterministic

Conversation

@dieterolson

Copy link
Copy Markdown
Contributor

What does this PR do?

Makes test_backoff_progression_capped deterministic: the socket in openflight.sim.transport is monkeypatched to refuse connections instantly, and the test polls for the retries it asserts on instead of sleeping a fixed 0.5 s. Also applies ruff's mechanical import-block fix to this file (pre-existing I001/F401 that the pre-commit hook enforces on any touch).

Why was this required?

The test dialed a real socket at 127.0.0.1:1 and slept 0.5 s, then asserted at least two retries had happened. How fast the OS refuses that connect is platform-dependent — on Windows it's slow enough that fewer than two retries land inside the window, so the test fails on every stock Windows checkout (and is timing-sensitive everywhere). The subject under test is the client's backoff schedule, not the platform's TCP stack; the fake socket exercises the same _try_connect failure path (settimeoutconnect raises OSError subclass → close) without the platform dependence.

Automated tests

Test-only change: tests/test_sim_transport.py 22/22 on Windows (previously 21/1). The poll loop bounds the wait at 3 s but typically completes in well under half a second.

Manual (human) testing

  • Reproduced the flake on Windows 11 (fixed sleep captured < 2 retries) before the change.
  • After: ran the single test repeatedly and the full module — green each time; verified the fake implements exactly the socket surface _try_connect uses so the production failure path (log + close + backoff) still executes.

Checklist

  • Single feature/fix — this PR is scoped to one thing with a clear story above
  • Automated tests included — test-only change; the module is the coverage
  • Manual testing described — I documented what I verified by hand above
  • Python tests pass (uv run pytest tests/ -v)
  • Pylint passes (uv run pylint src/openflight/ --fail-under=9)
  • Ruff passes (uv run ruff check src/openflight/)
  • UI builds (cd ui && npm run build) — not applicable, no UI changes
  • UI lint passes (cd ui && npm run lint) — not applicable, no UI changes
  • Updated docs or CHANGELOG if needed — test-only, no changelog entry
  • No unrelated changes mixed in

test_backoff_progression_capped dialed 127.0.0.1:1 and slept a fixed
0.5 s; how fast the OS refuses that connect is platform-dependent (slow
enough on Windows to capture fewer than two retries). The socket is now
monkeypatched to refuse instantly and the test polls for the retries it
asserts on, so it exercises the backoff schedule rather than the
platform's TCP stack.

Also applies ruff's mechanical import-block fix to this file (pre-existing
I001/F401 that the pre-commit hook enforces on touch; CI does not run ruff).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant