Skip to content

test: two flaky tests made reliable without weakening them - #260

Merged
7schmiede merged 1 commit into
mainfrom
fix/flaky-deadline-and-hub-probe
Oct 23, 2026
Merged

7schmiede merged 1 commit into
mainfrom
fix/flaky-deadline-and-hub-probe

Conversation

@7schmiede

Copy link
Copy Markdown
Member

Two tests that turned pull requests red on unrelated changes. Tests only, so there is no CHANGELOG entry.

a_change_reported_twice_makes_one_deadline_for_every_service (daemon, candidate pipeline)

Cause: check (macos-14) failed with "a fired 153.00925ms after its deadline". The macOS runner is a VM and oversleeps. The test allowed 100 ms past repeat + DEBOUNCE on a single try.

Fix: the regression this test guards (#233) is a pipeline that looks every 200 ms, counted from when its thread began. That regression is late by the same ~180 ms on every try, while an oversleep is late only now and then. The scenario is now its own function (one_edit_reported_twice). A late try is run again, three times at most, and the 100 ms bound stays the same. "Never before the deadline" is still checked on every try. The fixed 300 ms sleep before checking that each pipeline is done is now a wait of up to 5 s.

Checked against the regression: I put back sleep(200 ms) in place of sleep(left) and the test failed on all three tries: a was 181, 183 and 181 ms late, b 1 to 3 ms.

a_hub_answers_once_its_port_takes_connections (hub)

Cause: in run 39976589586 (ubuntu) the test failed 6 ms after the test binary began, with hub not running. The hub under test waits 4 s for its fake docker before it binds, so the probe in start_env (the port takes a TCP connection) connected to something else that had the port for a moment. hub status then found nothing there.

  • Self-connect is ruled out: Linux picks even source ports for connect(), and the port was odd. I checked this with 60 000 connects to an unbound port here and none connected.
  • The likely holder is a socket of another test: the 15 tests start together, each calls bind(0), and the kernel can hand out a port it just gave away.

Fix (tests only):

  • start_env counts the hub as up only once the hub's hub.json names the child's pid and the port, and the port takes a connection. The hub writes that file right after it binds.
  • A hub that exits first now fails with its exit status instead of a timeout.
  • free_port no longer gives two tests of the binary the same port.

Checked against the regression: I moved the bind back before the setup (the bug from #228) and the test still fails ("port … answers, but not as a devstack hub of this user").

Verification (Linux)

  • a_change_reported_twice…: passed 20/20, and 10/10 with all 16 cores kept busy by yes.
  • --test hub (all 15 tests): passed 20/20.
  • cargo fmt --check and cargo clippy -p devstack-daemon -p devstack --all-targets -- -D warnings are clean.
  • Not checked on macOS here: whether the macOS runner oversleeps on three tries in a row. This PR's own check (macos-14) run is the first evidence. The hub test is #[cfg(unix)] and also runs there.

🤖 Generated with Claude Code

`a_change_reported_twice_makes_one_deadline_for_every_service` failed on
the macOS runner with a service 153 ms past its deadline: the VM oversleeps.
The regression it guards (#233, a pipeline that looked every 200 ms from
when its thread began) is late by the same ~180 ms at every try; an
oversleep is late now and then. A late try is now tried again, three times
at most, with the same 100 ms bound. With the 200 ms poll put back, all
three tries fail (a 181, 183, 181 ms late).

`a_hub_answers_once_its_port_takes_connections` failed on ubuntu 6 ms after
it began: the probe connected to the port before the hub, which waits 4 s
for its `docker`, could have bound it. Something else had the port for a
moment, and `hub status` then found nothing there. The tests' hub is up
once its hub.json names its pid and port and the port takes a connection;
a hub that exits first says so. `free_port` no longer hands two tests of
the binary the same port. With the bind moved back before the setup, the
test still fails as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@7schmiede
7schmiede merged commit 055f9b9 into main Oct 23, 2026
13 checks passed
@7schmiede
7schmiede deleted the fix/flaky-deadline-and-hub-probe branch October 23, 2026 22:08
@7schmiede 7schmiede mentioned this pull request Oct 23, 2026
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