Skip to content
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

Complete synchronized storage session before storing outbox data #191

Merged
merged 3 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,25 @@ public async Task Commit_should_send_control_message_when_outbox_fails()
Assert.AreEqual(bool.TrueString, controlMessage.Message.Headers[Headers.ControlMessageHeader]);

var outboxTransaction = outboxStorage.StartedTransactions.Single();
Assert.IsFalse(completableSynchronizedStorageSession.Completed, "should not have completed synchronized storage session");
Assert.IsFalse(outboxTransaction.Commited, "should not have commited outbox operations");
Assert.IsFalse(outboxTransaction.Commited, "should not have committed outbox operations");
}

[Test]
public async Task Commit_should_complete_synchronized_storage_session_before_outbox_store()
{
var messageSession = new FakeMessageSession();
var dispatcher = new FakeDispatcher();
var outboxStorage = new FakeOutboxStorage { StoreCallback = (_, _, _) => throw new Exception("some error") };
var completableSynchronizedStorageSession = new FakeSynchronizableStorageSession();
using var session = new OutboxTransactionalSession(outboxStorage, completableSynchronizedStorageSession, messageSession, dispatcher, Enumerable.Empty<IOpenSessionOptionsCustomization>(), "queue address");

await session.Open(new FakeOpenSessionOptions());
await session.Send(new object());
Assert.ThrowsAsync<Exception>(async () => await session.Commit());

var outboxTransaction = outboxStorage.StartedTransactions.Single();
Assert.IsTrue(completableSynchronizedStorageSession.Completed, "should have completed synchronized storage session to match the receive pipeline behavior");
Assert.IsFalse(outboxTransaction.Commited, "should not have committed outbox operations");
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ protected override async Task CommitInternal(CancellationToken cancellationToken
var outgoingMessages = new TransportOperations(new TransportTransportOperation(message, new UnicastAddressTag(physicalQueueAddress)));
await dispatcher.Dispatch(outgoingMessages, new TransportTransaction(), cancellationToken).ConfigureAwait(false);

await synchronizedStorageSession.CompleteAsync(cancellationToken).ConfigureAwait(false);

var outboxMessage =
new OutboxMessage(SessionId, ConvertToOutboxOperations(pendingOperations.Operations));
await outboxStorage.Store(outboxMessage, outboxTransaction, Context, cancellationToken)
.ConfigureAwait(false);

await synchronizedStorageSession.CompleteAsync(cancellationToken).ConfigureAwait(false);

await outboxTransaction.Commit(cancellationToken).ConfigureAwait(false);
}

Expand Down