diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 4ffecdd58..f1a62be25 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: Upgrade `EventStore.Client` to v5.0.1 and use it for both .NET Framework and .NET Core * Fix: Storing events in MS SQL Server using `MsSqlEventPersistence` now correctly handles non-ANSI unicode characters in strings. diff --git a/Source/EventFlow.TestHelpers/EventFlow.TestHelpers.csproj b/Source/EventFlow.TestHelpers/EventFlow.TestHelpers.csproj index 30848e1d5..f038c8e5b 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 @@ -32,13 +32,18 @@ - - - + + + - - + + + + + + + \ No newline at end of file diff --git a/Source/EventFlow.TestHelpers/IntegrationTest.cs b/Source/EventFlow.TestHelpers/IntegrationTest.cs index 45ee0eec8..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(); } @@ -116,7 +118,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 +130,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/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..621a464b9 100644 --- a/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs +++ b/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs @@ -239,7 +239,7 @@ await PublishPingCommandAsync(id).ConfigureAwait(false) } } - [Test, Timeout(10000)] + [Test] public virtual async Task OptimisticConcurrencyCheck() { // Simulates a state in which two read models have been loaded to memory @@ -250,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] diff --git a/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs b/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs index 58dc65392..e10712402 100644 --- a/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs +++ b/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs @@ -71,15 +71,17 @@ protected override IEventFlowOptions Options(IEventFlowOptions eventFlowOptions) } [Test] - [Timeout(10000)] 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]