Skip to content

test(notifications): wait for the dispatch event, not the fake transport - #1587

Merged
frahlg merged 1 commit into
masterfrom
fix/notifications-dispatch-test
Oct 12, 2026
Merged

frahlg merged 1 commit into
masterfrom
fix/notifications-dispatch-test

Conversation

@frahlg

@frahlg frahlg commented Oct 12, 2026

Copy link
Copy Markdown
Member

Problem

TestDispatchReachesEveryInstalledPublisher failed on master at 851eaee0 (#1582) with sent = 0, want 1. It passed at af22b488 and on #1582's own CI.

Cause

Not #1582. The test is timing-sensitive and fails by chance.

  • fix(loadpoint): keep the EV ready time on the household clock #1582 changes no package that notifications imports, apart from one _test.go file in state. The failure reproduces on unmodified origin/master: 2 failures in 3,000 runs of the test alone, and 1 in 300 in each of the plain and -race runs together with its neighbour.
  • The test publishes an event, waits until both fake transports hold the message, then reads Status().Sent. deliver bumps that counter only after the last transport has returned and a log line is written. A goroutine that reads in that gap sees 0.
  • The service is right: it cannot count a send before the sends are done. The test waited on the wrong signal.
  • TestNothingToSendIsNotAFailure has the same flaw and the same fix.

Proof: with a 50 ms sleep between the last Publish and bumpSent (not in this PR), both old tests fail on every run with the CI message. Both new tests pass with that sleep, with and without -race.

Change

Tests only, in service_push_test.go.

  • Subscribe to notifications.dispatched. deliver emits it after it moves the counter, so Status() is final once it arrives.
  • Wait for that event instead of the fake transport, then read Status().
  • Check that each transport got exactly one message. The old wait accepted one or more.

No change to service.go. K5 (push notifications) builds on this package and can rely on the tests.

No changeset: no shipped code changes. Labelled no-changeset, as #1097, #1107 and #1119 were.

Test evidence

Run in a worktree from origin/master:

  • Before the fix, with the 50 ms sleep: both tests fail on every run.
  • After the fix, no sleep, test binary built once, 10,000 runs of TestDispatchReachesEveryInstalledPublisher and 400 runs of TestNothingToSendIsNotAFailure, plain and -race: 0 failures.
  • After the fix, with the 50 ms sleep, -count=20, plain and -race: pass.
  • go test -race -count=5 ./internal/notifications: pass. go vet and gofmt clean.
  • make verify: pass ("verify: vet + test + build clean", exit 0).

🤖 Generated with Claude Code

TestDispatchReachesEveryInstalledPublisher failed on master at 851eaee
with "sent = 0, want 1". It reproduces on unmodified origin/master, about
2 times in 3,000 runs of the test alone.

The test waited until both fake transports held the message, then read
Status().Sent. deliver counts a dispatch as sent only after the last
transport has returned and a log line has been written, so a goroutine that
reads in that window sees 0. The service is right: it cannot count a send
before the sends are done. The test waited on the wrong signal.
TestNothingToSendIsNotAFailure had the same flaw.

Both tests now wait for the notifications.dispatched event, which deliver
emits after it moves the counter, and then read Status(). They also check
that each transport got exactly one message; the old wait accepted one or
more.

With a 50 ms sleep between the last Publish and bumpSent (not committed),
both old tests fail on every run with the CI message, and both new tests
pass, with and without -race.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@frahlg frahlg added the no-changeset PR intentionally exempt from the changeset requirement (dev tooling / non-shipping) label Oct 12, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T15:48:56.195487Z 4ac3675 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@frahlg
frahlg merged commit 37d1676 into master Oct 12, 2026
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changeset PR intentionally exempt from the changeset requirement (dev tooling / non-shipping)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant