From de0d2a8cbf46c7f209db297144d4b58dd409a810 Mon Sep 17 00:00:00 2001 From: "Jeremy D. Miller" Date: Tue, 18 Jun 2024 06:24:04 -0500 Subject: [PATCH] ResetAllMartenDataAsync() also pauses and resumes all async projections and subscriptions --- src/Marten/HostExtensions.cs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Marten/HostExtensions.cs b/src/Marten/HostExtensions.cs index 0001a3a4cf..780d997125 100644 --- a/src/Marten/HostExtensions.cs +++ b/src/Marten/HostExtensions.cs @@ -82,10 +82,21 @@ public static async Task CleanAllMartenDataAsync(this IHost host) where T : I /// Call DocumentStore.ResetAllData() on the document store in this host /// /// - public static Task ResetAllMartenDataAsync(this IHost host) + public static async Task ResetAllMartenDataAsync(this IHost host) { + var coordinator = host.Services.GetService(); + if (coordinator != null) + { + await coordinator.PauseAsync().ConfigureAwait(false); + } + var store = host.DocumentStore(); - return store.Advanced.ResetAllData(CancellationToken.None); + await store.Advanced.ResetAllData(CancellationToken.None).ConfigureAwait(false); + + if (coordinator != null) + { + await coordinator.ResumeAsync().ConfigureAwait(false); + } } /// @@ -93,9 +104,20 @@ public static Task ResetAllMartenDataAsync(this IHost host) /// /// /// - public static Task ResetAllMartenDataAsync(this IHost host) where T : IDocumentStore + public static async Task ResetAllMartenDataAsync(this IHost host) where T : IDocumentStore { + var coordinator = host.Services.GetService>(); + if (coordinator != null) + { + await coordinator.PauseAsync().ConfigureAwait(false); + } + var store = host.DocumentStore(); - return store.Advanced.ResetAllData(CancellationToken.None); + await store.Advanced.ResetAllData(CancellationToken.None).ConfigureAwait(false); + + if (coordinator != null) + { + await coordinator.ResumeAsync().ConfigureAwait(false); + } } }