From 83a2aab49b89a62b88935c306bd6f49f4feafe51 Mon Sep 17 00:00:00 2001 From: felixkmh <24227002+felixkmh@users.noreply.github.com> Date: Wed, 3 Apr 2024 00:00:22 +0200 Subject: [PATCH] Added test for concurrently appending DocumentProviders --- .../Bug_3083_concurrent_type_generation.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/CoreTests/Bugs/Bug_3083_concurrent_type_generation.cs b/src/CoreTests/Bugs/Bug_3083_concurrent_type_generation.cs index 290e5eaecf..d3f07e7120 100644 --- a/src/CoreTests/Bugs/Bug_3083_concurrent_type_generation.cs +++ b/src/CoreTests/Bugs/Bug_3083_concurrent_type_generation.cs @@ -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; @@ -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(); + + var documentProvider1 = new MockDocumentProvider(); + var documentProvider2 = new MockDocumentProvider(); + var documentProvider3 = new MockDocumentProvider(); + var documentProvider4 = new MockDocumentProvider(); + + 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().ShouldBeTheSameAs(documentProvider1); + graph.StorageFor().ShouldBeTheSameAs(documentProvider2); + graph.StorageFor().ShouldBeTheSameAs(documentProvider3); + graph.StorageFor().ShouldBeTheSameAs(documentProvider4); + } + + public class MockDocumentProvider: DocumentProvider where T : notnull + { + public MockDocumentProvider(): this(null, null, null, null, null) + { + } + + public MockDocumentProvider(IBulkLoader bulkLoader, IDocumentStorage queryOnly, + IDocumentStorage lightweight, IDocumentStorage identityMap, IDocumentStorage 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; + } }