oliver-zehentleitner / maity
hub tests: background workers (probe sweep, public-pages prepare) race the WhyForge counters in test_outside_reads
tsk-9j767pr11k1a Done Maity Coder Claude 003
Flake in hub CI and locally under -n 4:tests/test_outside_reads.py::test_the_why_is_not_found_to_an_outsider_where_the_instance_token_does_not_serve[another_namespace], assert (2, 4) == (1, 4).
CI hits: #2129 run 45099723699, job 137447603338. Also seen locally by z5j2 on #2128.
Cause, reproduced by ops 3yc2 (seq 199682): a test race, not a hub bug.
- Every client from make_client starts probe.Worker in its lifespan (app.py:456). Its first sweep runs at once (probe.py _run, next_sweep = clock.now()).
- On SQLite, worker_runs.claim always yields (worker_runs.py:110).
- The sweep's observe_visibility (probe.py:717) calls repository_public through the WhyForge fake. That bumps
asked, adds "repos" toeventsand adds the project tobound. - When that sweep lands after the test has captured its counts, the assert is off by one.
- Proof: a pytest plugin sleeping before probe.sweep fails the test with exactly this assert at 0.1 s and 0.2 s, and at 0.5 s gives (1, 4) == (0, 4).
The same race can hit other asserts in the file:
- Exact counts: l.1306-1310, l.1355, l.1414-1416.
- Asserts that can pass for the wrong reason: l.1456, l.1577, l.1693.
Fix, hub tests only:
- Proposed: the WhyForge fake leaves calls from the
maity-probethread out of asked, events and bound, or records them apart. - Alternative: stop app.state.probe in every client the tests measure.
Acceptance:
- The whole file passes with 3yc2's sleep-before-sweep plugin at 0.1, 0.2 and 0.5 s. Ask 3yc2 for the plugin by DM.
- Repeated -n 4 runs pass.
- A counter-check: without the fix, the plugin makes the test fail.
Also needs a Keep the Why note in hub/context/testing.md, beside the clock-pin entry from #2129: background workers in test clients.