From 055edfdacafd5c7dddf90bc36e74213fd6e9a680 Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Mon, 1 Apr 2019 21:15:23 +0200 Subject: [PATCH 1/4] Compile EventFlow.TestHelper to NET Standard --- .../EventFlow.TestHelpers/EventFlow.TestHelpers.csproj | 7 +++++-- Source/EventFlow.TestHelpers/ProcessHelper.cs | 10 ++++++---- .../Suites/TestSuiteForReadModelStore.cs | 5 ++++- .../Suites/TestSuiteForScheduler.cs | 2 ++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Source/EventFlow.TestHelpers/EventFlow.TestHelpers.csproj b/Source/EventFlow.TestHelpers/EventFlow.TestHelpers.csproj index e315b4299..6440b925a 100644 --- a/Source/EventFlow.TestHelpers/EventFlow.TestHelpers.csproj +++ b/Source/EventFlow.TestHelpers/EventFlow.TestHelpers.csproj @@ -1,7 +1,7 @@  - net452 + net452;netstandard2.0 True False False @@ -30,10 +30,13 @@ + + + - + diff --git a/Source/EventFlow.TestHelpers/ProcessHelper.cs b/Source/EventFlow.TestHelpers/ProcessHelper.cs index e5417ae4f..a8435cc2a 100644 --- a/Source/EventFlow.TestHelpers/ProcessHelper.cs +++ b/Source/EventFlow.TestHelpers/ProcessHelper.cs @@ -24,7 +24,6 @@ using System; using System.Diagnostics; using System.IO; -using System.Management; using EventFlow.Core; using EventFlow.Extensions; using EventFlow.TestHelpers.Extensions; @@ -91,8 +90,9 @@ void InitializeProcess(Process p) { process.OutputDataReceived -= OutHandler; process.ErrorDataReceived -= ErrHandler; - +#if NET452 KillProcessAndChildren(process.Id); +#endif } catch (Exception e) { @@ -105,14 +105,15 @@ void InitializeProcess(Process p) }); } +#if NET452 private static void KillProcessAndChildren(int pid) { - var searcher = new ManagementObjectSearcher("Select * From Win32_Process Where ParentProcessID=" + pid); + var searcher = new System.Management.ManagementObjectSearcher("Select * From Win32_Process Where ParentProcessID=" + pid); var moc = searcher.Get(); foreach (var o in moc) { - var mo = (ManagementObject)o; + var mo = (System.Management.ManagementObject)o; KillProcessAndChildren(Convert.ToInt32(mo["ProcessID"])); } @@ -128,5 +129,6 @@ private static void KillProcessAndChildren(int pid) // Process already exited. } } +#endif } } \ No newline at end of file diff --git a/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs b/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs index fcb3ae16e..2356486fe 100644 --- a/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs +++ b/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs @@ -239,7 +239,10 @@ await PublishPingCommandAsync(id).ConfigureAwait(false) } } - [Test, Timeout(10000)] + [Test] +#if NET452 + [Timeout(10000)] +#endif public virtual async Task OptimisticConcurrencyCheck() { // Simulates a state in which two read models have been loaded to memory diff --git a/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs b/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs index 58dc65392..516766947 100644 --- a/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs +++ b/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs @@ -71,7 +71,9 @@ protected override IEventFlowOptions Options(IEventFlowOptions eventFlowOptions) } [Test] +#if NET452 [Timeout(10000)] +#endif public async Task AsynchronousSubscribesGetInvoked() { // Act From daffd5592608e08bd15c0cb947bd6d8d9cc059a7 Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Sun, 26 May 2019 19:28:15 +0200 Subject: [PATCH 2/4] Use cancellation instead in OptimisticConcurrencyCheck --- .../EventFlow.TestHelpers/IntegrationTest.cs | 7 +++- .../Suites/TestSuiteForReadModelStore.cs | 38 +++++++++---------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Source/EventFlow.TestHelpers/IntegrationTest.cs b/Source/EventFlow.TestHelpers/IntegrationTest.cs index 45ee0eec8..8b40d42fa 100644 --- a/Source/EventFlow.TestHelpers/IntegrationTest.cs +++ b/Source/EventFlow.TestHelpers/IntegrationTest.cs @@ -116,7 +116,10 @@ protected Task LoadSagaAsync(ThingyId thingyId) CancellationToken.None); } - protected async Task> PublishPingCommandsAsync(ThingyId thingyId, int count) + protected async Task> PublishPingCommandsAsync( + ThingyId thingyId, + int count, + CancellationToken cancellationToken = default) { if (count <= 0) throw new ArgumentOutOfRangeException(nameof(count)); @@ -125,7 +128,7 @@ protected async Task> PublishPingCommandsAsync(Thing for (var i = 0; i < count; i++) { var pingId = PingId.New; - await CommandBus.PublishAsync(new ThingyPingCommand(thingyId, pingId), CancellationToken.None).ConfigureAwait(false); + await CommandBus.PublishAsync(new ThingyPingCommand(thingyId, pingId), cancellationToken).ConfigureAwait(false); pingIds.Add(pingId); } diff --git a/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs b/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs index 2356486fe..621a464b9 100644 --- a/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs +++ b/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs @@ -240,9 +240,6 @@ await PublishPingCommandAsync(id).ConfigureAwait(false) } [Test] -#if NET452 - [Timeout(10000)] -#endif public virtual async Task OptimisticConcurrencyCheck() { // Simulates a state in which two read models have been loaded to memory @@ -253,23 +250,26 @@ public virtual async Task OptimisticConcurrencyCheck() // a controlled delay and a set of AutoResetEvent is used to ensure // that the read store is in the desired state before continuing - // Arrange - var id = ThingyId.New; - var waitState = new WaitState(); - await PublishPingCommandsAsync(id, 1).ConfigureAwait(false); - - // Arrange - _waitStates[id.Value] = waitState; - var delayedPublishTask = Task.Run(() => PublishPingCommandsAsync(id, 1)); - waitState.ReadStoreReady.WaitOne(); - _waitStates.Remove(id.Value); - await PublishPingCommandsAsync(id, 1).ConfigureAwait(false); - waitState.ReadStoreContinue.Set(); - await delayedPublishTask.ConfigureAwait(false); + using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10))) + { + // Arrange + var id = ThingyId.New; + var waitState = new WaitState(); + await PublishPingCommandsAsync(id, 1, cts.Token).ConfigureAwait(false); + + // Arrange + _waitStates[id.Value] = waitState; + var delayedPublishTask = Task.Run(() => PublishPingCommandsAsync(id, 1, cts.Token), cts.Token); + waitState.ReadStoreReady.WaitOne(TimeSpan.FromSeconds(10)); + _waitStates.Remove(id.Value); + await PublishPingCommandsAsync(id, 1, cts.Token).ConfigureAwait(false); + waitState.ReadStoreContinue.Set(); + await delayedPublishTask.ConfigureAwait(false); - // Assert - var readModel = await QueryProcessor.ProcessAsync(new ThingyGetQuery(id)).ConfigureAwait(false); - readModel.PingsReceived.Should().Be(3); + // Assert + var readModel = await QueryProcessor.ProcessAsync(new ThingyGetQuery(id), cts.Token).ConfigureAwait(false); + readModel.PingsReceived.Should().Be(3); + } } [Test] From 2c2abb7e3f15cf391d6a0320d8e4664662315ef6 Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Sun, 26 May 2019 19:29:48 +0200 Subject: [PATCH 3/4] Use cancellation token in AsynchronousSubscribesGetInvoked --- Source/EventFlow.TestHelpers/IntegrationTest.cs | 6 ++++-- .../Suites/TestSuiteForScheduler.cs | 16 ++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Source/EventFlow.TestHelpers/IntegrationTest.cs b/Source/EventFlow.TestHelpers/IntegrationTest.cs index 8b40d42fa..1ad71587d 100644 --- a/Source/EventFlow.TestHelpers/IntegrationTest.cs +++ b/Source/EventFlow.TestHelpers/IntegrationTest.cs @@ -100,9 +100,11 @@ protected Task LoadAggregateAsync(ThingyId thingyId) return AggregateStore.LoadAsync(thingyId); } - protected async Task PublishPingCommandAsync(ThingyId thingyId) + protected async Task PublishPingCommandAsync( + ThingyId thingyId, + CancellationToken cancellationToken = default) { - var pingIds = await PublishPingCommandsAsync(thingyId, 1).ConfigureAwait(false); + var pingIds = await PublishPingCommandsAsync(thingyId, 1, cancellationToken).ConfigureAwait(false); return pingIds.Single(); } diff --git a/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs b/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs index 516766947..e10712402 100644 --- a/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs +++ b/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs @@ -71,17 +71,17 @@ protected override IEventFlowOptions Options(IEventFlowOptions eventFlowOptions) } [Test] -#if NET452 - [Timeout(10000)] -#endif public async Task AsynchronousSubscribesGetInvoked() { - // Act - var pingId = await PublishPingCommandAsync(A()).ConfigureAwait(false); + using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10))) + { + // Act + var pingId = await PublishPingCommandAsync(A(), cts.Token).ConfigureAwait(false); - // Assert - var receivedPingId = await Task.Run(() => _testAsynchronousSubscriber.PingIds.Take()).ConfigureAwait(false); - receivedPingId.Should().IsSameOrEqualTo(pingId); + // Assert + var receivedPingId = await Task.Run(() => _testAsynchronousSubscriber.PingIds.Take(), cts.Token).ConfigureAwait(false); + receivedPingId.Should().IsSameOrEqualTo(pingId); + } } [Test] From 40d705c5dd377d6f049dca8ba9575edc9f53cd9d Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Mon, 27 May 2019 07:46:09 +0200 Subject: [PATCH 4/4] Update release notes --- RELEASE_NOTES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 93ddd446c..3e655c635 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,5 +1,6 @@ ### New in 0.72 (not released yet) +* New: `EventFlow.TestHelpers` are now released as .NET Standard as well * Fix: Storing events in MS SQL Server using `MsSqlEventPersistence` now correctly handles non-ANSI unicode characters in strings.