Skip to content

Stabilize Mocha saga integration tests against timing flakes#9947

Draft
glen-84 wants to merge 2 commits into
mainfrom
gai/stabilize-saga-integration-tests
Draft

Stabilize Mocha saga integration tests against timing flakes#9947
glen-84 wants to merge 2 commits into
mainfrom
gai/stabilize-saga-integration-tests

Conversation

@glen-84

@glen-84 glen-84 commented Jun 18, 2026

Copy link
Copy Markdown
Member

Summary

  • The four saga IntegrationTests relied on fixed Task.Delay waits before asserting on store state, which flaked under CI load: the Main Branch Coverage run had Saga_Should_TimeoutWithCustomResponse fail with Expected: 0, Actual: 1 when 500 ms wasn't enough for the timeout to propagate.
  • Replaced those delays with deterministic synchronization. Each test polls the specific persisted saga state, fails fast if the expected precondition never appears, and waits for the instance to be deleted, all bounded by the existing 10 s timeout.
  • The timeout tests wait until the saga is persisted before sending SagaTimedOutEvent, so it always targets a stored instance.
  • Saga_Should_SupportRequestResponse uses a new GatedTriggerRequestHandler that holds the reply, parking the saga in AwaitingResponse so its persisted state is observable; releasing the reply then drives finalization and deletion.

Test plan

  • dotnet test --filter-class Mocha.Sagas.Tests.IntegrationTests — 9/9 passing across multiple consecutive runs.
  • Full Mocha.Sagas.Tests suite — 136 passed, 1 skipped, 0 failed.

Copilot AI review requested due to automatic review settings June 18, 2026 10:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Stabilizes Mocha saga integration tests by replacing fixed Task.Delay waits with deterministic synchronization against persisted saga state, reducing CI timing flakes.

Changes:

  • Replaced fixed delays with bounded polling that waits for specific saga persistence/deletion conditions.
  • Ensured timeout tests only send SagaTimedOutEvent after the saga instance is persisted.
  • Added a gated request handler to hold replies so the AwaitingResponse persisted state can be observed deterministically.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Mocha/test/Mocha.Sagas.Tests/IntegrationTests.cs Outdated
Comment thread src/Mocha/test/Mocha.Sagas.Tests/IntegrationTests.cs Outdated
Comment thread src/Mocha/test/Mocha.Sagas.Tests/IntegrationTests.cs Outdated
@github-code-quality

Copy link
Copy Markdown

Code Coverage Overview

Languages: C#

C# / code-coverage/dotnet

The overall coverage in the branch remains at 49%, unchanged from the branch.

Show a code coverage summary of the most impacted files.
File 443ea28 b9841b3 +/-
/home/runner/wo...ageProcessor.cs 100% 89% -11%
/home/runner/wo...toResetEvent.cs 73% 68% -5%
/home/runner/wo...eiveEndpoint.cs 72% 69% -3%
/home/runner/wo...DefaultTopic.cs 89% 90% +1%
/home/runner/wo...efaultPubSub.cs 89% 91% +2%
/home/runner/wo...ueryExecutor.cs 65% 67% +2%
/home/runner/wo...tor/Mediator.cs 89% 91% +2%
/home/runner/wo...PromiseCache.cs 78% 81% +3%
/home/runner/wo...entsListener.cs 62% 66% +4%
/home/runner/wo...heMiddleware.cs 86% 92% +6%

Code Coverage is in Public Preview. Learn more and provide us with your feedback.

@glen-84 glen-84 marked this pull request as draft June 18, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants