Add scheduled delivery to the Mocha in-memory transport#10119
Open
glen-84 wants to merge 13 commits into
Open
Conversation
Contributor
Patch coverage80.4% of changed lines covered (197/245)
Uncovered changed lines (JSON){
"sha": "ac21cd81b18c1d4047f6d813d43b2e6146f78824",
"files": [
{ "path": "src/Mocha/src/Mocha.Transport.InMemory/Scheduling/InMemoryScheduledMessageWorker.cs", "ranges": [[41, 42], [108, 109], [111, 111], [118, 125], [127, 127], [129, 131], [145, 146], [148, 148], [166, 168], [173, 173], [175, 178], [181, 181], [183, 185], [187, 187], [194, 195], [200, 202]] },
{ "path": "src/Mocha/src/Mocha.Transport.InMemory/Scheduling/InMemoryTransportScheduledMessageStore.cs", "ranges": [[37, 39], [43, 45], [168, 169], [173, 174]] }
]
}Project coverage: 53.7% (231047/429857 lines) |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds native (non-durable) scheduled delivery support to Mocha’s in-memory transport, including a transport-owned in-process store + hosted delivery worker, plus scheduler-signal race hardening and documentation/test updates to reflect the new default behavior.
Changes:
- Implement in-memory scheduled message store + hosted worker, wired up automatically via
AddInMemory(). - Harden
MessageBusSchedulerSignalagainst notify/wait races; add regression tests. - Re-point Postgres EF fallback scheduling tests and update docs to reflect in-memory native scheduling and behavior differences.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| website/content/docs/mocha/transports/index.md | Updates transport decision matrix to reflect native in-memory scheduling. |
| website/content/docs/mocha/transports/in-memory.md | Documents in-memory scheduled delivery, cancellation, and non-durability. |
| website/content/docs/mocha/scheduling.md | Updates scheduling docs for in-memory native store and retry/troubleshooting distinctions. |
| website/content/docs/mocha/sagas.md | Updates saga timeout prerequisites to include in-memory native scheduling. |
| src/Mocha/test/Mocha.Transport.InMemory.Tests/Scheduling/InMemoryTransportScheduledMessageStoreTests.cs | Adds unit tests for the new in-memory scheduled message store behavior. |
| src/Mocha/test/Mocha.Transport.InMemory.Tests/Scheduling/InMemorySchedulingTests.cs | Adds end-to-end scheduled delivery tests using FakeTimeProvider. |
| src/Mocha/test/Mocha.Transport.InMemory.Tests/Mocha.Transport.InMemory.Tests.csproj | Adds Microsoft.Extensions.TimeProvider.Testing package for FakeTimeProvider. |
| src/Mocha/test/Mocha.Transport.InMemory.Tests/Helpers/MessageBusBuilder.cs | Starts hosted services in test helper so scheduled worker runs during tests. |
| src/Mocha/test/Mocha.Tests/Scheduling/SchedulingMiddlewareIntegrationTests.cs | Updates integration tests to use an in-memory transport without native scheduling registration when testing “no store” behavior. |
| src/Mocha/test/Mocha.Tests/Scheduling/MessageBusSchedulerSignalTests.cs | Adds regression tests for notify-before-wait and stale-target scenarios. |
| src/Mocha/test/Mocha.Sagas.Tests/IntegrationTests.cs | Removes custom test scheduled store registration now that in-memory has native scheduling. |
| src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/PostgresSchedulingIntegrationTests.cs | Ensures EF Core Postgres fallback scheduling remains exercised by using an in-memory transport without native scheduling store. |
| src/Mocha/src/Mocha/Scheduling/MessageBusSchedulerSignal.cs | Implements lost-wakeup hardening for scheduler signal notify/wait handshake. |
| src/Mocha/src/Mocha.Transport.InMemory/Scheduling/InMemoryTransportScheduledMessageStore.cs | Introduces in-memory scheduled message store with ordering + cancellation + dedicated signal. |
| src/Mocha/src/Mocha.Transport.InMemory/Scheduling/InMemoryScheduledMessageWorker.cs | Adds hosted worker that dispatches due scheduled messages via normal dispatch pipeline. |
| src/Mocha/src/Mocha.Transport.InMemory/Mocha.Transport.InMemory.csproj | Adds Mocha.Outbox reference needed by the scheduled dispatch worker. |
| src/Mocha/src/Mocha.Transport.InMemory/MessageBusBuilderExtensions.cs | Wires in-memory scheduled store + worker into AddInMemory() by default. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
ScheduledTime(viaScheduleSendAsync/SchedulePublishAsync, or a saga'sdescriptor.Timeout(...)) is delivered at ~that time instead of immediately, and can be cancelled via the returned token.AddInMemory()registers a transport-scoped store plus a hosted delivery worker on the post-Rework scheduling #10036ScheduledMessageStoreRegistration/resolver model. Delivery is in-process, non-durable (scheduled messages are lost on restart), and best-effort (no retry).ISchedulerSignalrather than the shared singleton, becauseMessageBusSchedulerSignalis a single-waiter primitive (two workers on one instance would corrupt each other's wait). Hardening that signal's notify/wait handshake against lost wake-ups (notify-before-wait and stale-target-between-waits) also benefits the Postgres dispatcher, which shares the type.Mocha.EntityFrameworkCore.Postgres.Testsscheduling tests are re-pointed onto a bare in-memory transport so they still exercise the EFUsePostgresScheduling()fallback: with in-memory now having native scheduling, the previous "in-memory transport + EF fallback" pairing is obsolete. Docs updated: in-memory scheduling is native, on by default, cancellable, and non-durable, with Postgres-specific troubleshooting scoped accordingly.Test plan
FakeTimeProvider): not-delivered-before-due, delivered-after-due, cancellation prevents delivery, body/headers preserved across pooled-context reuse, same-due-time ordering.Mocha.Tests3940, Sagas 568 pass/4 skip,Mocha.EntityFrameworkCore.Postgres.Testsscheduling 52 (Squadron/Docker).