-
-
Notifications
You must be signed in to change notification settings - Fork 808
Make outbox, inbox, and scheduling workers idempotent on start #9912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
PascalSenn
merged 6 commits into
ChilliCream:main
from
alisan3:ali/hosted-worker-idempodency
Jun 21, 2026
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eb9c8e3
thread saftey and idempotency on hosted workers
alisan3 655203b
review changes
alisan3 c71ca17
fix potential datatsource leak
alisan3 1957744
fix copilot review comments
alisan3 7319680
Merge branch 'main' into ali/hosted-worker-idempodency
alisan3 7a2a60b
Merge branch 'main' into ali/hosted-worker-idempodency
PascalSenn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
61 changes: 61 additions & 0 deletions
61
...Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/SchedulingServiceRegistrationTests.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| using Microsoft.EntityFrameworkCore; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Hosting; | ||
| using Mocha.EntityFrameworkCore.Postgres.Tests.Helpers; | ||
|
alisan3 marked this conversation as resolved.
|
||
| using Mocha.Scheduling; | ||
| using Mocha.Transport.InMemory; | ||
|
|
||
| namespace Mocha.EntityFrameworkCore.Postgres.Tests; | ||
|
|
||
| public sealed class SchedulingServiceRegistrationTests | ||
| { | ||
| private const string ConnectionString = "Host=localhost;Database=test"; | ||
|
alisan3 marked this conversation as resolved.
alisan3 marked this conversation as resolved.
|
||
|
|
||
| [Fact] | ||
| public async Task UsePostgresScheduling_Should_RegisterHostedService_When_Called() | ||
| { | ||
| // arrange | ||
| await using var provider = BuildProvider(); | ||
|
|
||
| // act | ||
| var hostedServices = provider.GetServices<IHostedService>(); | ||
|
|
||
| // assert | ||
| Assert.Contains(hostedServices, s => s is ScheduledMessageWorker); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task StartAsync_Should_NotThrow_When_CalledMultipleTimes() | ||
| { | ||
| // arrange | ||
| await using var provider = BuildProvider(); | ||
| var worker = provider.GetServices<IHostedService>() | ||
| .OfType<ScheduledMessageWorker>() | ||
| .Single(); | ||
|
|
||
| // act | ||
| await worker.StartAsync(CancellationToken.None); | ||
| await worker.StartAsync(CancellationToken.None); | ||
|
|
||
| // assert | ||
| await worker.StopAsync(CancellationToken.None); | ||
|
alisan3 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| private static ServiceProvider BuildProvider() | ||
| { | ||
| var services = new ServiceCollection(); | ||
| services.AddLogging(); | ||
| services.AddDbContext<TestDbContext>(o => o.UseNpgsql(ConnectionString)); | ||
|
|
||
| var builder = services.AddMessageBus(); | ||
| builder.AddEntityFramework<TestDbContext>(ef => ef.UsePostgresScheduling()); | ||
| builder.AddInMemory(); | ||
|
|
||
| var provider = services.BuildServiceProvider(); | ||
|
|
||
| // Build the runtime so that all singleton factories resolve | ||
| _ = provider.GetRequiredService<IMessagingRuntime>(); | ||
|
|
||
| return provider; | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.