Skip to content

Let the notify test observe the seam instead of the clock - #604

Merged
xmap merged 1 commit into
mainfrom
fix/notify-test-determinism
Aug 2, 2026
Merged

Let the notify test observe the seam instead of the clock#604
xmap merged 1 commit into
mainfrom
fix/notify-test-determinism

Conversation

@xmap

@xmap xmap commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Sibling of #603: a wall-clock assumption that holds serially and not under -n 4. This one had two, and the first was silently unsound.

The problem

wait_task = asyncio.create_task(wakeup.wait(5.0))
await asyncio.sleep(0.05)   # hope add_listener has finished
await _send_notify(db_pool, "wakeup-test")
await asyncio.wait_for(wait_task, timeout=2.0)
assert elapsed < 1.0        # a clock standing in for "the notify woke it"

If the 50ms sleep is too short, the NOTIFY is delivered to nobody and dropped. wait() then falls through to its own timeout, and the test fails on exactly the condition it exists to rule out. The old comment named that race and slept anyway.

The elapsed < 1.0 assertion is the same species: a timing proxy for a semantic claim.

The fix

Both replaced with signals the code already exposes:

was now
sleep(0.05) and hope wait on the _listening flag _ensure_listening sets
assert elapsed < 1.0 assert wakeup._event.is_set()

wait() clears _event before waiting; _on_notify sets it. Set means the notify woke it, clear means the timeout did — which is the claim the test's name makes, now asserted rather than inferred.

The remaining bounds are hang guards, not timing assertions. At 20s they sit far above any plausible contention delay and far below the 60s per-test cap, so a genuine hang still fails as a hang.

Verification

Two full runs under -n 4 — the configuration where it failed: 47,331 passed each. Also 3/3 serial and 3/3 under targeted contention.

🤖 Generated with Claude Code

Sibling of the drain-deadline fix: a wall-clock assumption that holds
serially and not under `-n 4`. This one had two, and the first was
silently unsound.

    await asyncio.sleep(0.05)   # hope add_listener has finished
    ...
    assert elapsed < 1.0        # a clock standing in for "the notify woke it"

If the sleep is too short the NOTIFY is delivered to nobody and dropped,
so `wait()` falls through to its own timeout and the test fails on
exactly the condition it exists to rule out. The old comment named that
race and then slept anyway.

Both replaced with signals the code already exposes. Readiness now waits
on the `_listening` flag `_ensure_listening` sets, so the NOTIFY cannot
be sent into the void. The conclusion reads `_event`, which `wait()`
clears before waiting and `_on_notify` sets: set means the notify woke
it, clear means the timeout did. That is the claim the test's name makes,
asserted rather than inferred from elapsed time.

The remaining bounds are hang guards, not timing assertions. At 20s they
are far above any plausible contention delay and far below the 60s
per-test cap, so a genuine hang still fails as a hang.

Verified where it broke: two full runs under `-n 4`, 47,331 passed each.
@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

Coverage report

This PR does not seem to contain any modification to coverable code.

@xmap
xmap merged commit f6bb914 into main Aug 2, 2026
16 checks passed
@xmap
xmap deleted the fix/notify-test-determinism branch August 2, 2026 13:17
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