fix(tests): make notification-email waits deterministic instead of wall-clock - #253
Merged
Conversation
…ll-clock Create_NotifiesTheOwner (and the other notification tests) polled the fake email sender against a fixed 20s deadline. Under full-suite load that broke 2 ways: the daemon can legitimately take longer than the deadline, and a test event committed before the SubscribeFromPresent subscriptions seed their starting position is skipped outright, so no deadline would ever see the email. The factory now blocks fixture init until every subscription agent is registered (position seeded while the database is still empty), and tests wait on Marten's WaitForNonStaleProjectionDataAsync — daemon progress, not a guessed timeout. Since delivery is final once the daemon catches up, the 1.5s "no extra email" grace sleeps are gone too. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
JobOfferApiTests.Create_NotifiesTheOwneris flaky under fullnpm testload: it spent ~21s waiting for the job-offer notification, then failed withAssert.Single() Failure: The collection was empty, while passing in isolation.The notification tests polled
factory.EmailSender.Sentagainst a fixed 20-second wall-clock deadline. Under load that breaks two distinct ways:SubscribeFromPresent, which seeds each shard''s starting position at the current high-water mark when the shard starts. The daemon acquires HotCold leadership in the background after the host already serves requests, so under load an event committed by an early test before the seed is skipped forever — no timeout ever sees that email.Fix (test infrastructure only)
TestWebApplicationFactory.InitializeAsyncnow blocks until every subscription agent is registered with the daemon. Agents register only after their position is seeded, and at fixture init the database is still empty, so no test event can ever land before the subscriptions listen.WaitForEmailsAsync(fixed 20s poll) is replaced by one factory helper that awaits Marten''sWaitForNonStaleProjectionDataAsync— it tracks actual daemon progress up to the event-store sequence at call time, with a generous 60s cap that only bites when something is genuinely broken, and rich shard diagnostics on timeout.Task.Delay(1500)"no extra email" grace sleeps are gone and those assertions are now deterministic (previously a slow daemon delivering a wrong extra email after the grace window would falsely pass).No production code changed.
Verification
npm test(backend + frontend + E2E): all green; integration suite finished in 12s under that load, where the flake used to appear.🤖 Generated with Claude Code