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

Fixed an unreported bug with FetchForExclusiveWriting() when the daem… #3621

Merged
merged 2 commits into from
Jan 8, 2025
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 @@ -498,6 +498,60 @@ public async Task fetch_aggregate_that_is_completely_caught_up()
await theSession.SaveChangesAsync();
}

[Fact]
public async Task fetch_aggregate_that_is_completely_caught_up_with_no_version_supplied()
{
StoreOptions(opts =>
{
opts.Projections.Snapshot<SimpleAggregateAsString>(SnapshotLifecycle.Async);
opts.Events.StreamIdentity = StreamIdentity.AsString;
});

var streamId = Guid.NewGuid().ToString();

theSession.Events.StartStream<SimpleAggregateAsString>(streamId, new AEvent(), new BEvent(), new BEvent(), new BEvent(),
new CEvent(), new CEvent());
await theSession.SaveChangesAsync();

var daemon = await theStore.BuildProjectionDaemonAsync();
await daemon.RebuildProjectionAsync<SimpleAggregateAsString>(CancellationToken.None);

var stream = await theSession.Events.FetchForWriting<SimpleAggregateAsString>(streamId);
stream.Aggregate.ShouldNotBeNull();
stream.CurrentVersion.ShouldBe(6);

stream.AppendOne(new EEvent());
await theSession.SaveChangesAsync();
}



[Fact]
public async Task fetch_aggregate_that_is_completely_caught_up_use_exclusive_locks()
{
StoreOptions(opts =>
{
opts.Projections.Snapshot<SimpleAggregateAsString>(SnapshotLifecycle.Async);
opts.Events.StreamIdentity = StreamIdentity.AsString;
});

var streamId = Guid.NewGuid().ToString();

theSession.Events.StartStream<SimpleAggregateAsString>(streamId, new AEvent(), new BEvent(), new BEvent(), new BEvent(),
new CEvent(), new CEvent());
await theSession.SaveChangesAsync();

var daemon = await theStore.BuildProjectionDaemonAsync();
await daemon.RebuildProjectionAsync<SimpleAggregateAsString>(CancellationToken.None);

var stream = await theSession.Events.FetchForExclusiveWriting<SimpleAggregateAsString>(streamId);
stream.Aggregate.ShouldNotBeNull();
stream.CurrentVersion.ShouldBe(6);

stream.AppendOne(new EEvent());
await theSession.SaveChangesAsync();
}

[Fact]
public async Task fetch_aggregate_that_is_in_progress()
{
Expand Down
5 changes: 4 additions & 1 deletion src/Marten/Events/Fetching/FetchAsyncPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ public async Task<IEventStream<TDoc>> FetchForWriting(DocumentSessionBase sessio
// Read in any events from after the current state of the aggregate
await reader.NextResultAsync(cancellation).ConfigureAwait(false);
var events = await new ListQueryHandler<IEvent>(null, selector).HandleAsync(reader, session, cancellation).ConfigureAwait(false);
document = await _aggregator.BuildAsync(events, session, document, cancellation).ConfigureAwait(false);
if (events.Any())
{
document = await _aggregator.BuildAsync(events, session, document, cancellation).ConfigureAwait(false);
}

if (document != null)
{
Expand Down
Loading