Skip to content

Commit

Permalink
Added test for concurrently appending DocumentProviders
Browse files Browse the repository at this point in the history
  • Loading branch information
felixkmh committed Apr 2, 2024
1 parent cfa8215 commit 83a2aab
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/CoreTests/Bugs/Bug_3083_concurrent_type_generation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Marten;
using Marten.Internal;
using Marten.Internal.Storage;
using Marten.Schema.BulkLoading;
using Marten.Testing.Harness;
using Shouldly;
using Xunit;
Expand Down Expand Up @@ -36,8 +37,61 @@ public async Task concurrent_type_generation()
storages.ShouldHaveSingleItem();
}

[Fact]
public async Task concurrent_append_providers()
{
var graph = new ProviderGraph(new StoreOptions());

var tasks = new List<Task>();

var documentProvider1 = new MockDocumentProvider<SomeDocument>();
var documentProvider2 = new MockDocumentProvider<OtherDocument>();
var documentProvider3 = new MockDocumentProvider<ThirdDocument>();
var documentProvider4 = new MockDocumentProvider<ForthDocument>();

tasks.Add(Task.Run(() => graph.Append(documentProvider1)));
tasks.Add(Task.Run(() => graph.Append(documentProvider2)));
tasks.Add(Task.Run(() => graph.Append(documentProvider3)));
tasks.Add(Task.Run(() => graph.Append(documentProvider4)));

await Task.WhenAll(tasks);

graph.StorageFor<SomeDocument>().ShouldBeTheSameAs(documentProvider1);
graph.StorageFor<OtherDocument>().ShouldBeTheSameAs(documentProvider2);
graph.StorageFor<ThirdDocument>().ShouldBeTheSameAs(documentProvider3);
graph.StorageFor<ForthDocument>().ShouldBeTheSameAs(documentProvider4);
}

public class MockDocumentProvider<T>: DocumentProvider<T> where T : notnull
{
public MockDocumentProvider(): this(null, null, null, null, null)
{
}

public MockDocumentProvider(IBulkLoader<T> bulkLoader, IDocumentStorage<T> queryOnly,
IDocumentStorage<T> lightweight, IDocumentStorage<T> identityMap, IDocumentStorage<T> dirtyTracking): base(
bulkLoader, queryOnly, lightweight, identityMap, dirtyTracking)
{
}
}

public class SomeDocument
{
public string Id { get; set; } = string.Empty;
}

public class OtherDocument
{
public string Id { get; set; } = string.Empty;
}

public class ThirdDocument
{
public string Id { get; set; } = string.Empty;
}

public class ForthDocument
{
public string Id { get; set; } = string.Empty;
}
}

0 comments on commit 83a2aab

Please sign in to comment.