Skip to content

Commit 2a884a7

Browse files
committed
More configure await in EF Core generated code, fixed new idempotency tests. Closes GH-2042
1 parent 1a4466f commit 2a884a7

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/Persistence/EfCoreTests/idempotency_with_inline_or_buffered_endpoints_end_to_end.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using IntegrationTests;
22
using JasperFx;
33
using JasperFx.CodeGeneration.Frames;
4+
using JasperFx.Core;
45
using JasperFx.Resources;
56
using Marten;
67
using Microsoft.Data.SqlClient;
@@ -162,6 +163,8 @@ public async Task apply_idempotency_to_non_transactional_handler()
162163
using var host = await Host.CreateDefaultBuilder()
163164
.UseWolverine(opts =>
164165
{
166+
opts.Durability.Mode = DurabilityMode.Solo;
167+
165168
opts.Services.AddDbContextWithWolverineIntegration<CleanDbContext>(x =>
166169
x.UseSqlServer(Servers.SqlServerConnectionString));
167170

@@ -194,6 +197,7 @@ public async Task apply_idempotency_to_non_transactional_handler()
194197

195198
var tracked2 = await host.TrackActivity()
196199
.DoNotAssertOnExceptionsDetected()
200+
.Timeout(15.Seconds())
197201
.ExecuteAndWaitAsync(c =>
198202
{
199203
sentMessage.WasPersistedInInbox = false;

src/Persistence/Wolverine.EntityFrameworkCore/Codegen/EnrollDbContextInTransaction.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,25 @@ public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
3737
"Enroll the DbContext & IMessagingContext in the outgoing Wolverine outbox transaction");
3838
writer.Write($"var {_envelopeTransaction.Usage} = new {typeof(EfCoreEnvelopeTransaction).FullNameInCode()}({_dbContext.Usage}, {_context.Usage}, {_scrapers.Usage});");
3939
writer.Write(
40-
$"await {_context.Usage}.{nameof(MessageContext.EnlistInOutboxAsync)}({_envelopeTransaction.Usage});");
40+
$"await {_context.Usage}.{nameof(MessageContext.EnlistInOutboxAsync)}({_envelopeTransaction.Usage}).ConfigureAwait(false);");
4141

4242

4343
writer.WriteComment("Start the actual database transaction");
44-
writer.Write($"using var {Transaction.Usage} = await {_dbContext.Usage}.Database.BeginTransactionAsync({_cancellation.Usage});");
44+
writer.Write($"using var {Transaction.Usage} = await {_dbContext.Usage}.Database.BeginTransactionAsync({_cancellation.Usage}).ConfigureAwait(false);");
4545
writer.Write("BLOCK:try");
4646

4747
// EF Core can only do eager idempotent checks
4848
if (_idempotencyStyle == IdempotencyStyle.Eager || _idempotencyStyle == IdempotencyStyle.Optimistic)
4949
{
50-
writer.Write($"await {_context.Usage}.{nameof(MessageContext.AssertEagerIdempotencyAsync)}({_cancellation.Usage});");
50+
writer.Write($"await {_context.Usage}.{nameof(MessageContext.AssertEagerIdempotencyAsync)}({_cancellation.Usage}).ConfigureAwait(false);");
5151
}
5252

5353
Next?.GenerateCode(method, writer);
5454

55-
writer.Write($"await {_envelopeTransaction.Usage}.CommitAsync({_cancellation.Usage});");
55+
writer.Write($"await {_envelopeTransaction.Usage}.CommitAsync({_cancellation.Usage}).ConfigureAwait(false);");
5656
writer.FinishBlock();
5757
writer.Write($"BLOCK:catch ({typeof(Exception).FullNameInCode()})");
58-
writer.Write($"await {_envelopeTransaction.Usage}.RollbackAsync();");
58+
writer.Write($"await {_envelopeTransaction.Usage}.RollbackAsync().ConfigureAwait(false);");
5959
writer.Write("throw;");
6060
writer.FinishBlock();
6161
}

src/Wolverine/Runtime/MessageContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private bool isMissingRequestedReply()
8080
public async Task AssertEagerIdempotencyAsync(CancellationToken cancellation)
8181
{
8282
if (Envelope == null || Envelope.WasPersistedInInbox ) return;
83-
if (Transaction == null)
83+
if (Transaction == null || Transaction is MessageContext)
8484
{
8585
var exists = await Runtime.Storage.Inbox.ExistsAsync(Envelope, cancellation);
8686
if (exists)

0 commit comments

Comments
 (0)