Tests (and any other caller) previously had no way to know when the
Postgres LISTEN behind the reactive event-processing loop had actually
registered, forcing a guessed sleep before relying on it. Mocks now
exposes Ready() <-chan struct{}, closed once listenForNotifications
successfully issues LISTEN. Purely additive - ProcessEvents' signature
is unchanged.
Updates the integration tests to wait on Ready() instead of a flat
sleep, which also cut TestProcessEvents_ReactsToNotification's runtime
from ~0.25s to ~0.06s with no flakes across repeated runs.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XEDaCB7C2NEBgyvqEtZuxY
1.8 KiB
1.8 KiB
Work Summary — 2026-08-05 19:13
Task
First of the four domains/amazon design insights, addressed one at a time per user request: no "now listening" readiness signal from (*Mocks).ProcessEvents.
Change
domains/amazon/mock.go:
Mocksgainedready chan struct{}(initialized inNewMocks) and areadyOnce sync.Onceguard.- New exported method
Ready() <-chan struct{}- closed oncelistenForNotificationssuccessfully issuesLISTENon Postgres, i.e. the moment the reactive path is actually live. listenForNotificationscallsm.readyOnce.Do(func() { close(m.ready) })right after theLISTENexec succeeds (and before spawning theWaitForNotificationgoroutine).ProcessEvents(ctx) error's signature is unchanged - this is purely additive, somain.go's existing call site needed no changes.
domains/amazon/mock_test.go:
TestProcessEvents_ReactsToNotificationandTestProcessEvents_ShutsDownOnContextCancelnowselectonm.Ready()(bounded by a 5s timeout as a safety net) instead of a flattime.Sleep(200 * time.Millisecond)/time.Sleep(50 * time.Millisecond)before proceeding.
Verification
go build ./.../go vet ./...clean.go test ./domains/amazon/... -v -race: all 4 pass.TestProcessEvents_ReactsToNotificationdropped from ~0.25s to ~0.06-0.07s per run (no longer paying for an arbitrary sleep) - and 10 consecutive runs (-count=1each) were all clean, no flakes.make test: full suite still green, no regressions.
Notes
This closes insight #1 from work-summaries/work-summary-Claude-2026-08-04-2318.md. The other three (fire-and-forget listener notifications, hardcoded poll interval, LISTEN-connection errors being fatal to the whole app) are still open, to be addressed one at a time per the user's request - not done in this pass.