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

fix: writing failed events #83

Merged
merged 3 commits into from
Dec 9, 2024
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
2 changes: 1 addition & 1 deletion src/Fluss.HotChocolate.IntegrationTest/HotChocolateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private async Task<Channel<List<Guid>>> SubscribeToTodos(CancellationToken ct)
socket.Options.AddSubProtocol("graphql-transport-ws");
await socket.ConnectAsync(new Uri(Address.Replace("http", "ws") + "/graphql"), CancellationToken.None);

Task.Run(async () =>
_ = Task.Run(async () =>
{
while (true)
{
Expand Down
29 changes: 28 additions & 1 deletion src/Fluss.UnitTest/Core/UnitOfWork/UnitOfWorkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public UnitOfWorkTest()

_unitOfWorkFactory = new UnitOfWorkFactory(
new ServiceCollection()
.AddScoped(_ => GetUnitOfWork())
.AddTransient(_ => GetUnitOfWork())
.BuildServiceProvider());
}

Expand Down Expand Up @@ -332,6 +332,33 @@ await Assert.ThrowsAsync<InvalidOperationException>(async () =>
});
}

[Fact]
public async Task FailingCommitDoesNotCacheEventsToWrite()
{
_policies.Add(new AllowAllPolicy());

try
{
await _unitOfWorkFactory.Commit(async unitOfWork =>
{
var aggregate = await unitOfWork.GetAggregate<TestAggregate, int>(100);
await aggregate.Create();

throw new Exception();
});
}
catch
{
}

await _unitOfWorkFactory.Commit(_ => ValueTask.CompletedTask);

var unitOfWork = GetUnitOfWork();
var aggregate = await unitOfWork.GetAggregate<TestAggregate, int>(100);

Assert.False(aggregate.Exists);
}

private record TestRootReadModel : RootReadModel
{
public int GotEvents { get; private init; }
Expand Down
1 change: 1 addition & 0 deletions src/Fluss/UnitOfWork/UnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public ValueTask Return()
_validator = null;
_userIdProvider = null;
_consistentVersion = null;
PublishedEventEnvelopes.Clear();
_readModels.Clear();
_isInstantiated = false;

Expand Down
Loading