From 50ff7b0d75248b23fd168ce4ff463ccda66d9a59 Mon Sep 17 00:00:00 2001 From: Gregorius Soedharmo Date: Tue, 19 Aug 2025 21:11:42 +0700 Subject: [PATCH] Remove FluentAssertions dependency from all TestKit (#7769) * Remove FluentAssertions dependency from all TestKit * Fix assertion logic (cherry picked from commit d924e57e205527d2e2c263792f52af290b22709a) --- .../Akka.TestKit.Xunit2/XunitAssertions.cs | 21 +++++ ...APISpec.ApproveTestKit.DotNet.verified.txt | 13 ++- ...oreAPISpec.ApproveTestKit.Net.verified.txt | 13 ++- ...c.ApproveTestKitXunit2.DotNet.verified.txt | 6 ++ ...Spec.ApproveTestKitXunit2.Net.verified.txt | 6 ++ src/core/Akka.Cluster.Tests/ClusterLogSpec.cs | 8 +- src/core/Akka.Cluster.Tests/ClusterSpec.cs | 30 +++---- .../ThrottlerTransportAdapterSpec.cs | 16 ++-- .../Akka.Streams.TestKit.csproj | 4 + src/core/Akka.Streams.TestKit/Utils.cs | 19 ++-- .../ActorMaterializerSpec.cs | 2 +- src/core/Akka.Streams.Tests/BugSpec.cs | 2 +- .../Dsl/AsyncEnumerableSpec.cs | 12 +-- .../Akka.Streams.Tests/Dsl/AttributesSpec.cs | 4 +- .../Dsl/FlowAggregateAsyncSpec.cs | 16 ++-- .../Dsl/FlowAggregateSpec.cs | 16 ++-- .../Akka.Streams.Tests/Dsl/FlowAskSpec.cs | 2 +- .../Akka.Streams.Tests/Dsl/FlowBatchSpec.cs | 2 +- .../Dsl/FlowFlattenMergeSpec.cs | 18 ++-- .../Akka.Streams.Tests/Dsl/FlowGroupBySpec.cs | 6 +- .../Akka.Streams.Tests/Dsl/FlowOrElseSpec.cs | 4 +- .../Dsl/FlowScanAsyncSpec.cs | 2 +- .../Dsl/FlowSelectAsyncSpec.cs | 12 +-- .../Dsl/FlowSelectAsyncUnorderedSpec.cs | 2 +- src/core/Akka.Streams.Tests/Dsl/FlowSpec.cs | 8 +- .../Dsl/FlowSplitWhenSpec.cs | 27 +++--- .../Akka.Streams.Tests/Dsl/FlowSumSpec.cs | 4 +- .../Dsl/FlowThrottleSpec.cs | 32 +++---- .../Akka.Streams.Tests/Dsl/FramingSpec.cs | 10 +-- .../Dsl/FutureFlattenSourceSpec.cs | 31 ++++--- .../Dsl/GraphMergeSortedSpec.cs | 4 +- src/core/Akka.Streams.Tests/Dsl/HubSpec.cs | 78 ++++++++--------- .../Akka.Streams.Tests/Dsl/JsonFramingSpec.cs | 10 +-- .../Dsl/KeepAliveConcatSpec.cs | 4 +- .../Akka.Streams.Tests/Dsl/LastElementSpec.cs | 4 +- .../Akka.Streams.Tests/Dsl/LastSinkSpec.cs | 22 ++--- .../Akka.Streams.Tests/Dsl/LazySinkSpec.cs | 12 +-- .../Akka.Streams.Tests/Dsl/LazySourceSpec.cs | 6 +- .../Akka.Streams.Tests/Dsl/PagedSourceSpec.cs | 12 +-- src/core/Akka.Streams.Tests/Dsl/PulseSpec.cs | 6 +- .../Akka.Streams.Tests/Dsl/RestartSpec.cs | 2 +- src/core/Akka.Streams.Tests/Dsl/SampleSpec.cs | 4 +- .../Dsl/SinkForeachAsyncSpec.cs | 22 ++--- src/core/Akka.Streams.Tests/Dsl/SourceSpec.cs | 12 +-- .../Dsl/UnfoldResourceAsyncSourceSpec.cs | 28 +++--- src/core/Akka.Streams.Tests/Dsl/ValveSpec.cs | 64 +++++++------- src/core/Akka.Streams.Tests/FusingSpec.cs | 6 +- .../Akka.Streams.Tests/IO/FileSinkSpec.cs | 33 +++---- .../Akka.Streams.Tests/IO/FileSourceSpec.cs | 2 +- .../IO/OutputStreamSinkSpec.cs | 9 +- .../IO/OutputStreamSourceSpec.cs | 26 +++--- src/core/Akka.Streams.Tests/IO/TcpSpec.cs | 66 +++++++------- .../Fusing/ActorGraphInterpreterSpec.cs | 12 +-- .../Implementation/StreamLayoutSpec.cs | 12 +-- .../Implementation/TimeoutsSpec.cs | 20 ++--- src/core/Akka.Streams.Tests/ScriptedTest.cs | 2 +- src/core/Akka.TestKit/Akka.TestKit.csproj | 1 - .../Akka.TestKit/Extensions/TaskExtensions.cs | 86 ------------------- src/core/Akka.TestKit/ITestKitAssertions.cs | 9 ++ src/core/Akka.TestKit/TestKitBase_Within.cs | 3 +- .../Akka.Tests.Shared.Internals/AkkaSpec.cs | 37 +++++--- ...dScheduler_TellScheduler_Schedule_Tests.cs | 1 + .../Actor/SupervisorHierarchySpec.cs | 6 +- 63 files changed, 466 insertions(+), 503 deletions(-) diff --git a/src/contrib/testkits/Akka.TestKit.Xunit2/XunitAssertions.cs b/src/contrib/testkits/Akka.TestKit.Xunit2/XunitAssertions.cs index be065061215..9a6e632aae2 100644 --- a/src/contrib/testkits/Akka.TestKit.Xunit2/XunitAssertions.cs +++ b/src/contrib/testkits/Akka.TestKit.Xunit2/XunitAssertions.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System; +using System.Threading.Tasks; using Akka.TestKit.Xunit2.Internals; using Xunit; @@ -85,5 +86,25 @@ public void AssertEqual(T expected, T actual, Func comparer, stri if(!comparer(expected, actual)) throw AkkaEqualException.ForMismatchedValues(expected, actual, format, args); } + + public Exception AssertThrows(Action action) + { + return Assert.ThrowsAny(action); + } + + public TException AssertThrows(Action action) where TException : Exception + { + return Assert.ThrowsAny(action); + } + + public async Task AssertThrowsAsync(Func action) + { + return await Assert.ThrowsAnyAsync(action); + } + + public Task AssertThrowsAsync(Func action) where TException : Exception + { + return Assert.ThrowsAnyAsync(action); + } } } diff --git a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveTestKit.DotNet.verified.txt b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveTestKit.DotNet.verified.txt index 0ecde733e61..61b5d33f603 100644 --- a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveTestKit.DotNet.verified.txt +++ b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveTestKit.DotNet.verified.txt @@ -127,6 +127,12 @@ namespace Akka.TestKit void AssertEqual(T expected, T actual, string format = "", params object[] args); void AssertEqual(T expected, T actual, System.Func comparer, string format = "", params object[] args); void AssertFalse(bool condition, string format = "", params object[] args); + System.Exception AssertThrows(System.Action action); + TException AssertThrows(System.Action action) + where TException : System.Exception; + System.Threading.Tasks.Task AssertThrowsAsync(System.Func action); + System.Threading.Tasks.Task AssertThrowsAsync(System.Func action) + where TException : System.Exception; void AssertTrue(bool condition, string format = "", params object[] args); void Fail(string format = "", params object[] args); } @@ -613,13 +619,6 @@ namespace Akka.TestKit.Extensions public class static TaskExtensions { public static System.Threading.Tasks.Task AwaitWithTimeout(this System.Threading.Tasks.Task parentTask, System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken = null) { } - public static System.Threading.Tasks.Task ShouldCompleteWithin(this System.Threading.Tasks.Task task, T expected, System.TimeSpan timeout, string because = "", params object[] becauseArgs) { } - public static System.Threading.Tasks.Task ShouldCompleteWithin(this System.Threading.Tasks.Task task, System.TimeSpan timeout, string because = "", params object[] becauseArgs) { } - public static System.Threading.Tasks.Task ShouldCompleteWithin(this System.Threading.Tasks.Task task, System.TimeSpan timeout, string because = "", params object[] becauseArgs) { } - public static System.Threading.Tasks.Task ShouldThrowWithin(this System.Threading.Tasks.Task task, T expected, System.TimeSpan timeout, string because = "", params object[] becauseArgs) - where T : System.Exception { } - public static System.Threading.Tasks.Task ShouldThrowWithin(this System.Threading.Tasks.Task task, System.TimeSpan timeout, string because = "", params object[] becauseArgs) - where T : System.Exception { } public static System.Threading.Tasks.Task WithTimeout(this System.Threading.Tasks.Task parentTask, System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken = null) { } } } diff --git a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveTestKit.Net.verified.txt b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveTestKit.Net.verified.txt index 7903d26784d..692ecc8345b 100644 --- a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveTestKit.Net.verified.txt +++ b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveTestKit.Net.verified.txt @@ -127,6 +127,12 @@ namespace Akka.TestKit void AssertEqual(T expected, T actual, string format = "", params object[] args); void AssertEqual(T expected, T actual, System.Func comparer, string format = "", params object[] args); void AssertFalse(bool condition, string format = "", params object[] args); + System.Exception AssertThrows(System.Action action); + TException AssertThrows(System.Action action) + where TException : System.Exception; + System.Threading.Tasks.Task AssertThrowsAsync(System.Func action); + System.Threading.Tasks.Task AssertThrowsAsync(System.Func action) + where TException : System.Exception; void AssertTrue(bool condition, string format = "", params object[] args); void Fail(string format = "", params object[] args); } @@ -613,13 +619,6 @@ namespace Akka.TestKit.Extensions public class static TaskExtensions { public static System.Threading.Tasks.Task AwaitWithTimeout(this System.Threading.Tasks.Task parentTask, System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken = null) { } - public static System.Threading.Tasks.Task ShouldCompleteWithin(this System.Threading.Tasks.Task task, T expected, System.TimeSpan timeout, string because = "", params object[] becauseArgs) { } - public static System.Threading.Tasks.Task ShouldCompleteWithin(this System.Threading.Tasks.Task task, System.TimeSpan timeout, string because = "", params object[] becauseArgs) { } - public static System.Threading.Tasks.Task ShouldCompleteWithin(this System.Threading.Tasks.Task task, System.TimeSpan timeout, string because = "", params object[] becauseArgs) { } - public static System.Threading.Tasks.Task ShouldThrowWithin(this System.Threading.Tasks.Task task, T expected, System.TimeSpan timeout, string because = "", params object[] becauseArgs) - where T : System.Exception { } - public static System.Threading.Tasks.Task ShouldThrowWithin(this System.Threading.Tasks.Task task, System.TimeSpan timeout, string because = "", params object[] becauseArgs) - where T : System.Exception { } public static System.Threading.Tasks.Task WithTimeout(this System.Threading.Tasks.Task parentTask, System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken = null) { } } } diff --git a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveTestKitXunit2.DotNet.verified.txt b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveTestKitXunit2.DotNet.verified.txt index df82f81663c..41f0bab0113 100644 --- a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveTestKitXunit2.DotNet.verified.txt +++ b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveTestKitXunit2.DotNet.verified.txt @@ -70,6 +70,12 @@ namespace Akka.TestKit.Xunit2 public void AssertEqual(T expected, T actual, string format = "", params object[] args) { } public void AssertEqual(T expected, T actual, System.Func comparer, string format = "", params object[] args) { } public void AssertFalse(bool condition, string format = "", params object[] args) { } + public System.Exception AssertThrows(System.Action action) { } + public TException AssertThrows(System.Action action) + where TException : System.Exception { } + public System.Threading.Tasks.Task AssertThrowsAsync(System.Func action) { } + public System.Threading.Tasks.Task AssertThrowsAsync(System.Func action) + where TException : System.Exception { } public void AssertTrue(bool condition, string format = "", params object[] args) { } public void Fail(string format = "", params object[] args) { } } diff --git a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveTestKitXunit2.Net.verified.txt b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveTestKitXunit2.Net.verified.txt index 881e30f215f..ed14b3aa484 100644 --- a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveTestKitXunit2.Net.verified.txt +++ b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveTestKitXunit2.Net.verified.txt @@ -70,6 +70,12 @@ namespace Akka.TestKit.Xunit2 public void AssertEqual(T expected, T actual, string format = "", params object[] args) { } public void AssertEqual(T expected, T actual, System.Func comparer, string format = "", params object[] args) { } public void AssertFalse(bool condition, string format = "", params object[] args) { } + public System.Exception AssertThrows(System.Action action) { } + public TException AssertThrows(System.Action action) + where TException : System.Exception { } + public System.Threading.Tasks.Task AssertThrowsAsync(System.Func action) { } + public System.Threading.Tasks.Task AssertThrowsAsync(System.Func action) + where TException : System.Exception { } public void AssertTrue(bool condition, string format = "", params object[] args) { } public void Fail(string format = "", params object[] args) { } } diff --git a/src/core/Akka.Cluster.Tests/ClusterLogSpec.cs b/src/core/Akka.Cluster.Tests/ClusterLogSpec.cs index aabcca5d445..7f5790dc382 100644 --- a/src/core/Akka.Cluster.Tests/ClusterLogSpec.cs +++ b/src/core/Akka.Cluster.Tests/ClusterLogSpec.cs @@ -72,7 +72,7 @@ await EventFilter tcs.TrySetResult(true); }); _cluster.Join(_selfAddress); - await tcs.Task.ShouldCompleteWithin(10.Seconds()); + await tcs.Task.WaitAsync(10.Seconds()); }); } @@ -92,7 +92,7 @@ await EventFilter tcs.TrySetResult(true); }); _cluster.Down(_selfAddress); - await tcs.Task.ShouldCompleteWithin(10.Seconds()); + await tcs.Task.WaitAsync(10.Seconds()); }); } } @@ -124,9 +124,9 @@ public ClusterLogVerboseDefaultSpec(ITestOutputHelper output) public async Task A_cluster_must_not_log_verbose_cluster_events_by_default() { _cluster.Settings.LogInfoVerbose.ShouldBeFalse(); - await JoinAsync(upLogMessage).ShouldThrowWithin(11.Seconds()); + await AssertThrowsAsync(() => JoinAsync(upLogMessage)).WaitAsync(11.Seconds()); await AwaitUpAsync(); - await DownAsync(downLogMessage).ShouldThrowWithin(11.Seconds()); + await AssertThrowsAsync(() => DownAsync(downLogMessage)).WaitAsync(11.Seconds()); } } diff --git a/src/core/Akka.Cluster.Tests/ClusterSpec.cs b/src/core/Akka.Cluster.Tests/ClusterSpec.cs index 5a55b84cd0f..65d9f419074 100644 --- a/src/core/Akka.Cluster.Tests/ClusterSpec.cs +++ b/src/core/Akka.Cluster.Tests/ClusterSpec.cs @@ -205,7 +205,7 @@ public async Task A_cluster_must_complete_LeaveAsync_task_upon_being_removed() var removed = (ClusterEvent.MemberRemoved)await probe.FishForMessageAsync(m => m is ClusterEvent.MemberRemoved); removed.PreviousStatus.Should().BeEquivalentTo(MemberStatus.Exiting); - await leaveTask.ShouldCompleteWithin(RemainingOrDefault); + await leaveTask.WaitAsync(RemainingOrDefault); // A second call for LeaveAsync should complete immediately (should be the same task as before) Cluster.Get(sys2).LeaveAsync().IsCompleted.Should().BeTrue(); @@ -235,7 +235,7 @@ await WithinAsync(TimeSpan.FromSeconds(10), async () => }); // LeaveAsync() task expected to complete immediately - await _cluster.LeaveAsync().ShouldCompleteWithin(RemainingOrDefault); + await _cluster.LeaveAsync().WaitAsync(RemainingOrDefault); } [Fact] @@ -324,14 +324,14 @@ public async Task A_cluster_must_be_able_to_JoinAsync() try { - await _cluster.JoinAsync(_selfAddress).ShouldCompleteWithin(timeout); + await _cluster.JoinAsync(_selfAddress).WaitAsync(timeout); LeaderActions(); // Member should already be up _cluster.Subscribe(TestActor, ClusterEvent.InitialStateAsEvents, typeof(ClusterEvent.IMemberEvent)); await ExpectMsgAsync(); // join second time - response should be immediate success - await _cluster.JoinAsync(_selfAddress).ShouldCompleteWithin(100.Milliseconds()); + await _cluster.JoinAsync(_selfAddress).WaitAsync(100.Milliseconds()); } finally { @@ -346,7 +346,7 @@ await Awaiting(async () => await task; }) .Should().ThrowAsync() - .ShouldCompleteWithin(timeout); + .WaitAsync(timeout); } [Fact] @@ -370,7 +370,7 @@ await Awaiting(async () => await task; }) .Should().ThrowAsync() - .ShouldCompleteWithin(15.Seconds()); + .WaitAsync(15.Seconds()); } finally { @@ -385,14 +385,14 @@ public async Task A_cluster_must_be_able_to_join_async_to_seed_nodes() try { - await _cluster.JoinSeedNodesAsync(new[] { _selfAddress }).ShouldCompleteWithin(timeout); + await _cluster.JoinSeedNodesAsync(new[] { _selfAddress }).WaitAsync(timeout); LeaderActions(); // Member should already be up _cluster.Subscribe(TestActor, ClusterEvent.InitialStateAsEvents, typeof(ClusterEvent.IMemberEvent)); await ExpectMsgAsync(); // join second time - response should be immediate success - await _cluster.JoinSeedNodesAsync(new[] { _selfAddress }).ShouldCompleteWithin(100.Milliseconds()); + await _cluster.JoinSeedNodesAsync(new[] { _selfAddress }).WaitAsync(100.Milliseconds()); } finally { @@ -407,7 +407,7 @@ await Awaiting(async () => await ExpectMsgAsync(); }) .Should().ThrowAsync() - .ShouldCompleteWithin(timeout); + .WaitAsync(timeout); } [Fact] @@ -431,7 +431,7 @@ await Awaiting(async () => await task; }) .Should().ThrowAsync() - .ShouldCompleteWithin(15.Seconds()); + .WaitAsync(15.Seconds()); } finally { @@ -477,7 +477,7 @@ public async Task A_cluster_must_leave_via_CoordinatedShutdownRun() var removed = (ClusterEvent.MemberRemoved)await probe.FishForMessageAsync(m => m is ClusterEvent.MemberRemoved); new [] {MemberStatus.Exiting, MemberStatus.Leaving}.Should().Contain(removed.PreviousStatus); - await task.ShouldCompleteWithin(3.Seconds()); + await task.WaitAsync(3.Seconds()); } finally { @@ -537,7 +537,7 @@ public async Task A_cluster_must_terminate_ActorSystem_via_leave_CoordinatedShut var probe = CreateTestProbe(sys2); Cluster.Get(sys2).Subscribe(probe.Ref, typeof(ClusterEvent.IMemberEvent)); await probe.ExpectMsgAsync(); - await Cluster.Get(sys2).JoinAsync(Cluster.Get(sys2).SelfAddress).ShouldCompleteWithin(10.Seconds()); + await Cluster.Get(sys2).JoinAsync(Cluster.Get(sys2).SelfAddress).WaitAsync(10.Seconds()); await probe.ExpectMsgAsync(); Cluster.Get(sys2).Leave(Cluster.Get(sys2).SelfAddress); @@ -546,7 +546,7 @@ public async Task A_cluster_must_terminate_ActorSystem_via_leave_CoordinatedShut // MemberExited might not be published before MemberRemoved var removed = (ClusterEvent.MemberRemoved)await probe.FishForMessageAsync(m => m is ClusterEvent.MemberRemoved); removed.PreviousStatus.Should().BeEquivalentTo(MemberStatus.Exiting); - await sys2.WhenTerminated.ShouldCompleteWithin(10.Seconds()); + await sys2.WhenTerminated.WaitAsync(10.Seconds()); Cluster.Get(sys2).IsTerminated.Should().BeTrue(); CoordinatedShutdown.Get(sys2).ShutdownReason.Should().BeOfType(); } @@ -572,14 +572,14 @@ public async Task A_cluster_must_terminate_ActorSystem_via_Down_CoordinatedShutd var probe = CreateTestProbe(sys3); Cluster.Get(sys3).Subscribe(probe.Ref, typeof(ClusterEvent.IMemberEvent)); await probe.ExpectMsgAsync(); - await Cluster.Get(sys3).JoinAsync(Cluster.Get(sys3).SelfAddress).ShouldCompleteWithin(10.Seconds()); + await Cluster.Get(sys3).JoinAsync(Cluster.Get(sys3).SelfAddress).WaitAsync(10.Seconds()); await probe.ExpectMsgAsync(); Cluster.Get(sys3).Down(Cluster.Get(sys3).SelfAddress); await probe.ExpectMsgAsync(); await probe.ExpectMsgAsync(); - await sys3.WhenTerminated.ShouldCompleteWithin(10.Seconds()); + await sys3.WhenTerminated.WaitAsync(10.Seconds()); Cluster.Get(sys3).IsTerminated.Should().BeTrue(); CoordinatedShutdown.Get(sys3).ShutdownReason.Should().BeOfType(); } diff --git a/src/core/Akka.Remote.Tests/Transport/ThrottlerTransportAdapterSpec.cs b/src/core/Akka.Remote.Tests/Transport/ThrottlerTransportAdapterSpec.cs index 21c4caad453..1ed0e0c3abf 100644 --- a/src/core/Akka.Remote.Tests/Transport/ThrottlerTransportAdapterSpec.cs +++ b/src/core/Akka.Remote.Tests/Transport/ThrottlerTransportAdapterSpec.cs @@ -147,7 +147,7 @@ protected override void OnReceive(object message) private async Task Here() { var identity = await Sys.ActorSelection(RootB / "user" / "echo").Ask(new Identify(null)) - .ShouldCompleteWithin(DefaultTimeout); + .WaitAsync(DefaultTimeout); return identity.Subject; } @@ -158,7 +158,7 @@ private Task Throttle(ThrottleTransportAdapter.Direction direction, Thrott Sys.AsInstanceOf().Provider.AsInstanceOf().Transport; return transport.ManagementCommand(new SetThrottle(rootBAddress, direction, mode)) - .ShouldCompleteWithin(DefaultTimeout); + .WaitAsync(DefaultTimeout); } private Task Disassociate() @@ -168,7 +168,7 @@ private Task Disassociate() Sys.AsInstanceOf().Provider.AsInstanceOf().Transport; return transport.ManagementCommand(new ForceDisassociate(rootBAddress)) - .ShouldCompleteWithin(DefaultTimeout); + .WaitAsync(DefaultTimeout); } #endregion @@ -188,7 +188,7 @@ public async Task ThrottlerTransportAdapter_must_maintain_average_message_rate() await Throttle( ThrottleTransportAdapter.Direction.Send, new Remote.Transport.TokenBucket(PingPacketSize * 4, BytesPerSecond, 0, 0)) - .ShouldCompleteWithin(true, TimeSpan.FromSeconds(3)); + .WaitAsync(TimeSpan.FromSeconds(3)); var here = await Here(); var tester = Sys.ActorOf(Props.Create(() => new ThrottlingTester(here, TestActor))); @@ -199,7 +199,7 @@ await Throttle( time.Should().BeGreaterThan(TotalTime - 12); await Throttle(ThrottleTransportAdapter.Direction.Send, Unthrottled.Instance) - .ShouldCompleteWithin(true, TimeSpan.FromSeconds(3)); + .WaitAsync(TimeSpan.FromSeconds(3)); } [Fact] @@ -214,15 +214,15 @@ public async Task ThrottlerTransportAdapter_must_survive_blackholing() MuteDeadLetters(_systemB, typeof(ThrottlingTester.Lost)); await Throttle(ThrottleTransportAdapter.Direction.Both, Blackhole.Instance) - .ShouldCompleteWithin(true, 3.Seconds()); + .WaitAsync(3.Seconds()); here.Tell(new ThrottlingTester.Lost("BlackHole 2")); await ExpectNoMsgAsync(TimeSpan.FromSeconds(1)); - await Disassociate().ShouldCompleteWithin(true, TimeSpan.FromSeconds(3)); + await Disassociate().WaitAsync(TimeSpan.FromSeconds(3)); await ExpectNoMsgAsync(TimeSpan.FromSeconds(1)); await Throttle(ThrottleTransportAdapter.Direction.Both, Unthrottled.Instance) - .ShouldCompleteWithin(true, TimeSpan.FromSeconds(3)); + .WaitAsync(TimeSpan.FromSeconds(3)); // after we remove the Blackhole we can't be certain of the state // of the connection, repeat until success diff --git a/src/core/Akka.Streams.TestKit/Akka.Streams.TestKit.csproj b/src/core/Akka.Streams.TestKit/Akka.Streams.TestKit.csproj index c0c21e179cf..e8fab6ee40d 100644 --- a/src/core/Akka.Streams.TestKit/Akka.Streams.TestKit.csproj +++ b/src/core/Akka.Streams.TestKit/Akka.Streams.TestKit.csproj @@ -12,6 +12,10 @@ + + + + diff --git a/src/core/Akka.Streams.TestKit/Utils.cs b/src/core/Akka.Streams.TestKit/Utils.cs index 8e13e29c1ff..e70fe69757e 100644 --- a/src/core/Akka.Streams.TestKit/Utils.cs +++ b/src/core/Akka.Streams.TestKit/Utils.cs @@ -16,8 +16,6 @@ using Akka.TestKit; using Akka.TestKit.Extensions; using Akka.Util.Internal; -using FluentAssertions; -using FluentAssertions.Extensions; namespace Akka.Streams.TestKit { @@ -67,15 +65,12 @@ public static async Task AssertAllStagesStoppedAsync( TimeSpan? timeout = null, CancellationToken cancellationToken = default) { - timeout ??= 20.Seconds(); - var result = await block().ShouldCompleteWithin(timeout.Value); + timeout ??= TimeSpan.FromSeconds(20); + var result = await block().WaitAsync(timeout.Value, cancellationToken); if (materializer is not ActorMaterializerImpl impl) return result; var probe = spec.CreateTestProbe(impl.System); - probe.Send(impl.Supervisor, StreamSupervisor.StopChildren.Instance); - await probe.ExpectMsgAsync(cancellationToken: cancellationToken); - await probe.WithinAsync(TimeSpan.FromSeconds(5), async () => { IImmutableSet children = ImmutableHashSet.Empty; @@ -83,6 +78,9 @@ await probe.WithinAsync(TimeSpan.FromSeconds(5), async () => { await probe.AwaitAssertAsync(async () => { + impl.Supervisor.Tell(StreamSupervisor.StopChildren.Instance, probe.Ref); + await probe.ExpectMsgAsync(cancellationToken: cancellationToken); + impl.Supervisor.Tell(StreamSupervisor.GetChildren.Instance, probe.Ref); children = (await probe.ExpectMsgAsync(cancellationToken: cancellationToken)).Refs; if (children.Count != 0) @@ -113,12 +111,5 @@ public static void AssertDispatcher(IActorRef @ref, string dispatcher) if (r.Underlying.Props.Dispatcher != dispatcher) throw new Exception($"Expected {@ref} to use dispatcher [{dispatcher}], yet used : [{r.Underlying.Props.Dispatcher}]"); } - - [Obsolete("Use ShouldCompleteWithin instead")] - public static T AwaitResult(this Task task, TimeSpan? timeout = null) - { - task.Wait(timeout??TimeSpan.FromSeconds(3)).Should().BeTrue(); - return task.Result; - } } } diff --git a/src/core/Akka.Streams.Tests/ActorMaterializerSpec.cs b/src/core/Akka.Streams.Tests/ActorMaterializerSpec.cs index 9e43d0d8ec5..b271d43f066 100644 --- a/src/core/Akka.Streams.Tests/ActorMaterializerSpec.cs +++ b/src/core/Akka.Streams.Tests/ActorMaterializerSpec.cs @@ -44,7 +44,7 @@ public async Task ActorMaterializer_should_properly_shut_down_actors_associated_ m.Shutdown(); - Func task = () => f.ShouldCompleteWithin(3.Seconds()); + Func task = () => f.WaitAsync(3.Seconds()); await task.Should().ThrowAsync(); } diff --git a/src/core/Akka.Streams.Tests/BugSpec.cs b/src/core/Akka.Streams.Tests/BugSpec.cs index 606ebb4cc98..4c497a6ed44 100644 --- a/src/core/Akka.Streams.Tests/BugSpec.cs +++ b/src/core/Akka.Streams.Tests/BugSpec.cs @@ -52,7 +52,7 @@ public async Task Issue_4580_EmptyByteStringCausesPipeToBeClosed() var readFromStreamTask = StreamConverters.FromInputStream(() => clientPipe, 1) .RunForeach(bs => result.Add(bs.ToString(Encoding.ASCII)), Materializer); - await Task.WhenAll(writeToStreamTask, readFromStreamTask).ShouldCompleteWithin(3.Seconds()); + await Task.WhenAll(writeToStreamTask, readFromStreamTask).WaitAsync(3.Seconds()); var expected = Enumerable.Range(0, 100) .SelectMany(i => i == 10 ? Array.Empty() : i.ToString().Select(c => c.ToString())); diff --git a/src/core/Akka.Streams.Tests/Dsl/AsyncEnumerableSpec.cs b/src/core/Akka.Streams.Tests/Dsl/AsyncEnumerableSpec.cs index af6cdf9efee..e69383d331e 100644 --- a/src/core/Akka.Streams.Tests/Dsl/AsyncEnumerableSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/AsyncEnumerableSpec.cs @@ -58,7 +58,7 @@ await Awaiting(async () => { cts.Cancel(); } - }).Should().ThrowAsync().ShouldCompleteWithin(3.Seconds()); + }).Should().ThrowAsync().WaitAsync(3.Seconds()); }, Materializer); } @@ -69,7 +69,7 @@ await this.AssertAllStagesStoppedAsync(async () => { var input = Enumerable.Range(1, 6).ToList(); var asyncEnumerable = Source.From(input).RunAsAsyncEnumerable(Materializer); - var output = await asyncEnumerable.ToListAsync().AsTask().ShouldCompleteWithin(3.Seconds()); + var output = await asyncEnumerable.ToListAsync().AsTask().WaitAsync(3.Seconds()); output.Should().BeEquivalentTo(input, options => options.WithStrictOrdering()); }, Materializer); } @@ -82,10 +82,10 @@ await this.AssertAllStagesStoppedAsync(async () => var input = Enumerable.Range(1, 6).ToList(); var asyncEnumerable = Source.From(input).RunAsAsyncEnumerable(Materializer); - var output = await asyncEnumerable.ToListAsync().AsTask().ShouldCompleteWithin(3.Seconds()); + var output = await asyncEnumerable.ToListAsync().AsTask().WaitAsync(3.Seconds()); output.Should().BeEquivalentTo(input, options => options.WithStrictOrdering()); - output = await asyncEnumerable.ToListAsync().AsTask().ShouldCompleteWithin(3.Seconds()); + output = await asyncEnumerable.ToListAsync().AsTask().WaitAsync(3.Seconds()); output.Should().BeEquivalentTo(input, options => options.WithStrictOrdering()); }, Materializer); } @@ -114,7 +114,7 @@ public async Task RunAsAsyncEnumerable_Throws_on_Abrupt_Stream_termination() var thrown = false; try { - await a.ShouldCompleteWithin(10.Seconds()); + await a.WaitAsync(10.Seconds()); } catch (StreamDetachedException) { @@ -141,7 +141,7 @@ await Awaiting(async () => await foreach (var a in task) { } - }).Should().ThrowAsync().ShouldCompleteWithin(3.Seconds()); + }).Should().ThrowAsync().WaitAsync(3.Seconds()); } [Fact] diff --git a/src/core/Akka.Streams.Tests/Dsl/AttributesSpec.cs b/src/core/Akka.Streams.Tests/Dsl/AttributesSpec.cs index 8a9cb4f60f1..1c831c45d52 100644 --- a/src/core/Akka.Streams.Tests/Dsl/AttributesSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/AttributesSpec.cs @@ -41,7 +41,7 @@ public async Task Attributes_must_be_overridable_on_a_module_basis() Keep.Right); var task = runnable.Run(Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.GetAttribute().Value.Should().Contain("new-name"); } @@ -60,7 +60,7 @@ public async Task Attributes_must_keep_the_outermost_attribute_as_the_least_spec .ToMaterialized(AttributesSink.Create(), Keep.Right) .WithAttributes(Attributes.CreateName("new-name")) .Run(Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.GetAttribute().Value.Should().Contain("attributesSink"); } diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowAggregateAsyncSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowAggregateAsyncSpec.cs index 87ee61b6776..b07d6a28ff1 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowAggregateAsyncSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowAggregateAsyncSpec.cs @@ -60,7 +60,7 @@ public async Task A_AggregateAsync_must_work_when_using_Source_AggregateAsync() await this.AssertAllStagesStoppedAsync(async() => { var task = AggregateSource.RunWith(Sink.First(), Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().Be(Expected); }, Materializer); } @@ -71,7 +71,7 @@ public async Task A_AggregateAsync_must_work_when_using_Sink_AggregateAsync() await this.AssertAllStagesStoppedAsync(async() => { var task = InputSource.RunWith(AggregateSink, Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().Be(Expected); }, Materializer); } @@ -83,7 +83,7 @@ public async Task A_AggregateAsync_must_work_when_using_Flow_AggregateAsync() await this.AssertAllStagesStoppedAsync(async() => { var task = InputSource.Via(AggregateFlow).RunWith(Sink.First(), Materializer); - var complete = await task.ShouldCompleteWithin(flowTimeout); + var complete = await task.WaitAsync(flowTimeout); complete.Should().Be(Expected); }, Materializer); } @@ -94,7 +94,7 @@ public async Task A_AggregateAsync_must_work_when_using_Source_AggregateAsync_an await this.AssertAllStagesStoppedAsync(async() => { var task = AggregateSource.Via(AggregateFlow).RunWith(AggregateSink, Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().Be(Expected); }, Materializer); } @@ -273,7 +273,7 @@ await this.AssertAllStagesStoppedAsync(async () => var result = await Source.From(tasks) .AggregateAsync(string.Empty, (_, t) => t) .WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.ResumingDecider)) - .RunWith(Sink.First(), Materializer).ShouldCompleteWithin(3.Seconds()); + .RunWith(Sink.First(), Materializer).WaitAsync(3.Seconds()); result.Should().Be("happy!"); }, Materializer); @@ -293,7 +293,7 @@ await this.AssertAllStagesStoppedAsync(async() => .WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.ResumingDecider)) .Grouped(10) .RunWith(Sink.First>(), Materializer) - .ShouldCompleteWithin(3.Seconds()); + .WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(2); }, Materializer); } @@ -425,7 +425,7 @@ await this.AssertAllStagesStoppedAsync(async() => { var task = Source.From(Enumerable.Empty()) .RunAggregateAsync(0, (acc, element) => Task.FromResult(acc + element), Materializer); - var complete = await task.ShouldCompleteWithin(RemainingOrDefault); + var complete = await task.WaitAsync(RemainingOrDefault); complete.ShouldBe(0); }, Materializer); } @@ -437,7 +437,7 @@ await this.AssertAllStagesStoppedAsync(async() => { var task = Source.Single(100) .RunAggregateAsync(5, (acc, element) => Task.FromResult(acc + element), Materializer); - var complete = await task.ShouldCompleteWithin(RemainingOrDefault); + var complete = await task.WaitAsync(RemainingOrDefault); complete.ShouldBe(105); }, Materializer); } diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowAggregateSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowAggregateSpec.cs index 2cf148976a8..2de01d86050 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowAggregateSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowAggregateSpec.cs @@ -42,7 +42,7 @@ public async Task A_Aggregate_must_work_when_using_Source_RunAggregate() await this.AssertAllStagesStoppedAsync(async() => { var task = InputSource.RunAggregate(0, (sum, i) => sum + i, Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().Be(Expected); }, Materializer); } @@ -53,7 +53,7 @@ public async Task A_Aggregate_must_work_when_using_Source_Aggregate() await this.AssertAllStagesStoppedAsync(async() => { var task = AggregateSource.RunWith(Sink.First(), Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().Be(Expected); }, Materializer); } @@ -64,7 +64,7 @@ public async Task A_Aggregate_must_work_when_using_Sink_Aggregate() await this.AssertAllStagesStoppedAsync(async() => { var task = InputSource.RunWith(AggregateSink, Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().Be(Expected); }, Materializer); } @@ -75,7 +75,7 @@ public async Task A_Aggregate_must_work_when_using_Flow_Aggregate() await this.AssertAllStagesStoppedAsync(async() => { var task = InputSource.Via(AggregateFlow).RunWith(Sink.First(), Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().Be(Expected); }, Materializer); } @@ -86,7 +86,7 @@ public async Task A_Aggregate_must_work_when_using_Source_Aggregate_and_Flow_Agg await this.AssertAllStagesStoppedAsync(async() => { var task = AggregateSource.Via(AggregateFlow).RunWith(AggregateSink, Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().Be(Expected); }, Materializer); } @@ -148,7 +148,7 @@ await this.AssertAllStagesStoppedAsync(async() => var task = InputSource.RunWith( aggregate.WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.ResumingDecider)), Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().Be(Expected - 50); }, Materializer); } @@ -169,7 +169,7 @@ await this.AssertAllStagesStoppedAsync(async() => var task = InputSource.RunWith( aggregate.WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.RestartingDecider)), Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().Be(Enumerable.Range(51, 50).Sum()); }, Materializer); } @@ -181,7 +181,7 @@ await this.AssertAllStagesStoppedAsync(async() => { var task = Source.From(Enumerable.Empty()) .RunAggregate(0, (acc, element) => acc + element, Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().Be(0); }, Materializer); } diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowAskSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowAskSpec.cs index cde14790a75..61a7e5e8932 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowAskSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowAskSpec.cs @@ -275,7 +275,7 @@ await InterceptAsync(async () => { r.Tell(PoisonPill.Instance); await done; - }).ShouldCompleteWithin(RemainingOrDefault); + }).WaitAsync(RemainingOrDefault); }, _materializer); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowBatchSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowBatchSpec.cs index f31914ac20c..db23e69ccf7 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowBatchSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowBatchSpec.cs @@ -87,7 +87,7 @@ public async Task Batch_must_work_on_a_variable_rate_chain() Thread.Sleep(10); return i; }).RunAggregate(0, (i, i1) => i + i1, Materializer); - var result = await task.ShouldCompleteWithin(10.Seconds()); + var result = await task.WaitAsync(10.Seconds()); result.Should().Be(500500); } diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowFlattenMergeSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowFlattenMergeSpec.cs index 89b8b2940e2..ec0c8eec23b 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowFlattenMergeSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowFlattenMergeSpec.cs @@ -54,7 +54,7 @@ await this.AssertAllStagesStoppedAsync(async () => var task = Source.From(new[] {Src10(0), Src10(10), Src10(20), Src10(30)}) .MergeMany(4, s => s) .RunWith(ToSet, Materializer); - await task.ShouldCompleteWithin(1.Seconds()); + await task.WaitAsync(1.Seconds()); task.Result.Should().BeEquivalentTo(Enumerable.Range(0, 40)); }, Materializer); } @@ -68,7 +68,7 @@ await this.AssertAllStagesStoppedAsync(async () => .MergeMany(3, s => s) .Take(40) .RunWith(ToSet, Materializer); - await task.ShouldCompleteWithin(1.Seconds()); + await task.WaitAsync(1.Seconds()); task.Result.Should().BeEquivalentTo(Enumerable.Range(0, 40)); }, Materializer); } @@ -83,7 +83,7 @@ await this.AssertAllStagesStoppedAsync(async () => .Take(40) .RunWith(ToSeq, Materializer); - await task.ShouldCompleteWithin(1.Seconds()); + await task.WaitAsync(1.Seconds()); task.Result.Take(30).Should().BeEquivalentTo(Enumerable.Range(0, 30)); task.Result.Drop(30).Should().BeEquivalentTo(Enumerable.Range(30, 10)); @@ -100,7 +100,7 @@ await this.AssertAllStagesStoppedAsync(async () => .MergeMany(1, x => x) .RunWith(Sink.First(), Materializer); - (await Awaiting(() => future.ShouldCompleteWithin(1.Seconds())) + (await Awaiting(() => future.WaitAsync(1.Seconds())) .Should().ThrowAsync()).And.Should().Be(ex); }, Materializer); } @@ -117,7 +117,7 @@ await this.AssertAllStagesStoppedAsync(async () => .MergeMany(10, x => x) .RunWith(Sink.First(), Materializer); - (await Awaiting(() => future.ShouldCompleteWithin(1.Seconds())) + (await Awaiting(() => future.WaitAsync(1.Seconds())) .Should().ThrowAsync()).And.Should().Be(ex); }, Materializer); } @@ -137,7 +137,7 @@ await this.AssertAllStagesStoppedAsync(async () => }) .RunWith(Sink.First(), Materializer); - (await Awaiting(() => future.ShouldCompleteWithin(1.Seconds())) + (await Awaiting(() => future.WaitAsync(1.Seconds())) .Should().ThrowAsync()).And.Should().Be(ex); }, Materializer); } @@ -152,7 +152,7 @@ await this.AssertAllStagesStoppedAsync(async () => .MergeMany(10, x => x) .RunWith(Sink.First(), Materializer); - (await Awaiting(() => future.ShouldCompleteWithin(1.Seconds())) + (await Awaiting(() => future.WaitAsync(1.Seconds())) .Should().ThrowAsync()).And.Should().Be(ex); }, Materializer); } @@ -333,7 +333,7 @@ await this.AssertAllStagesStoppedAsync(async () => .AddAttributes(Attributes.CreateName("outer")) .RunWith(Sink.First(), Materializer); - var attributes = (await task.ShouldCompleteWithin(3.Seconds())).AttributeList.ToList(); + var attributes = (await task.WaitAsync(3.Seconds())).AttributeList.ToList(); var innerName = new Attributes.Name("inner"); var outerName = new Attributes.Name("outer"); @@ -354,7 +354,7 @@ await this.AssertAllStagesStoppedAsync(async () => .MergeMany(4, _ => Source.FromGraph(new FailingInnerMat(matFail))) .RunWith(Sink.Ignore(), Materializer); - await task.ShouldThrowWithin(matFail, 1.Seconds()); + await AssertThrowsAsync(async () => await task).WaitAsync(1.Seconds()); }, Materializer); } diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowGroupBySpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowGroupBySpec.cs index 9dc063bc111..233cba231e1 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowGroupBySpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowGroupBySpec.cs @@ -100,7 +100,7 @@ await this.AssertAllStagesStoppedAsync(async () => ((Source>, NotUsed>)source).RunWith( Sink.First>>(), Materializer); - await task.ShouldCompleteWithin(3.Seconds()); + await task.WaitAsync(3.Seconds()); task.Result.OrderBy(e => e.First()) .Should().BeEquivalentTo(new[] { "Aaa", "Abb" }, new[] { "Bcc" }, new[] { "Cdd", "Cee" }); }, Materializer); @@ -425,7 +425,7 @@ await this.AssertAllStagesStoppedAsync(async () => .Select(t => t.Item2) .ConcatSubstream(); var futureGroupSource = source.RunWith(Sink.First>(), Materializer); - await futureGroupSource.ShouldCompleteWithin(3.Seconds()); + await futureGroupSource.WaitAsync(3.Seconds()); var publisher = futureGroupSource.Result.RunWith(Sink.AsPublisher(false), Materializer); var probe = this.CreateSubscriberProbe(); @@ -731,7 +731,7 @@ await this.AssertAllStagesStoppedAsync(async () => } else { - var probe = await props.Probes[props.ProbesReaderTop].Task.ShouldCompleteWithin(3.Seconds()); + var probe = await props.Probes[props.ProbesReaderTop].Task.WaitAsync(3.Seconds()); props.ProbesReaderTop++; map[index] = new SubFlowState(probe, false, byteString); //stream automatically requests next element diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowOrElseSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowOrElseSpec.cs index 9eac5217fb8..f31cbd48275 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowOrElseSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowOrElseSpec.cs @@ -37,7 +37,7 @@ public async Task An_OrElse_flow_should_pass_elements_from_the_first_input() var sink = Sink.Seq(); - var complete = await source1.OrElse(source2).RunWith(sink, Materializer).ShouldCompleteWithin(3.Seconds()); + var complete = await source1.OrElse(source2).RunWith(sink, Materializer).WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(new[] { 1, 2, 3 }); } @@ -49,7 +49,7 @@ public async Task An_OrElse_flow_should_pass_elements_from_the_second_input_if_t var sink = Sink.Seq(); - var complete = await source1.OrElse(source2).RunWith(sink, Materializer).ShouldCompleteWithin(3.Seconds()); + var complete = await source1.OrElse(source2).RunWith(sink, Materializer).WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(new[] { 4, 5, 6 }); } diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowScanAsyncSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowScanAsyncSpec.cs index 20ab0c3e699..1c2661e931b 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowScanAsyncSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowScanAsyncSpec.cs @@ -67,7 +67,7 @@ public async Task A_ScanAsync_must_work_with_a_large_source() var eventualActual = Source.From(elements) .ScanAsync(0L, (l, l1) => Task.FromResult(l + l1)) .RunWith(Sink.Last(), Materializer); - var complete = await eventualActual.ShouldCompleteWithin(3.Seconds()); + var complete = await eventualActual.WaitAsync(3.Seconds()); complete.ShouldBe(expectedSum); } diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowSelectAsyncSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowSelectAsyncSpec.cs index 9f7c17b3cf2..ba9629d8977 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowSelectAsyncSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowSelectAsyncSpec.cs @@ -123,7 +123,7 @@ await this.AssertAllStagesStoppedAsync(async () => await c.ExpectNextNAsync(Enumerable.Range(1, 13)); await c.ExpectNoMsgAsync(TimeSpan.FromMilliseconds(200)); - }, Materializer).ShouldCompleteWithin(RemainingOrDefault); + }, Materializer).WaitAsync(RemainingOrDefault); } // Turning this on in CI/CD for now @@ -149,7 +149,7 @@ await this.AssertAllStagesStoppedAsync(async() => { var exception = await c.ExpectErrorAsync(); exception.InnerException!.Message.Should().Be("err1"); - }, Materializer).ShouldCompleteWithin(RemainingOrDefault); + }, Materializer).WaitAsync(RemainingOrDefault); } [Fact] @@ -171,7 +171,7 @@ await this.AssertAllStagesStoppedAsync(async() => { .Request(10) .ExpectNextN([1, 2]) .ExpectErrorAsync() - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); exception.Message.Should().Be("err1"); }, Materializer); } @@ -204,7 +204,7 @@ await this.AssertAllStagesStoppedAsync(async () => { await Awaiting(async () => await done).Should() .ThrowAsync() .WithMessage("err1") - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); latch.CountDown(); }, Materializer); @@ -508,7 +508,7 @@ await this.AssertAllStagesStoppedAsync(async() => .Grouped(10) .RunWith(Sink.First>(), Materializer); - var complete = await t.ShouldCompleteWithin(3.Seconds()); + var complete = await t.WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(new[] { 1, 2 }); }, Materializer); } @@ -731,7 +731,7 @@ await this.AssertAllStagesStoppedAsync(async () => return 1; }) .RunAggregate(0, (acc, i) => acc + i, Materializer) - .ShouldCompleteWithin(3.Seconds()); + .WaitAsync(3.Seconds()); result.Should().Be(n); }, Materializer); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowSelectAsyncUnorderedSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowSelectAsyncUnorderedSpec.cs index 0ca58abbaba..c3ef4f882a1 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowSelectAsyncUnorderedSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowSelectAsyncUnorderedSpec.cs @@ -239,7 +239,7 @@ await this.AssertAllStagesStoppedAsync(async() => .WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.ResumingDecider)) .RunWith(Sink.First(), Materializer); - var complete = await t.ShouldCompleteWithin(3.Seconds()); + var complete = await t.WaitAsync(3.Seconds()); complete.Should().Be("happy"); }, Materializer); } diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowSpec.cs index ec1d2bff175..6d25c78ad34 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowSpec.cs @@ -388,7 +388,7 @@ await this.AssertAllStagesStoppedAsync(async () => .Limit(100) .RunWith(Sink.Seq(), Materializer); - await task.ShouldCompleteWithin(3.Seconds()); + await task.WaitAsync(3.Seconds()); task.Result.Should().BeEquivalentTo(Enumerable.Range(1,10)); // Reusable: @@ -397,7 +397,7 @@ await this.AssertAllStagesStoppedAsync(async () => .Limit(100) .RunWith(Sink.Seq(), Materializer); - await task.ShouldCompleteWithin(3.Seconds()); + await task.WaitAsync(3.Seconds()); task.Result.Should().BeEquivalentTo(Enumerable.Range(1, 10)); }, Materializer); } @@ -681,7 +681,7 @@ await this.AssertAllStagesStoppedAsync(async () => .Via(Flow.FromFunction(i => i + 1)) .RunWith(Sink.Seq(), Materializer); - await task.ShouldCompleteWithin(3.Seconds()); + await task.WaitAsync(3.Seconds()); task.Result.Should().BeEquivalentTo(Enumerable.Range(1, 10)); }, Materializer); } @@ -779,7 +779,7 @@ await this.AssertAllStagesStoppedAsync(async () => .ToMaterialized(Sink.First(), Keep.Right); var task = Source.Single(4711).RunWith(sink, noFusingMaterializer); - await task.ShouldCompleteWithin(3.Seconds()); + await task.WaitAsync(3.Seconds()); task.Result.Should().Be(4712); }, Materializer); } diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowSplitWhenSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowSplitWhenSpec.cs index 935133666e4..ac8c42e4e09 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowSplitWhenSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowSplitWhenSpec.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Akka.Pattern; using Akka.Streams.Dsl; @@ -135,7 +136,7 @@ await this.AssertAllStagesStoppedAsync(async () => .RunWith(Sink.FirstOrDefault>(), Materializer); result.Should().BeEquivalentTo(default(IEnumerable)); }, Materializer) - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); } [Fact] @@ -157,8 +158,7 @@ await WithSubstreamsSupportAsync(1, 3, masterSubscription.Request(1); await masterSubscriber.ExpectCompleteAsync(); }); - }, Materializer) - .ShouldCompleteWithin(RemainingOrDefault); + }, Materializer); } [Fact] @@ -186,7 +186,7 @@ await WithSubstreamsSupportAsync(5, 8, await masterSubscriber.ExpectCompleteAsync(); }); }, Materializer) - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); } [Fact] @@ -256,7 +256,7 @@ await this.AssertAllStagesStoppedAsync(async () => { masterStream3.Cancel(); await inputs3.ExpectCancellationAsync(); }, Materializer) - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); } [Fact] @@ -277,9 +277,8 @@ await WithSubstreamsSupportAsync(5, 8, await s1.ExpectNextAsync(4); s1.Request(1); await s1.ExpectCompleteAsync(); - }); - }, Materializer) - .ShouldCompleteWithin(RemainingOrDefault); + }).WaitAsync(TimeSpan.FromSeconds(3)); + }, Materializer); } [Fact] @@ -319,7 +318,7 @@ await this.AssertAllStagesStoppedAsync(async () => { await substreamPuppet.ExpectErrorAsync(ex); await upstreamSubscription.ExpectCancellationAsync(); }, Materializer) - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); } [Fact] @@ -334,7 +333,7 @@ await this.AssertAllStagesStoppedAsync(async () => { .RunWith(Sink.First>(), Materializer); result.Should().BeEquivalentTo(Enumerable.Range(1, 100)); }, Materializer) - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); } [LocalFact(SkipLocal = "Racy on Azure DevOps")] @@ -359,7 +358,7 @@ await Source.Single(1) .RunWith(Sink.Ignore(), Materializer) ).Should().ThrowAsync(); }, Materializer) - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); } [Fact] @@ -385,7 +384,7 @@ await testSource.Lift() .RunWith(Sink.Ignore(), tightTimeoutMaterializer); }).Should().ThrowAsync(); }, Materializer) - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); } [Fact(Skip = "Supervision is not supported fully by GraphStages yet")] @@ -412,7 +411,7 @@ await this.AssertAllStagesStoppedAsync(async () => { var upSub = await up.ExpectSubscriptionAsync(); await upSub.ExpectCancellationAsync(); }, Materializer) - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); } [Fact] @@ -429,7 +428,7 @@ await WithSubstreamsSupportAsync(5, 8, SubstreamCancelStrategy.Propagate, await masterSubscriber.ExpectCompleteAsync(); }); }, Materializer) - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); } } } diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowSumSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowSumSpec.cs index aab4527e75b..afa8c10c5ad 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowSumSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowSumSpec.cs @@ -146,7 +146,7 @@ await this.AssertAllStagesStoppedAsync(async() => var task = InputSource.RunWith( sum.WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.ResumingDecider)), Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().Be(Expected - 50); }, Materializer); } @@ -167,7 +167,7 @@ await this.AssertAllStagesStoppedAsync(async() => var task = InputSource.RunWith( sum.WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.RestartingDecider)), Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().Be(Enumerable.Range(51, 50).Sum()); }, Materializer); } diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowThrottleSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowThrottleSpec.cs index ae0ed8e5223..3bef38c9d07 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowThrottleSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowThrottleSpec.cs @@ -67,7 +67,7 @@ await probe.AsyncBuilder() .ExpectNext(1, 2, 4, 5) .ExpectComplete() .ExecuteAsync() - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); }, Materializer); } @@ -83,7 +83,7 @@ await probe.AsyncBuilder() .ExpectNext(1, 2, 3, 4, 5) .ExpectComplete() .ExecuteAsync() - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); }, Materializer); } @@ -99,7 +99,7 @@ await probe.AsyncBuilder() .ExpectNext(1, 2, 3, 4, 5) .ExpectComplete() .ExecuteAsync() - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); }, Materializer); } @@ -115,7 +115,7 @@ await probe.AsyncBuilder() .ExpectNext(1) .ExpectNoMsg(TimeSpan.FromMilliseconds(100)) .ExecuteAsync() - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); probe.Cancel(); }, Materializer); } @@ -132,7 +132,7 @@ await this.AssertAllStagesStoppedAsync(async () => .Via(sharedThrottle) .Via(sharedThrottle) .RunWith(Sink.First(), Materializer) - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); t.Should().Be(1); // It works with a new stream, too @@ -140,7 +140,7 @@ await this.AssertAllStagesStoppedAsync(async () => .Via(sharedThrottle) .Via(sharedThrottle) .RunWith(Sink.First(), Materializer) - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); t.Should().Be(2); }, Materializer); } @@ -224,7 +224,7 @@ await probe.AsyncBuilder() .ExpectNoMsg(TimeSpan.FromMilliseconds(150)) .ExpectNext(4) .ExecuteAsync() - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); probe.Cancel(); // assertion may take longer then the throttle and therefore the next assertion fails result.Should().BeEquivalentTo(new[] { new OnNext(1), new OnNext(2) }); @@ -323,7 +323,7 @@ await this.AssertAllStagesStoppedAsync(async () => var t1 = await Source.From(Enumerable.Range(1, 5)) .Throttle(1, TimeSpan.FromMilliseconds(200), 5, ThrottleMode.Enforcing) .RunWith(Sink.Seq(), Materializer) // Burst is 5 so this will not fail - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); t1.Should().BeEquivalentTo(Enumerable.Range(1, 5)); await Awaiting(async () => @@ -332,7 +332,7 @@ await Source.From(Enumerable.Range(1, 6)) .Throttle(1, TimeSpan.FromMilliseconds(200), 5, ThrottleMode.Enforcing) .RunWith(Sink.Ignore(), Materializer); }).Should().ThrowAsync() - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); }, Materializer); } @@ -350,7 +350,7 @@ await probe.AsyncBuilder() .ExpectNext(1, 2, 3, 4, 5) .ExpectComplete() .ExecuteAsync() - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); }, Materializer); } @@ -366,7 +366,7 @@ await probe.AsyncBuilder() .ExpectNext(1, 2, 3, 4, 5) .ExpectComplete() .ExecuteAsync() - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); }, Materializer); } @@ -390,7 +390,7 @@ await probe.AsyncBuilder() .ExpectNext(list[3]) .ExpectComplete() .ExecuteAsync() - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); }, Materializer); } @@ -449,7 +449,7 @@ await probe.AsyncBuilder() .ExpectNoMsg(TimeSpan.FromMilliseconds(100)) .ExpectNext(4) .ExecuteAsync() - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); probe.Cancel(); // assertion may take longer then the throttle and therefore the next assertion fails @@ -547,7 +547,7 @@ await this.AssertAllStagesStoppedAsync(async () => { var t1 = await Source.From(Enumerable.Range(1, 4)) .Throttle(2, TimeSpan.FromMilliseconds(200), 10, x => x, ThrottleMode.Enforcing) .RunWith(Sink.Seq(), Materializer) - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); t1.Should().BeEquivalentTo(Enumerable.Range(1, 4)); // Burst is 10 so this will not fail await Awaiting(async () => @@ -556,7 +556,7 @@ await Source.From(Enumerable.Range(1, 6)) .Throttle(2, TimeSpan.FromMilliseconds(200), 5, x => x, ThrottleMode.Enforcing) .RunWith(Sink.Ignore(), Materializer); }).Should().ThrowAsync() - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); }, Materializer); } @@ -573,7 +573,7 @@ await probe.AsyncBuilder() .ExpectNext(1, 2, 3, 4, 5) .ExpectComplete() .ExecuteAsync() - .ShouldCompleteWithin(RemainingOrDefault); + .WaitAsync(RemainingOrDefault); }, Materializer); } diff --git a/src/core/Akka.Streams.Tests/Dsl/FramingSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FramingSpec.cs index a8a1ed1d1ee..f7adcf3a891 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FramingSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FramingSpec.cs @@ -203,7 +203,7 @@ public async Task Delimiter_bytes_based_framing_must_allow_truncated_frames_if_c .Grouped(1000) .RunWith(Sink.First>(), Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().ContainSingle(s => s.Equals("I have no end")); } @@ -442,7 +442,7 @@ public async Task Length_field_based_framing_must_fail_the_stage_on_negative_len await Awaiting(async () => await result) .Should().ThrowAsync() .WithMessage("Decoded frame header reported negative size -4") - .ShouldCompleteWithin(3.Seconds()); + .WaitAsync(3.Seconds()); } [Fact] @@ -458,7 +458,7 @@ public async Task Length_field_based_framing_must_ignore_length_field_value_when .Via(Flow.Create().Via(Framing.LengthField(4, 0, 1000, ByteOrder.LittleEndian, ComputeFrameSize))) .RunWith(Sink.Seq(), Materializer); - var complete = await result.ShouldCompleteWithin(3.Seconds()); + var complete = await result.WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(ImmutableArray.Create(bs)); } @@ -477,7 +477,7 @@ public async Task Length_field_based_framing_must_fail_the_stage_on_computeFrame await Awaiting(async () => await result) .Should().ThrowAsync() .WithMessage("Computed frame size 3 is less than minimum chunk size 4") - .ShouldCompleteWithin(3.Seconds()); + .WaitAsync(3.Seconds()); } [Fact] @@ -493,7 +493,7 @@ public async Task Length_field_based_framing_must_let_zero_length_field_values_p .Via(Flow.Create().Via(Framing.LengthField(4, 1000))) .RunWith(Sink.Seq(), Materializer); - var complete = await result.ShouldCompleteWithin(3.Seconds()); + var complete = await result.WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(bytes.ToImmutableList()); } } diff --git a/src/core/Akka.Streams.Tests/Dsl/FutureFlattenSourceSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FutureFlattenSourceSpec.cs index 8f79bed3100..c3ad411e384 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FutureFlattenSourceSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FutureFlattenSourceSpec.cs @@ -44,8 +44,8 @@ await this.AssertAllStagesStoppedAsync(async () => .Run(_materializer); // wait until the underlying task is completed - await sourceMatVal.ShouldCompleteWithin(3.Seconds()); - await sinkMatVal.ShouldCompleteWithin(3.Seconds()); + await sourceMatVal.WaitAsync(3.Seconds()); + await sinkMatVal.WaitAsync(3.Seconds()); // should complete as soon as inner source has been materialized sourceMatVal.Result.Should().Be("foo"); @@ -89,8 +89,8 @@ await this.AssertAllStagesStoppedAsync(async () => sourcePromise.SetResult(Underlying); // wait until the underlying task is completed - await sourceMatVal.ShouldCompleteWithin(3.Seconds()); - await sinkMatVal.ShouldCompleteWithin(3.Seconds()); + await sourceMatVal.WaitAsync(3.Seconds()); + await sinkMatVal.WaitAsync(3.Seconds()); // should complete as soon as inner source has been materialized sourceMatVal.Result.Should().Be("foo"); @@ -124,7 +124,10 @@ await probe.AsyncBuilder() sourcePromise.SetResult(Underlying); // wait until the underlying task is completed - var ex = await sourceMatVal.ShouldThrowWithin(3.Seconds()); + var task = AssertThrowsAsync(() => sourceMatVal); + await task.WaitAsync(3.Seconds()); + + var ex = task.Result; ex.Message.Should().Be("Stream cancelled before Source Task completed"); }, _materializer); } @@ -142,8 +145,8 @@ await this.AssertAllStagesStoppedAsync(async () => .Run(_materializer); // wait until the underlying task is completed - await sourceMatVal.ShouldThrowWithin(failure, 3.Seconds()); - await sinkMatVal.ShouldThrowWithin(failure, 3.Seconds()); + await AssertThrowsAsync(() => sourceMatVal, failure).WaitAsync(3.Seconds()); + await AssertThrowsAsync(() => sinkMatVal, failure).WaitAsync(3.Seconds()); }, _materializer); } @@ -170,8 +173,8 @@ await this.AssertAllStagesStoppedAsync(async () => sourcePromise.SetException(failure); // wait until the underlying tasks are completed - await sourceMatVal.ShouldThrowWithin(failure, 3.Seconds()); - await sinkMatVal.ShouldThrowWithin(failure, 3.Seconds()); + await AssertThrowsAsync(() => sourceMatVal, failure).WaitAsync(3.Seconds()); + await AssertThrowsAsync(() => sinkMatVal, failure).WaitAsync(3.Seconds()); }, _materializer); } @@ -192,7 +195,7 @@ await this.AssertAllStagesStoppedAsync(async () => sourcePromise.SetException(failure); // wait until the underlying tasks are completed - await sourceMatVal.ShouldThrowWithin(failure, 3.Seconds()); + await AssertThrowsAsync(() => sourceMatVal, failure).WaitAsync(3.Seconds()); }, _materializer); } @@ -212,7 +215,7 @@ await this.AssertAllStagesStoppedAsync(async () => await subscriber.EnsureSubscriptionAsync(); sourcePromise.SetResult(Source.FromPublisher(publisher).MapMaterializedValue(_ => "woho")); - await matVal.ShouldCompleteWithin(3.Seconds()); + await matVal.WaitAsync(3.Seconds()); // materialized value completes but still no demand matVal.Result.Should().Be("woho"); @@ -242,7 +245,7 @@ await this.AssertAllStagesStoppedAsync(async () => await subscriber.EnsureSubscriptionAsync(); sourcePromise.SetResult(Source.FromPublisher(publisher).MapMaterializedValue(_ => "woho")); - await matVal.ShouldCompleteWithin(3.Seconds()); + await matVal.WaitAsync(3.Seconds()); // materialized value completes but still no demand matVal.Result.Should().Be("woho"); @@ -264,8 +267,8 @@ await this.AssertAllStagesStoppedAsync(async () => var (innerSourceMat, outerSinkMat) = Source.FromTaskSource(inner).ToMaterialized(Sink.Seq(), Keep.Both).Run(_materializer); // wait until the underlying tasks are completed - await outerSinkMat.ShouldThrowWithin(FailingMatGraphStage.Exception, 3.Seconds()); - await innerSourceMat.ShouldThrowWithin(FailingMatGraphStage.Exception, 3.Seconds()); + await AssertThrowsAsync(() => outerSinkMat, FailingMatGraphStage.Exception).WaitAsync(3.Seconds()); + await AssertThrowsAsync(() => innerSourceMat, FailingMatGraphStage.Exception).WaitAsync(3.Seconds()); }, _materializer); } diff --git a/src/core/Akka.Streams.Tests/Dsl/GraphMergeSortedSpec.cs b/src/core/Akka.Streams.Tests/Dsl/GraphMergeSortedSpec.cs index 7f62d00d12c..49afcb9d42b 100644 --- a/src/core/Akka.Streams.Tests/Dsl/GraphMergeSortedSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/GraphMergeSortedSpec.cs @@ -62,7 +62,7 @@ public async Task MergeSorted_must_work_in_the_nominal_case() .Concat(Source.Single>(new List())) .RunWith(Sink.First>(), Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(Enumerable.Range(0, n), o => o.WithStrictOrdering()); } } @@ -74,7 +74,7 @@ public async Task MergeSorted_must_work_with_custom_comparer() .MergeSorted(Source.From(new[] { 0, 1, 2, 7 }), (l, r) => 2 * l.CompareTo(r)) .RunWith(Sink.Seq(), Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(new[] { 0, 1, 1, 2, 5, 7 }, o => o.WithStrictOrdering()); } } diff --git a/src/core/Akka.Streams.Tests/Dsl/HubSpec.cs b/src/core/Akka.Streams.Tests/Dsl/HubSpec.cs index 601e6874178..c8054b57fdf 100644 --- a/src/core/Akka.Streams.Tests/Dsl/HubSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/HubSpec.cs @@ -45,7 +45,7 @@ await this.AssertAllStagesStoppedAsync(async () => Source.From(Enumerable.Range(1, 10)).RunWith(sink, Materializer); Source.From(Enumerable.Range(11, 10)).RunWith(sink, Materializer); - var result = await task.ShouldCompleteWithin(3.Seconds()); + var result = await task.WaitAsync(3.Seconds()); result.OrderBy(x => x).Should().BeEquivalentTo(Enumerable.Range(1, 20)); }, Materializer); } @@ -78,7 +78,7 @@ await upstream.AsyncBuilder() .ExpectCancellation() .ExecuteAsync(); - var result = await task.ShouldCompleteWithin(3.Seconds()); + var result = await task.WaitAsync(3.Seconds()); result.Should().BeEquivalentTo(Enumerable.Range(1, 5)); }, Materializer); } @@ -98,7 +98,7 @@ await upstream1.AsyncBuilder() .ExpectCancellation() .ExecuteAsync(); - var result = await task.ShouldCompleteWithin(3.Seconds()); + var result = await task.WaitAsync(3.Seconds()); result.Should().BeEquivalentTo(Enumerable.Range(1, 5)); Source.FromPublisher(upstream2).RunWith(sink, Materializer); @@ -175,7 +175,7 @@ await this.AssertAllStagesStoppedAsync(async () => Source.From(Enumerable.Range(1, 10000)).RunWith(sink, Materializer); Source.From(Enumerable.Range(10001, 10000)).RunWith(sink, Materializer); - var result = await task.ShouldCompleteWithin(3.Seconds()); + var result = await task.WaitAsync(3.Seconds()); result.OrderBy(x => x).Should().BeEquivalentTo(Enumerable.Range(1, 20000)); }, Materializer); } @@ -212,7 +212,7 @@ await this.AssertAllStagesStoppedAsync(async () => Source.From(Enumerable.Range(1, 1000)).RunWith(sink, Materializer); Source.From(Enumerable.Range(1001, 1000)).RunWith(sink, Materializer); - var result = await task.ShouldCompleteWithin(3.Seconds()); + var result = await task.WaitAsync(3.Seconds()); result.OrderBy(x => x).Should().BeEquivalentTo(Enumerable.Range(1, 2000)); }, Materializer); @@ -231,7 +231,7 @@ await this.AssertAllStagesStoppedAsync(async () => .RunWith(sink, Materializer); Source.From(Enumerable.Range(1001, 1000)).RunWith(sink, Materializer); - var result = await task.ShouldCompleteWithin(3.Seconds()); + var result = await task.WaitAsync(3.Seconds()); result.OrderBy(x => x).Should().BeEquivalentTo(Enumerable.Range(1, 2000)); }, Materializer); } @@ -270,7 +270,7 @@ await EventFilter.Error(contains: "Upstream producer failed with exception") { Source.Failed(new TestException("failing")).RunWith(sink, Materializer); Source.From(Enumerable.Range(1, 10)).RunWith(sink, Materializer); - var result = await task.ShouldCompleteWithin(3.Seconds()); + var result = await task.WaitAsync(3.Seconds()); result.Should().BeEquivalentTo(Enumerable.Range(1, 10)); }); }); @@ -300,7 +300,7 @@ await EventFilter { Source.Failed(ActorPublisher.NormalShutdownReason).RunWith(sink, Materializer); Source.From(Enumerable.Range(1, 10)).RunWith(sink, Materializer); - var result = await task.ShouldCompleteWithin(3.Seconds()); + var result = await task.WaitAsync(3.Seconds()); result.Should().BeEquivalentTo(Enumerable.Range(1, 10)); }); }); @@ -313,7 +313,7 @@ public async Task BroadcastHub_must_work_in_the_happy_case() await this.AssertAllStagesStoppedAsync(async () => { var source = Source.From(Enumerable.Range(1, 10)).RunWith(BroadcastHub.Sink(8), Materializer); - var result = await source.RunWith(Sink.Seq(), Materializer).ShouldCompleteWithin(3.Seconds()); + var result = await source.RunWith(Sink.Seq(), Materializer).WaitAsync(3.Seconds()); result.Should().BeEquivalentTo(Enumerable.Range(1, 10)); }, Materializer); } @@ -336,8 +336,8 @@ await this.AssertAllStagesStoppedAsync(async () => // No Task.Delay needed - hub waits for 2 consumers before pulling upstream firstElement.SetResult(1); - (await f1.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 10)); - (await f2.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 10)); + (await f1.WaitAsync(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 10)); + (await f2.WaitAsync(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 10)); }, Materializer); } @@ -359,8 +359,8 @@ await this.AssertAllStagesStoppedAsync(async () => // No Task.Delay needed - hub waits for 2 consumers before pulling upstream firstElement.SetResult(1); - (await f1.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 20)); - (await f2.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 10)); + (await f1.WaitAsync(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 20)); + (await f2.WaitAsync(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 10)); }, Materializer); } @@ -370,9 +370,9 @@ public async Task BroadcastHub_must_ensure_that_subsequent_consumers_see_subsequ await this.AssertAllStagesStoppedAsync(async () => { var source = Source.From(Enumerable.Range(1, 20)).RunWith(BroadcastHub.Sink(8), Materializer); - (await source.Take(10).RunWith(Sink.Seq(), Materializer).ShouldCompleteWithin(3.Seconds())) + (await source.Take(10).RunWith(Sink.Seq(), Materializer).WaitAsync(3.Seconds())) .Should().BeEquivalentTo(Enumerable.Range(1, 10)); - (await source.Take(10).RunWith(Sink.Seq(), Materializer).ShouldCompleteWithin(3.Seconds())) + (await source.Take(10).RunWith(Sink.Seq(), Materializer).WaitAsync(3.Seconds())) .Should().BeEquivalentTo(Enumerable.Range(11, 10)); }, Materializer); } @@ -396,8 +396,8 @@ await this.AssertAllStagesStoppedAsync(async () => // No Task.Delay needed - hub waits for 2 consumers before pulling upstream firstElement.SetResult(1); - (await f1.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 10)); - (await f2.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 10)); + (await f1.WaitAsync(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 10)); + (await f2.WaitAsync(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 10)); }, Materializer); } @@ -420,8 +420,8 @@ await this.AssertAllStagesStoppedAsync(async () => // No Task.Delay needed - hub waits for 2 consumers before pulling upstream firstElement.SetResult(1); - (await f1.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 10)); - (await f2.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 10)); + (await f1.WaitAsync(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 10)); + (await f2.WaitAsync(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 10)); }, Materializer); } @@ -448,8 +448,8 @@ await this.AssertAllStagesStoppedAsync(async () => // No Task.Delay needed - hub waits for 2 consumers before pulling upstream firstElement.SetResult(1); - (await f1.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 20)); - (await f2.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 20)); + (await f1.WaitAsync(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 20)); + (await f2.WaitAsync(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 20)); }, Materializer); } @@ -471,8 +471,8 @@ await this.AssertAllStagesStoppedAsync(async () => // No Task.Delay needed - hub waits for 2 consumers before pulling upstream firstElement.SetResult(1); - (await f1.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 10)); - (await f2.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 10)); + (await f1.WaitAsync(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 10)); + (await f2.WaitAsync(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 10)); }, Materializer); } @@ -508,7 +508,7 @@ await downstream.AsyncBuilder() await downstream.CancelAsync(); killSwitch.Shutdown(); - await ignoredTask.ShouldCompleteWithin(3.Seconds()); + await ignoredTask.WaitAsync(3.Seconds()); }, Materializer); } @@ -585,7 +585,7 @@ await this.AssertAllStagesStoppedAsync(async () => // cases should work in the end await Task.Delay(50); - (await source.RunWith(Sink.Seq(), Materializer).ShouldCompleteWithin(3.Seconds())) + (await source.RunWith(Sink.Seq(), Materializer).WaitAsync(3.Seconds())) .Should().BeEmpty(); }, Materializer); } @@ -604,7 +604,7 @@ await this.AssertAllStagesStoppedAsync(async () => await Awaiting(async () => { await source.RunWith(Sink.Seq(), Materializer); - }).Should().ThrowAsync().ShouldCompleteWithin(3.Seconds()); + }).Should().ThrowAsync().WaitAsync(3.Seconds()); }, Materializer); } @@ -648,7 +648,7 @@ await this.AssertAllStagesStoppedAsync(async () => var items = Enumerable.Range(1, 10).ToList(); var source = Source.From(items) .RunWith(PartitionHub.Sink((_, _) => 0, 0, 8), Materializer); - var result = await source.RunWith(Sink.Seq(), Materializer).ShouldCompleteWithin(3.Seconds()); + var result = await source.RunWith(Sink.Seq(), Materializer).WaitAsync(3.Seconds()); result.Should().BeEquivalentTo(items); }, Materializer); } @@ -666,8 +666,8 @@ await this.AssertAllStagesStoppedAsync(async () => await Task.Delay(50); var result2 = source.RunWith(Sink.Seq(), Materializer); - (await result1.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo(new[] { 0, 2, 4, 6, 8 }); - (await result2.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo(new[] { 1, 3, 5, 7, 9 }); + (await result1.WaitAsync(3.Seconds())).Should().BeEquivalentTo(new[] { 0, 2, 4, 6, 8 }); + (await result2.WaitAsync(3.Seconds())).Should().BeEquivalentTo(new[] { 1, 3, 5, 7, 9 }); }, Materializer); } @@ -690,8 +690,8 @@ await this.AssertAllStagesStoppedAsync(async () => var result1 = source.RunWith(Sink.Seq(), Materializer); var result2 = source.RunWith(Sink.Seq(), Materializer); - (await result1.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo(new[] { 1, 3, 5, 7, 9 }); - (await result2.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo(new[] { 0, 2, 4, 6, 8 }); + (await result1.WaitAsync(3.Seconds())).Should().BeEquivalentTo(new[] { 1, 3, 5, 7, 9 }); + (await result2.WaitAsync(3.Seconds())).Should().BeEquivalentTo(new[] { 0, 2, 4, 6, 8 }); }, Materializer); } @@ -719,8 +719,8 @@ await this.AssertAllStagesStoppedAsync(async () => var result1 = source.RunWith(Sink.Seq(), Materializer); var result2 = source.RunWith(Sink.Seq(), Materializer); - (await result1.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo("usr-2"); - (await result2.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo("usr-1", "usr-1", "usr-3"); + (await result1.WaitAsync(3.Seconds())).Should().BeEquivalentTo("usr-2"); + (await result2.WaitAsync(3.Seconds())).Should().BeEquivalentTo("usr-1", "usr-1", "usr-3"); }, Materializer); } @@ -738,8 +738,8 @@ await this.AssertAllStagesStoppedAsync(async () => var result2 = source.Throttle(10, TimeSpan.FromMilliseconds(100), 10, ThrottleMode.Shaping) .RunWith(Sink.Seq(), Materializer); - var count1 = (await result1.ShouldCompleteWithin(3.Seconds())).Count; - var count2 = (await result2.ShouldCompleteWithin(3.Seconds())).Count; + var count1 = (await result1.WaitAsync(3.Seconds())).Count; + var count2 = (await result2.WaitAsync(3.Seconds())).Count; count1.ShouldBeGreaterThan(count2); }, Materializer); } @@ -887,8 +887,8 @@ await this.AssertAllStagesStoppedAsync(async () => var expectationF1 = Enumerable.Range(1, 18).Where(v => v % 2 == 0).ToList(); expectationF1.Insert(0, 50); - (await f1.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo(expectationF1); - (await f2.ShouldCompleteWithin(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 19).Where(v => v % 2 != 0)); + (await f1.WaitAsync(3.Seconds())).Should().BeEquivalentTo(expectationF1); + (await f2.WaitAsync(3.Seconds())).Should().BeEquivalentTo(Enumerable.Range(1, 19).Where(v => v % 2 != 0)); }, Materializer); } @@ -938,7 +938,7 @@ await this.AssertAllStagesStoppedAsync(async () => // cases should work in the end await Task.Delay(50); - (await source.RunWith(Sink.Seq(), Materializer).ShouldCompleteWithin(3.Seconds())) + (await source.RunWith(Sink.Seq(), Materializer).WaitAsync(3.Seconds())) .Should().BeEmpty(); }, Materializer); } @@ -984,7 +984,7 @@ await this.AssertAllStagesStoppedAsync(async () => await Awaiting(async () => { await source.RunWith(Sink.Seq(), Materializer); - }).Should().ThrowAsync().WithMessage("Fail!").ShouldCompleteWithin(3.Seconds()); + }).Should().ThrowAsync().WithMessage("Fail!").WaitAsync(3.Seconds()); }, Materializer); } } diff --git a/src/core/Akka.Streams.Tests/Dsl/JsonFramingSpec.cs b/src/core/Akka.Streams.Tests/Dsl/JsonFramingSpec.cs index 1fd42031028..0b256d23549 100644 --- a/src/core/Akka.Streams.Tests/Dsl/JsonFramingSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/JsonFramingSpec.cs @@ -53,7 +53,7 @@ public async Task Collecting_multiple_json_should_parse_json_array() return list; }, Materializer); - var complete = await result.ShouldCompleteWithin(3.Seconds()); + var complete = await result.WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(new [] { @"{ ""name"" : ""john"" }", @@ -79,7 +79,7 @@ public async Task Collecting_multiple_json_should_emit_single_json_element_from_ return list; }, Materializer); - var complete = await result.ShouldCompleteWithin(3.Seconds()); + var complete = await result.WaitAsync(3.Seconds()); complete.Should().HaveCount(1).And.Subject.Should().Contain(@"{ ""name"" : ""john"" }"); } @@ -100,7 +100,7 @@ public async Task Collecting_multiple_json_should_parse_line_delimited() return list; }, Materializer); - var complete = await result.ShouldCompleteWithin(3.Seconds()); + var complete = await result.WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(new[] { @"{ ""name"" : ""john"" }", @@ -123,7 +123,7 @@ public async Task Collecting_multiple_json_should_parse_comma_delimited() return list; }, Materializer); - var complete = await result.ShouldCompleteWithin(3.Seconds()); + var complete = await result.WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(new[] { @"{ ""name"" : ""john"" }", @@ -149,7 +149,7 @@ public async Task Collecting_multiple_json_should_parse_chunks_successfully() list.Add(s.ToString()); return list; }, Materializer) - .ShouldCompleteWithin(3.Seconds()); ; + .WaitAsync(3.Seconds()); ; result.Should().BeEquivalentTo(new[] diff --git a/src/core/Akka.Streams.Tests/Dsl/KeepAliveConcatSpec.cs b/src/core/Akka.Streams.Tests/Dsl/KeepAliveConcatSpec.cs index 1e5c50b7ddd..452386dc620 100644 --- a/src/core/Akka.Streams.Tests/Dsl/KeepAliveConcatSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/KeepAliveConcatSpec.cs @@ -39,7 +39,7 @@ public async Task KeepAliveConcat_should_not_emit_additional_elements_if_upstrea .Grouped(1000) .RunWith(Sink.First>>(), Sys.Materializer()); - var complete = await t.ShouldCompleteWithin(3.Seconds()); + var complete = await t.WaitAsync(3.Seconds()); complete .SelectMany(x => x) .Should().BeEquivalentTo(Enumerable.Range(1, 10), o => o.WithStrictOrdering()); @@ -59,7 +59,7 @@ public async Task KeepAliveConcat_should_emit_elements_periodically_after_silent .Grouped(1000) .RunWith(Sink.First>>(), Sys.Materializer()); - var complete = await t.ShouldCompleteWithin(TimeSpan.FromSeconds(6)); + var complete = await t.WaitAsync(TimeSpan.FromSeconds(6)); complete .SelectMany(x => x) .Should().BeEquivalentTo(Enumerable.Range(1, 10), o => o.WithStrictOrdering()); diff --git a/src/core/Akka.Streams.Tests/Dsl/LastElementSpec.cs b/src/core/Akka.Streams.Tests/Dsl/LastElementSpec.cs index 8026a9be1b8..893b751b2fd 100644 --- a/src/core/Akka.Streams.Tests/Dsl/LastElementSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/LastElementSpec.cs @@ -36,7 +36,7 @@ public async Task A_stream_via_LastElement_should_materialize_to_the_last_elemen .ExpectNext( 1, 2, 3) .ExpectComplete(); - var complete = await lastElement.ShouldCompleteWithin(TimeSpan.FromSeconds(1)); + var complete = await lastElement.WaitAsync(TimeSpan.FromSeconds(1)); complete.Should().Be(Option.Create(3)); } @@ -54,7 +54,7 @@ public async Task A_stream_via_LastElement_should_materialize_to_materialize_to_ probe.Request(3) .ExpectComplete(); - var complete = await lastElement.ShouldCompleteWithin(1.Seconds()); + var complete = await lastElement.WaitAsync(1.Seconds()); complete.Should().Be(Option.None); } diff --git a/src/core/Akka.Streams.Tests/Dsl/LastSinkSpec.cs b/src/core/Akka.Streams.Tests/Dsl/LastSinkSpec.cs index ab74407e92d..7b1c4902b2b 100644 --- a/src/core/Akka.Streams.Tests/Dsl/LastSinkSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/LastSinkSpec.cs @@ -35,7 +35,7 @@ await this.AssertAllStagesStoppedAsync(async () => { var result = await Source.From(Enumerable.Range(1,42)).Select(x=>x) .RunWith(Sink.Last(), Materializer) - .ShouldCompleteWithin(3.Seconds()); + .WaitAsync(3.Seconds()); result.Should().Be(42); }, Materializer); } @@ -45,8 +45,9 @@ public async Task A_Flow_with_Sink_Last_must_yield_the_first_error() { await this.AssertAllStagesStoppedAsync(async () => { - (await Source.Failed(new Exception("ex")).RunWith(Sink.Last(), Materializer) - .ShouldThrowWithin(1.Seconds())).Message.Should().Be("ex"); + var task = Source.Failed(new Exception("ex")).RunWith(Sink.Last(), Materializer); + var ex = await AssertThrowsAsync(() => task).WaitAsync(1.Seconds()); + ex.Message.Should().Be("ex"); }, Materializer); } @@ -55,9 +56,9 @@ public async Task A_Flow_with_Sink_Last_must_yield_NoSuchElementException_for_em { await this.AssertAllStagesStoppedAsync(async () => { - (await Source.Empty().RunWith(Sink.Last(), Materializer) - .ShouldThrowWithin(1.Seconds())) - .Message.Should().Be("Last of empty stream"); + var task = Source.Empty().RunWith(Sink.Last(), Materializer); + var ex = await AssertThrowsAsync(() => task).WaitAsync(1.Seconds()); + ex.Message.Should().Be("Last of empty stream"); }, Materializer); } @@ -68,7 +69,7 @@ await this.AssertAllStagesStoppedAsync(async () => { var result = await Source.From(Enumerable.Range(1, 42)).Select(x => x) .RunWith(Sink.LastOrDefault(), Materializer) - .ShouldCompleteWithin(1.Seconds()); + .WaitAsync(1.Seconds()); result.Should().Be(42); }, Materializer); } @@ -78,8 +79,9 @@ public async Task A_Flow_with_Sink_LastOption_must_yield_the_first_error() { await this.AssertAllStagesStoppedAsync(async () => { - (await Source.Failed(new Exception("ex")).RunWith(Sink.LastOrDefault(), Materializer) - .ShouldThrowWithin(1.Seconds())).Message.Should().Be("ex"); + var task = Source.Failed(new Exception("ex")).RunWith(Sink.LastOrDefault(), Materializer); + var ex = await AssertThrowsAsync(() => task).WaitAsync(1.Seconds()); + ex.Message.Should().Be("ex"); }, Materializer); } @@ -90,7 +92,7 @@ await this.AssertAllStagesStoppedAsync(async () => { var result = await Source.Empty() .RunWith(Sink.LastOrDefault(), Materializer) - .ShouldCompleteWithin(1.Seconds()); + .WaitAsync(1.Seconds()); result.Should().Be(0); }, Materializer); } diff --git a/src/core/Akka.Streams.Tests/Dsl/LazySinkSpec.cs b/src/core/Akka.Streams.Tests/Dsl/LazySinkSpec.cs index 77b66b84aef..7ac5332041c 100644 --- a/src/core/Akka.Streams.Tests/Dsl/LazySinkSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/LazySinkSpec.cs @@ -49,7 +49,7 @@ await this.AssertAllStagesStoppedAsync(async() => { var lazySink = Sink.LazyInitAsync(() => Task.FromResult(this.SinkProbe())); var taskProbe = Source.From(Enumerable.Range(0, 11)).RunWith(lazySink, Materializer); - var probe = await taskProbe.ShouldCompleteWithin(RemainingOrDefault); + var probe = await taskProbe.WaitAsync(RemainingOrDefault); probe.Value.Request(100); foreach (var i in Enumerable.Range(0, 11)) { @@ -76,7 +76,7 @@ await this.AssertAllStagesStoppedAsync(async() => taskProbe.Wait(TimeSpan.FromMilliseconds(200)).ShouldBeFalse(); p.SetResult(this.SinkProbe()); - var complete = await taskProbe.ShouldCompleteWithin(RemainingOrDefault); + var complete = await taskProbe.WaitAsync(RemainingOrDefault); var probe = complete.Value; probe.Request(100); await probe.ExpectNextAsync(0); @@ -97,7 +97,7 @@ await this.AssertAllStagesStoppedAsync(async() => { var lazySink = Sink.LazyInitAsync(() => Task.FromResult(Sink.Aggregate(0, (int i, int i2) => i + i2))); var taskProbe = Source.Empty().RunWith(lazySink, Materializer); - var complete = await taskProbe.ShouldCompleteWithin(RemainingOrDefault); + var complete = await taskProbe.WaitAsync(RemainingOrDefault); complete.ShouldBe(Option>.None); }, Materializer); } @@ -109,7 +109,7 @@ await this.AssertAllStagesStoppedAsync(async() => { var lazySink = Sink.LazyInitAsync(() => Task.FromResult(this.SinkProbe())); var taskProbe = Source.Single(1).RunWith(lazySink, Materializer); - var taskResult = await taskProbe.ShouldCompleteWithin(RemainingOrDefault); + var taskResult = await taskProbe.WaitAsync(RemainingOrDefault); await taskResult.Value.Request(1).ExpectNext(1).ExpectCompleteAsync(); }, Materializer); } @@ -140,7 +140,7 @@ await this.AssertAllStagesStoppedAsync(async() => var sourceSub = await sourceProbe.ExpectSubscriptionAsync(); await sourceSub.ExpectRequestAsync(1); sourceSub.SendNext(0); - var complete = await taskProbe.ShouldCompleteWithin(RemainingOrDefault); + var complete = await taskProbe.WaitAsync(RemainingOrDefault); var probe = complete.Value; await probe.Request(1).ExpectNextAsync(0); sourceSub.SendError(Ex); @@ -181,7 +181,7 @@ await this.AssertAllStagesStoppedAsync(async() => await sourceSub.ExpectRequestAsync(1); sourceSub.SendNext(0); await sourceSub.ExpectRequestAsync(1); - var complete = await taskProbe.ShouldCompleteWithin(RemainingOrDefault); + var complete = await taskProbe.WaitAsync(RemainingOrDefault); var probe = complete.Value; await probe.Request(1).ExpectNextAsync(0); probe.Cancel(); diff --git a/src/core/Akka.Streams.Tests/Dsl/LazySourceSpec.cs b/src/core/Akka.Streams.Tests/Dsl/LazySourceSpec.cs index d6d12dd90a2..c8531e5fdfb 100644 --- a/src/core/Akka.Streams.Tests/Dsl/LazySourceSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/LazySourceSpec.cs @@ -39,7 +39,7 @@ public async Task A_lazy_source_must_work_like_a_normal_source_happy_path() await this.AssertAllStagesStoppedAsync(async() => { var result = Source.Lazily(() => Source.From(new[] { 1, 2, 3 })).RunWith(Sink.Seq(), Materializer); - var complete = await result.ShouldCompleteWithin(3.Seconds()); + var complete = await result.WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(ImmutableList.Create(1, 2, 3)); }, Materializer); } @@ -72,7 +72,7 @@ await Awaiting(async () => await Source.Lazily(() => Source.From(new[] { 1, 2, 3 })) .ToMaterialized(Sink.Cancelled(), Keep.Left) .Run(Materializer); - }).Should().ThrowAsync().ShouldCompleteWithin(3.Seconds()); + }).Should().ThrowAsync().WaitAsync(3.Seconds()); }, Materializer); } @@ -180,7 +180,7 @@ await this.AssertAllStagesStoppedAsync(async() => .AddAttributes(Attributes.CreateName("outer")) .RunWith(Sink.First(), Materializer); - var complete = await first.ShouldCompleteWithin(3.Seconds()); + var complete = await first.WaitAsync(3.Seconds()); var attributes = complete.AttributeList.ToList(); var inner = new Attributes.Name("inner"); var outer = new Attributes.Name("outer"); diff --git a/src/core/Akka.Streams.Tests/Dsl/PagedSourceSpec.cs b/src/core/Akka.Streams.Tests/Dsl/PagedSourceSpec.cs index cc4f93bc261..2855eaa6914 100644 --- a/src/core/Akka.Streams.Tests/Dsl/PagedSourceSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/PagedSourceSpec.cs @@ -49,7 +49,7 @@ public async Task PagedSource_should_return_the_items_in_the_proper_order() var source = PagedSource.Create(0, new MultiplesOfTwoPage().Page); var t = source.Take(3).RunWith(Sink.Seq(), Sys.Materializer()); - var complete = await t.ShouldCompleteWithin(3.Seconds()); + var complete = await t.WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(new[] { 0, 2, 4 }, o => o.WithStrictOrdering()); } @@ -59,7 +59,7 @@ public async Task PagedSource_should_return_not_more_items_then_available() var source = PagedSource.Create(0, new MultiplesOfTwoPage(4).Page); var t = source.Take(10).RunWith(Sink.Seq(), Sys.Materializer()); - var complete = await t.ShouldCompleteWithin(3.Seconds()); + var complete = await t.WaitAsync(3.Seconds()); complete.Should().HaveCount(4); } } @@ -88,7 +88,7 @@ public async Task PagedSource_should_return_the_items_in_the_proper_order() { var t = _source.Take(4).RunWith(Sink.Seq(), Sys.Materializer()); - var complete = await t.ShouldCompleteWithin(3.Seconds()); + var complete = await t.WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(new[] { "a", "b", "c", "d" }, o => o.WithStrictOrdering()); } @@ -97,7 +97,7 @@ public async Task PagedSource_should_close_stream_when_received_empty_page() { var t = _source.RunWith(Sink.Seq(), Sys.Materializer()); - var complete = await t.ShouldCompleteWithin(3.Seconds()); + var complete = await t.WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(new[] { "a", "b", "c", "d", "e" }, o => o.WithStrictOrdering()); } } @@ -133,7 +133,7 @@ public async Task PagedSource_should_return_the_items_in_the_proper_order() { var t = _source.Take(4).RunWith(Sink.Seq(), Sys.Materializer()); - var complete = await t.ShouldCompleteWithin(3.Seconds()); + var complete = await t.WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(new[] { 1, 2, 3, 4 }, o => o.WithStrictOrdering()); } @@ -142,7 +142,7 @@ public async Task PagedSource_should_close_stream_when_received_empty_link() { var t = _source.RunWith(Sink.Seq(), Sys.Materializer()); - var complete = await t.ShouldCompleteWithin(3.Seconds()); + var complete = await t.WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(new[] { 1, 2, 3, 4, 5 }, o => o.WithStrictOrdering()); } } diff --git a/src/core/Akka.Streams.Tests/Dsl/PulseSpec.cs b/src/core/Akka.Streams.Tests/Dsl/PulseSpec.cs index 8766c676698..371ca5a1003 100644 --- a/src/core/Akka.Streams.Tests/Dsl/PulseSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/PulseSpec.cs @@ -38,7 +38,7 @@ public async Task Pulse_should_signal_demand_once_every_interval() probe.ExpectNoMsg(_pulseInterval); probe.SendComplete(); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(new[] { 1, 2 }, o => o.WithStrictOrdering()); } @@ -67,7 +67,7 @@ public async Task Initially_opened_Pulse_should_emit_the_first_available_element .InitialTimeout(Dilated(TimeSpan.FromMilliseconds(2))) .RunWith(Sink.First(), Sys.Materializer()); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().Be(1); } @@ -88,7 +88,7 @@ public async Task Initially_opened_Pulse_should_signal_demand_once_every_interva probe.ExpectNoMsg(_pulseInterval); probe.SendComplete(); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(new[] { 1, 2 }, o => o.WithStrictOrdering()); } } diff --git a/src/core/Akka.Streams.Tests/Dsl/RestartSpec.cs b/src/core/Akka.Streams.Tests/Dsl/RestartSpec.cs index f6b04d2ca24..f25ca852a7c 100644 --- a/src/core/Akka.Streams.Tests/Dsl/RestartSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/RestartSpec.cs @@ -431,7 +431,7 @@ await probe.AsyncBuilder() .SendComplete() .ExecuteAsync(); - await tcs.Task.ShouldCompleteWithin(3.Seconds()); + await tcs.Task.WaitAsync(3.Seconds()); tcs.Task.Result.Should().ContainInOrder("a", "b", "c"); created.Current.Should().Be(1); }, Materializer); diff --git a/src/core/Akka.Streams.Tests/Dsl/SampleSpec.cs b/src/core/Akka.Streams.Tests/Dsl/SampleSpec.cs index 66d64713121..92e0fa1e5c1 100644 --- a/src/core/Akka.Streams.Tests/Dsl/SampleSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/SampleSpec.cs @@ -32,7 +32,7 @@ public async Task Sample_Stage_should_return_every_Nth_element_in_stream() var expected = list.Where(x => x % n == 0); - var complete = await future.ShouldCompleteWithin(3.Seconds()); + var complete = await future.WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(expected, o => o.WithStrictOrdering()); } } @@ -47,7 +47,7 @@ public async Task Sample_Stage_should_return_elements_using_next_function() .Via(new Sample(next)) .RunWith(Sink.Seq(), Sys.Materializer()); - var complete = await future.ShouldCompleteWithin(3.Seconds()); + var complete = await future.WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(new[] { 1, 3, 6, 10 }, o => o.WithStrictOrdering()); } diff --git a/src/core/Akka.Streams.Tests/Dsl/SinkForeachAsyncSpec.cs b/src/core/Akka.Streams.Tests/Dsl/SinkForeachAsyncSpec.cs index 63c3de0e0d2..ef80d550613 100644 --- a/src/core/Akka.Streams.Tests/Dsl/SinkForeachAsyncSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/SinkForeachAsyncSpec.cs @@ -36,7 +36,7 @@ public SinkForeachAsyncSpec(ITestOutputHelper helper) : base(helper) public async Task A_ForeachAsync_must_handle_empty_source() { var p = Source.From(new List()).RunWith(Sink.ForEachAsync(3, _ => Task.CompletedTask), Materializer); - (await p.ShouldCompleteWithin(RemainingOrDefault)).Should().Be(Done.Instance); + (await p.WaitAsync(RemainingOrDefault)).Should().Be(Done.Instance); } [Fact] @@ -65,7 +65,7 @@ public async Task A_ForeachAsync_must_be_able_to_run_elements_in_parallel() latch[4].CountDown(); probe.ExpectMsg(4); - (await p.ShouldCompleteWithin(TimeSpan.FromSeconds(4))).Should().Be(Done.Instance); + (await p.WaitAsync(TimeSpan.FromSeconds(4))).Should().Be(Done.Instance); } [Fact] @@ -141,7 +141,7 @@ int Four() latch[4].CountDown(); probe.ExpectMsg(4); - (await p.ShouldCompleteWithin(TimeSpan.FromSeconds(4))).Should().Be(Done.Instance); + (await p.WaitAsync(TimeSpan.FromSeconds(4))).Should().Be(Done.Instance); oneCalled.ShouldBeTrue(); twoCalled.ShouldBeTrue(); @@ -158,7 +158,7 @@ public async Task A_ForeachAsync_must_produce_elements_in_the_order_they_are_rea .ToDictionary(t => t.i, t => t.Item2); var p = Source.From(Enumerable.Range(1, 4)).RunWith(Sink.ForEachAsync(4, async n => { - await latch[n].WaitAsync().ShouldCompleteWithin(TimeSpan.FromSeconds(5)); + await latch[n].WaitAsync().WaitAsync(TimeSpan.FromSeconds(5)); probe.Ref.Tell(n); }), Materializer); @@ -174,7 +174,7 @@ public async Task A_ForeachAsync_must_produce_elements_in_the_order_they_are_rea latch[1].Signal(); probe.ExpectMsg(1); - (await p.ShouldCompleteWithin(TimeSpan.FromSeconds(4))).Should().Be(Done.Instance); + (await p.WaitAsync(TimeSpan.FromSeconds(4))).Should().Be(Done.Instance); } [Fact] @@ -187,7 +187,7 @@ public async Task A_ForeachAsync_must_not_run_more_functions_in_parallel_then_sp var p = Source.From(Enumerable.Range(1, 5)).RunWith(Sink.ForEachAsync(4, async n => { probe.Ref.Tell(n); - await latch[n].WaitAsync().ShouldCompleteWithin(TimeSpan.FromSeconds(5)); + await latch[n].WaitAsync().WaitAsync(TimeSpan.FromSeconds(5)); }), Materializer); probe.ExpectMsgAllOf(new[] { 1, 2, 3, 4 }); @@ -200,7 +200,7 @@ public async Task A_ForeachAsync_must_not_run_more_functions_in_parallel_then_sp latch[5].Signal(); probe.ExpectMsg(5); - (await p.ShouldCompleteWithin(TimeSpan.FromSeconds(5))).Should().Be(Done.Instance); + (await p.WaitAsync(TimeSpan.FromSeconds(5))).Should().Be(Done.Instance); } [Fact] @@ -215,13 +215,13 @@ public async Task A_ForeachAsync_must_resume_after_function_failure() throw new TestException("err1"); probe.Ref.Tell(n); - await latch.WaitAsync().ShouldCompleteWithin(TimeSpan.FromSeconds(10)); + await latch.WaitAsync().WaitAsync(TimeSpan.FromSeconds(10)); }).WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.ResumingDecider)), Materializer); latch.Signal(); probe.ExpectMsgAllOf(new[] { 1, 2, 4, 5 }); - (await p.ShouldCompleteWithin(TimeSpan.FromSeconds(5))).Should().Be(Done.Instance); + (await p.WaitAsync(TimeSpan.FromSeconds(5))).Should().Be(Done.Instance); } [Fact] @@ -236,13 +236,13 @@ public void A_ForeachAsync_must_finish_after_function_failure() if (n == 3) { // Error will happen only after elements 1, 2 has been processed - await errorLatch.WaitAsync().ShouldCompleteWithin(TimeSpan.FromSeconds(5)); + await errorLatch.WaitAsync().WaitAsync(TimeSpan.FromSeconds(5)); throw new TestException("err2"); } probe.Ref.Tell(n); errorLatch.Signal(); - await element4Latch.WaitAsync().ShouldCompleteWithin(TimeSpan.FromSeconds(5)); // Block element 4, 5, 6, ... from entering + await element4Latch.WaitAsync().WaitAsync(TimeSpan.FromSeconds(5)); // Block element 4, 5, 6, ... from entering }).WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.StoppingDecider)), Materializer); // Only the first two messages are guaranteed to arrive due to their enforced ordering related to the time diff --git a/src/core/Akka.Streams.Tests/Dsl/SourceSpec.cs b/src/core/Akka.Streams.Tests/Dsl/SourceSpec.cs index d9e9b42a622..b2dfde02fad 100644 --- a/src/core/Akka.Streams.Tests/Dsl/SourceSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/SourceSpec.cs @@ -110,7 +110,7 @@ await this.AssertAllStagesStoppedAsync(async() => c.ExpectNoMsg(TimeSpan.FromMilliseconds(300)); subs.Cancel(); - var complete = await f.Task.ShouldCompleteWithin(3.Seconds()); + var complete = await f.Task.WaitAsync(3.Seconds()); complete.Should().Be(null); }, Materializer); } @@ -130,7 +130,7 @@ await this.AssertAllStagesStoppedAsync(async() => //external cancellation neverPromise.TrySetResult(0).Should().BeTrue(); - var counter = await counterFuture.ShouldCompleteWithin(3.Seconds()); + var counter = await counterFuture.WaitAsync(3.Seconds()); counter.Should().Be(0); }, Materializer); } @@ -149,7 +149,7 @@ await this.AssertAllStagesStoppedAsync(async() => //external cancellation neverPromise.TrySetResult(6).Should().BeTrue(); - var complete = await counterFuture.ShouldCompleteWithin(3.Seconds()); + var complete = await counterFuture.WaitAsync(3.Seconds()); complete.Should().Be(6); }, Materializer); } @@ -415,7 +415,7 @@ public async Task Cycle_Source_must_continuously_generate_the_same_sequence() var complete = await Source.Cycle(() => new[] {1, 2, 3}.AsEnumerable().GetEnumerator()) .Grouped(9) .RunWith(Sink.First>(), Materializer) - .ShouldCompleteWithin(3.Seconds()); + .WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(expected); } @@ -462,7 +462,7 @@ public async Task A_ZipN_Source_must_properly_ZipN() var complete = await Source.ZipN(sources) .RunWith(Sink.Seq>(), Materializer) - .ShouldCompleteWithin(3.Seconds()); + .WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(new[] { @@ -484,7 +484,7 @@ public async Task A_ZipWithN_Source_must_properly_ZipWithN() var complete = await Source.ZipWithN(list => list.Sum(), sources) .RunWith(Sink.Seq(), Materializer) - .ShouldCompleteWithin(3.Seconds()); + .WaitAsync(3.Seconds()); complete.Should().BeEquivalentTo(new[] {111, 222, 333}); } diff --git a/src/core/Akka.Streams.Tests/Dsl/UnfoldResourceAsyncSourceSpec.cs b/src/core/Akka.Streams.Tests/Dsl/UnfoldResourceAsyncSourceSpec.cs index 2d344e29538..613de1c1c39 100644 --- a/src/core/Akka.Streams.Tests/Dsl/UnfoldResourceAsyncSourceSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/UnfoldResourceAsyncSourceSpec.cs @@ -102,18 +102,18 @@ await this.AssertAllStagesStoppedAsync(async () => .RunWith(Sink.FromSubscriber(probe), Materializer); await probe.RequestAsync(1); - await resource.Created.ShouldCompleteWithin(3.Seconds()); + await resource.Created.WaitAsync(3.Seconds()); await probe.ExpectNoMsgAsync(TimeSpan.FromMilliseconds(200)); createPromise.SetResult(Done.Instance); foreach (var i in values) { - await resource.FirstElementRead.ShouldCompleteWithin(3.Seconds()); + await resource.FirstElementRead.WaitAsync(3.Seconds()); (await probe.ExpectNextAsync()).ShouldBe(i); await probe.RequestAsync(1); } - await resource.Closed.ShouldCompleteWithin(3.Seconds()); + await resource.Closed.WaitAsync(3.Seconds()); closePromise.SetResult(Done.Instance); await probe.ExpectCompleteAsync(); @@ -136,13 +136,13 @@ await this.AssertAllStagesStoppedAsync(async () => .RunWith(Sink.FromSubscriber(probe), Materializer); await probe.RequestAsync(1L); - await resource.FirstElementRead.ShouldCompleteWithin(3.Seconds()); + await resource.FirstElementRead.WaitAsync(3.Seconds()); // we cancel before we complete first read (racy) await probe.CancelAsync(); await Task.Delay(100); firtRead.SetResult(Done.Instance); - await resource.Closed.ShouldCompleteWithin(3.Seconds()); + await resource.Closed.WaitAsync(3.Seconds()); }, Materializer); } @@ -253,7 +253,7 @@ await this.AssertAllStagesStoppedAsync(async () => .WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.ResumingDecider)) .RunWith(Sink.Seq(), Materializer); - var r = await result.ShouldCompleteWithin(3.Seconds()); + var r = await result.WaitAsync(3.Seconds()); r.ShouldBe(new[] { 1, 2, 3 }); }, Materializer); } @@ -287,7 +287,7 @@ await this.AssertAllStagesStoppedAsync(async () => .WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.ResumingDecider)) .RunWith(Sink.Seq(), Materializer); - var r = await result.ShouldCompleteWithin(3.Seconds()); + var r = await result.WaitAsync(3.Seconds()); r.ShouldBe(new[] { 1, 2, 3 }); }, Materializer); } @@ -322,7 +322,7 @@ await this.AssertAllStagesStoppedAsync(async () => .WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.RestartingDecider)) .RunWith(Sink.Seq(), Materializer); - var r = await result.ShouldCompleteWithin(3.Seconds()); + var r = await result.WaitAsync(3.Seconds()); r.ShouldBe(new[] { 1, 2, 3 }); startCount.Current.ShouldBe(2); }, Materializer); @@ -358,7 +358,7 @@ await this.AssertAllStagesStoppedAsync(async () => .WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.RestartingDecider)) .RunWith(Sink.Seq(), Materializer); - var r = await result.ShouldCompleteWithin(3.Seconds()); + var r = await result.WaitAsync(3.Seconds()); r.ShouldBe(new[] { 1, 2, 3 }); startCount.Current.ShouldBe(2); }, Materializer); @@ -505,7 +505,7 @@ public async Task A_UnfoldResourceAsyncSource_must_close_resource_when_stream_is materializer.Shutdown(); materializer.IsShutdown.Should().BeTrue(); - var r = await closePromise.Task.ShouldCompleteWithin(3.Seconds()); + var r = await closePromise.Task.WaitAsync(3.Seconds()); r.Should().Be("Closed"); } @@ -527,7 +527,7 @@ await this.AssertAllStagesStoppedAsync(async () => await probe.CancelAsync(); - var r = await closePromise.Task.ShouldCompleteWithin(3.Seconds()); + var r = await closePromise.Task.WaitAsync(3.Seconds()); r.Should().Be("Closed"); }, Materializer); } @@ -553,7 +553,7 @@ await this.AssertAllStagesStoppedAsync(async () => }) .RunWith(Sink.Cancelled(), Materializer); - var r = await closePromise.Task.ShouldCompleteWithin(3.Seconds()); + var r = await closePromise.Task.WaitAsync(3.Seconds()); r.Should().Be("Closed"); }, Materializer); } @@ -580,7 +580,7 @@ await this.AssertAllStagesStoppedAsync(async () => await probe.RequestAsync(1L); await probe.ExpectErrorAsync(); - var r = await closePromise.Task.ShouldCompleteWithin(3.Seconds()); + var r = await closePromise.Task.WaitAsync(3.Seconds()); r.Should().Be("Closed"); }, Materializer); } @@ -609,7 +609,7 @@ await this.AssertAllStagesStoppedAsync(async () => await probe.RequestAsync(1L); await probe.ExpectErrorAsync(); - var r = await closePromise.Task.ShouldCompleteWithin(3.Seconds()); + var r = await closePromise.Task.WaitAsync(3.Seconds()); r.Should().Be("Closed"); }, Materializer); } diff --git a/src/core/Akka.Streams.Tests/Dsl/ValveSpec.cs b/src/core/Akka.Streams.Tests/Dsl/ValveSpec.cs index 0621ac7cb80..325e0ae0d8c 100644 --- a/src/core/Akka.Streams.Tests/Dsl/ValveSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/ValveSpec.cs @@ -32,10 +32,10 @@ public async Task Closed_Valve_should_emit_only_3_elements_into_a_sequence_when_ var switchTask = t.Item1; var seq = t.Item2; - var valveSwitch = await switchTask.ShouldCompleteWithin(3.Seconds()); + var valveSwitch = await switchTask.WaitAsync(3.Seconds()); await Task.Delay(100); var flip = valveSwitch.Flip(SwitchMode.Open); - var complete = await flip.ShouldCompleteWithin(3.Seconds()); + var complete = await flip.WaitAsync(3.Seconds()); complete.Should().BeTrue(); } @@ -48,12 +48,12 @@ public async Task Closed_Valve_should_emit_only_5_elements_when_the_valve_is_swi .ToMaterialized(this.SinkProbe(), Keep.Both) .Run(Sys.Materializer()); - IValveSwitch valveSwitch = await switchTask.ShouldCompleteWithin(3.Seconds()); + IValveSwitch valveSwitch = await switchTask.WaitAsync(3.Seconds()); probe.Request(2); probe.ExpectNoMsg(TimeSpan.FromMilliseconds(100)); Task flip = valveSwitch.Flip(SwitchMode.Open); - var complete = await flip.ShouldCompleteWithin(3.Seconds()); + var complete = await flip.WaitAsync(3.Seconds()); // valve is now open complete.Should().BeTrue(); // @@ -78,11 +78,11 @@ public async Task Closed_Valve_should_emit_only_3_elements_when_the_valve_is_swi var switchTask = t.Item1.Item2; var sinkProbe = t.Item2; - var valveSwitch = await switchTask.ShouldCompleteWithin(3.Seconds()); + var valveSwitch = await switchTask.WaitAsync(3.Seconds()); sinkProbe.Request(1); var flip = valveSwitch.Flip(SwitchMode.Open); - var complete = await flip.ShouldCompleteWithin(3.Seconds()); + var complete = await flip.WaitAsync(3.Seconds()); complete.Should().BeTrue(); sourceProbe.SendNext(1); @@ -90,13 +90,13 @@ public async Task Closed_Valve_should_emit_only_3_elements_when_the_valve_is_swi sinkProbe.ExpectNext().Should().Be(1); flip = valveSwitch.Flip(SwitchMode.Close); - var complete1 = await flip.ShouldCompleteWithin(3.Seconds()); + var complete1 = await flip.WaitAsync(3.Seconds()); complete1.Should().BeTrue(); sinkProbe.ExpectNoMsg(TimeSpan.FromMilliseconds(100)); flip = valveSwitch.Flip(SwitchMode.Open); - var complete2 = await flip.ShouldCompleteWithin(3.Seconds()); + var complete2 = await flip.WaitAsync(3.Seconds()); complete2.Should().BeTrue(); sinkProbe.ExpectNoMsg(TimeSpan.FromMilliseconds(100)); @@ -123,12 +123,12 @@ public async Task Closed_Valve_should_return_false_when_the_valve_is_already_clo var switchTask = t.Item1; var probe = t.Item2; - var valveSwitch = await switchTask.ShouldCompleteWithin(3.Seconds()); + var valveSwitch = await switchTask.WaitAsync(3.Seconds()); - var complete = await valveSwitch.Flip(SwitchMode.Close).ShouldCompleteWithin(3.Seconds()); + var complete = await valveSwitch.Flip(SwitchMode.Close).WaitAsync(3.Seconds()); complete.Should().BeFalse(); - var complete1 = await valveSwitch.Flip(SwitchMode.Close).ShouldCompleteWithin(3.Seconds()); + var complete1 = await valveSwitch.Flip(SwitchMode.Close).WaitAsync(3.Seconds()); complete1.Should().BeFalse(); } @@ -142,7 +142,7 @@ public async Task Closed_Valve_should_emit_nothing_when_the_source_is_empty() var seq = t.Item2; - var complete = await seq.ShouldCompleteWithin(3.Seconds()); + var complete = await seq.WaitAsync(3.Seconds()); complete.Should().BeEmpty(); } @@ -159,7 +159,7 @@ public async Task Closed_Valve_should_emit_nothing_when_the_source_is_failing() var resultException = await Awaiting(async () => await seq) .Should().ThrowAsync() - .ShouldCompleteWithin(3.Seconds()); + .WaitAsync(3.Seconds()); resultException.And.Should().Be(ex); } @@ -176,7 +176,7 @@ public async Task Closed_Valve_should_not_pull_elements_again_when_opened_and_cl var switchTask = t.Item2; var resultTask = t.Item3; - var valveSwitch = await switchTask.ShouldCompleteWithin(3.Seconds()); + var valveSwitch = await switchTask.WaitAsync(3.Seconds()); async Task result() { @@ -189,7 +189,7 @@ async Task result() return await resultTask; } - var complete = await result().ShouldCompleteWithin(3.Seconds()); + var complete = await result().WaitAsync(3.Seconds()); complete.Should().Be(1); } @@ -204,8 +204,8 @@ public async Task Closed_Valve_should_be_in_closed_state() var switchTask = t.Item1; var seq = t.Item2; - var valveSwitch = await switchTask.ShouldCompleteWithin(3.Seconds()); - var mode = await valveSwitch.GetMode().ShouldCompleteWithin(3.Seconds()); + var valveSwitch = await switchTask.WaitAsync(3.Seconds()); + var mode = await valveSwitch.GetMode().WaitAsync(3.Seconds()); mode.Should().Be(SwitchMode.Close); } @@ -221,28 +221,28 @@ public async Task Open_Valve_should_emit_5_elements_after_it_has_been_close_open var switchTask = t.Item1.Item2; var sinkProbe = t.Item2; - var valveSwitch = await switchTask.ShouldCompleteWithin(3.Seconds()); + var valveSwitch = await switchTask.WaitAsync(3.Seconds()); sinkProbe.Request(1); var flip = valveSwitch.Flip(SwitchMode.Close); - var complete = await flip.ShouldCompleteWithin(3.Seconds()); + var complete = await flip.WaitAsync(3.Seconds()); complete.Should().BeTrue(); sourceProbe.SendNext(1); sinkProbe.ExpectNoMsg(TimeSpan.FromMilliseconds(100)); flip = valveSwitch.Flip(SwitchMode.Open); - var complete1 = await flip.ShouldCompleteWithin(3.Seconds()); + var complete1 = await flip.WaitAsync(3.Seconds()); complete1.Should().BeTrue(); sinkProbe.ExpectNext().Should().Be(1); flip = valveSwitch.Flip(SwitchMode.Close); - var complete2 = await flip.ShouldCompleteWithin(3.Seconds()); + var complete2 = await flip.WaitAsync(3.Seconds()); complete2.Should().BeTrue(); flip = valveSwitch.Flip(SwitchMode.Open); - var complete3 = await flip.ShouldCompleteWithin(3.Seconds()); + var complete3 = await flip.WaitAsync(3.Seconds()); complete3.Should().BeTrue(); sinkProbe.ExpectNoMsg(TimeSpan.FromMilliseconds(100)); @@ -268,12 +268,12 @@ public async Task Open_Valve_should_return_false_when_the_valve_is_already_opene var switchTask = t.Item1; - var valveSwitch = await switchTask.ShouldCompleteWithin(3.Seconds()); + var valveSwitch = await switchTask.WaitAsync(3.Seconds()); - var complete = await valveSwitch.Flip(SwitchMode.Open).ShouldCompleteWithin(3.Seconds()); + var complete = await valveSwitch.Flip(SwitchMode.Open).WaitAsync(3.Seconds()); complete.Should().BeFalse(); - var complete1 = await valveSwitch.Flip(SwitchMode.Open).ShouldCompleteWithin(3.Seconds()); + var complete1 = await valveSwitch.Flip(SwitchMode.Open).WaitAsync(3.Seconds()); complete1.Should().BeFalse(); } @@ -287,7 +287,7 @@ public async Task Open_Valve_should_emit_only_3_elements_into_a_sequence() var seq = t.Item2; - var complete = await seq.ShouldCompleteWithin(TimeSpan.FromMilliseconds(200)); + var complete = await seq.WaitAsync(TimeSpan.FromMilliseconds(200)); complete.Should().ContainInOrder(1, 2, 3); } @@ -301,7 +301,7 @@ public async Task Open_Valve_should_emit_nothing_when_the_source_is_empty() var seq = t.Item2; - var complete = await seq.ShouldCompleteWithin(3.Seconds()); + var complete = await seq.WaitAsync(3.Seconds()); complete.Should().BeEmpty(); } @@ -319,7 +319,7 @@ public async Task Open_Valve_should_emit_nothing_when_the_source_is_failing() var resultException = await Awaiting(async () => await seq) .Should().ThrowAsync() - .ShouldCompleteWithin(3.Seconds()); + .WaitAsync(3.Seconds()); resultException.And.Should().Be(ex); } @@ -336,7 +336,7 @@ public async Task Open_Valve_should_not_pull_elements_again_when_closed_and_re_o var switchTask = t.Item2; var resultTask = t.Item3; - var valveSwitch = await switchTask.ShouldCompleteWithin(3.Seconds()); + var valveSwitch = await switchTask.WaitAsync(3.Seconds()); async Task result() { @@ -348,7 +348,7 @@ async Task result() return await resultTask; } - var complete = await result().ShouldCompleteWithin(3.Seconds()); + var complete = await result().WaitAsync(3.Seconds()); complete.Should().Be(1); } @@ -362,8 +362,8 @@ public async Task Open_Valve_should_be_in_open_state() var switchTask = t.Item1; - var valveSwitch = await switchTask.ShouldCompleteWithin(3.Seconds()); - var complete = await valveSwitch.GetMode().ShouldCompleteWithin(3.Seconds()); + var valveSwitch = await switchTask.WaitAsync(3.Seconds()); + var complete = await valveSwitch.GetMode().WaitAsync(3.Seconds()); complete.Should().Be(SwitchMode.Open); } } diff --git a/src/core/Akka.Streams.Tests/FusingSpec.cs b/src/core/Akka.Streams.Tests/FusingSpec.cs index 28facd27e45..05f5f31cffc 100644 --- a/src/core/Akka.Streams.Tests/FusingSpec.cs +++ b/src/core/Akka.Streams.Tests/FusingSpec.cs @@ -49,7 +49,7 @@ public async Task A_SubFusingActorMaterializer_must_work_with_asynchronous_bound .Grouped(1000) .RunWith(Sink.First>(), Materializer); - await t.ShouldCompleteWithin(3.Seconds()); + await t.WaitAsync(3.Seconds()); t.Result.Distinct().OrderBy(i => i).Should().BeEquivalentTo(Enumerable.Range(0, 199).Where(i => i%2 == 0)); } @@ -71,7 +71,7 @@ public async Task A_SubFusingActorMaterializer_must_use_multiple_actors_when_the .Grouped(1000) .RunWith(Sink.First>(), Materializer); - await t.ShouldCompleteWithin(3.Seconds()); + await t.WaitAsync(3.Seconds()); t.Result.Should().BeEquivalentTo(Enumerable.Range(0, 10)); var refs = await ReceiveNAsync(20).Distinct().ToListAsync(); @@ -110,7 +110,7 @@ string RefFunc() .Grouped(1000) .RunWith(Sink.First>(), Materializer); - await t.ShouldCompleteWithin(3.Seconds()); + await t.WaitAsync(3.Seconds()); t.Result.Should().BeEquivalentTo(Enumerable.Range(0, 10)); var refs = await ReceiveNAsync(20).Distinct().ToListAsync(); diff --git a/src/core/Akka.Streams.Tests/IO/FileSinkSpec.cs b/src/core/Akka.Streams.Tests/IO/FileSinkSpec.cs index e1497c7fd12..3fe43796435 100644 --- a/src/core/Akka.Streams.Tests/IO/FileSinkSpec.cs +++ b/src/core/Akka.Streams.Tests/IO/FileSinkSpec.cs @@ -64,7 +64,7 @@ await TargetFileAsync(async f => var completion = Source.From(_testByteStrings) .RunWith(FileIO.ToFile(f), _materializer); - var result = await completion.ShouldCompleteWithin(Remaining); + var result = await completion.WaitAsync(Remaining); result.Count.Should().Be(6006); await AwaitAssertAsync( @@ -84,7 +84,7 @@ await TargetFileAsync(async f => var completion = Source.From(_testByteStrings) .RunWith(FileIO.ToFile(f), _materializer); - var result = await completion.ShouldCompleteWithin(Remaining); + var result = await completion.WaitAsync(Remaining); result.Count.Should().Be(6006); await AwaitAssertAsync( () => CheckFileContent(f, _testLines.Aggregate((s, s1) => s + s1)), @@ -105,7 +105,7 @@ Task Write(IEnumerable lines) => Source.From(lines) .RunWith(FileIO.ToFile(f, FileMode.OpenOrCreate), _materializer); var completion1 = Write(_testLines); - await completion1.ShouldCompleteWithin(Remaining); + await completion1.WaitAsync(Remaining); var lastWrite = new string[100]; for (var i = 0; i < 100; i++) @@ -113,7 +113,7 @@ Task Write(IEnumerable lines) => Source.From(lines) var completion2 = Write(lastWrite); - var result = await completion2.ShouldCompleteWithin(Remaining); + var result = await completion2.WaitAsync(Remaining); var lastWriteString = new string(lastWrite.SelectMany(x => x).ToArray()); result.Count.Should().Be(lastWriteString.Length); @@ -138,11 +138,11 @@ Task Write(List lines) => .RunWith(FileIO.ToFile(f), _materializer); var task1 = Write(_testLines); - await task1.ShouldCompleteWithin(Remaining); + await task1.WaitAsync(Remaining); var lastWrite = Enumerable.Range(0, 100).Select(_ => "x").ToList(); var task2 = Write(lastWrite); - var result = await task2.ShouldCompleteWithin(Remaining); + var result = await task2.WaitAsync(Remaining); result.Count.Should().Be(lastWrite.Count); @@ -166,7 +166,7 @@ Task Write(List lines) => Source.From(lines) var completion1 = Write(_testLines); - var result1 = await completion1.ShouldCompleteWithin(Remaining); ; + var result1 = await completion1.WaitAsync(Remaining); ; var lastWrite = new List(); for (var i = 0; i < 100; i++) @@ -174,7 +174,7 @@ Task Write(List lines) => Source.From(lines) var completion2 = Write(lastWrite); - var result2 = await completion2.ShouldCompleteWithin(Remaining); + var result2 = await completion2.WaitAsync(Remaining); var lastWriteString = new string(lastWrite.SelectMany(x => x).ToArray()); var testLinesString = new string(_testLines.SelectMany(x => x).ToArray()); @@ -221,10 +221,10 @@ Task Write(List lines, long pos) => Source.From(lines) _materializer); var completion1 = Write(_testLines, 0); - await completion1.ShouldCompleteWithin(Remaining); + await completion1.WaitAsync(Remaining); var completion2 = Write(testLinesPart2, startPosition); - var result2 = await completion2.ShouldCompleteWithin(Remaining); + var result2 = await completion2.WaitAsync(Remaining); f.Length.ShouldBe(startPosition + result2.Count); @@ -321,7 +321,7 @@ await TargetFileAsync(async f => var completion = Source.From(new []{_testByteStrings.Head()}) .RunWith(lazySink, _materializer); - await completion.ShouldCompleteWithin(Remaining); + await completion.WaitAsync(Remaining); await AwaitAssertAsync( () => CheckFileContent(f, _testLines.Head()), Remaining); @@ -342,7 +342,7 @@ await TargetFileAsync(async f => }) .RunWith(FileIO.ToFile(f), _materializer); - var ex = await InterceptAsync(() => completion).ShouldCompleteWithin(3.Seconds()); + var ex = await InterceptAsync(() => completion).WaitAsync(3.Seconds()); ex.IoResult.Count.ShouldBe(1001); CheckFileContent(f, string.Join("", _testLines.TakeWhile(s => !s.Contains('b')))); await Task.CompletedTask; @@ -357,12 +357,7 @@ await TargetFileAsync(async _ => var completion = Source.Single(ByteString.FromString("42")) .RunWith(FileIO.ToFile(new FileInfo("I-hope-this-file-doesnt-exist.txt"), FileMode.Open), _materializer); - async Task Exec() - { - await completion; - } - - await Exec().ShouldThrowWithin(RemainingOrDefault); + await AssertThrowsAsync(() => completion).WaitAsync(RemainingOrDefault); }, _materializer); } @@ -397,7 +392,7 @@ await AwaitAssertAsync(() => // We still have to wait for the task to complete, because the signal // came from the FileSink actor, not the source actor. - await task.ShouldCompleteWithin(Remaining); + await task.WaitAsync(Remaining); await ExpectTerminatedAsync(actor, Remaining); f.Length.ShouldBe(8); diff --git a/src/core/Akka.Streams.Tests/IO/FileSourceSpec.cs b/src/core/Akka.Streams.Tests/IO/FileSourceSpec.cs index e1b8ad56b49..169289777e9 100644 --- a/src/core/Akka.Streams.Tests/IO/FileSourceSpec.cs +++ b/src/core/Akka.Streams.Tests/IO/FileSourceSpec.cs @@ -241,7 +241,7 @@ await this.AssertAllStagesStoppedAsync(async() => c.ExpectSubscription(); c.ExpectError(); - var complete = await r.ShouldCompleteWithin(Dilated(TimeSpan.FromSeconds(3))); + var complete = await r.WaitAsync(Dilated(TimeSpan.FromSeconds(3))); complete.WasSuccessful.ShouldBeFalse(); }, _materializer); } diff --git a/src/core/Akka.Streams.Tests/IO/OutputStreamSinkSpec.cs b/src/core/Akka.Streams.Tests/IO/OutputStreamSinkSpec.cs index aaa5e1f0c96..29d3d7aed27 100644 --- a/src/core/Akka.Streams.Tests/IO/OutputStreamSinkSpec.cs +++ b/src/core/Akka.Streams.Tests/IO/OutputStreamSinkSpec.cs @@ -221,7 +221,7 @@ await this.AssertAllStagesStoppedAsync(async () => await p.ExpectMsgAsync(datas[0].ToString()); await p.ExpectMsgAsync(datas[1].ToString()); await p.ExpectMsgAsync(datas[2].ToString()); - await completion.ShouldCompleteWithin(3.Seconds()); + await completion.WaitAsync(3.Seconds()); }, _materializer); } @@ -235,7 +235,8 @@ await this.AssertAllStagesStoppedAsync(async () => .RunWith(StreamConverters.FromOutputStream(() => new CloseOutputStream(p)), _materializer); await p.ExpectMsgAsync("closed"); - await completion.ShouldThrowWithin(3.Seconds()); + + await AssertThrowsAsync(() => completion).WaitAsync(3.Seconds()); }, _materializer); } @@ -248,7 +249,7 @@ await Awaiting(async () => { await Source.Failed(new Exception("Boom!")) .RunWith(StreamConverters.FromOutputStream(() => new OutputStream()), _materializer) - .ShouldCompleteWithin(3.Seconds()); + .WaitAsync(3.Seconds()); }).Should().ThrowAsync(); }, _materializer); } @@ -263,7 +264,7 @@ await this.AssertAllStagesStoppedAsync(async () => .RunWith(StreamConverters.FromOutputStream(() => new CompletionOutputStream(p)), _materializer); await p.ExpectMsgAsync("closed"); - await completion.ShouldCompleteWithin(3.Seconds()); + await completion.WaitAsync(3.Seconds()); }, _materializer); } } diff --git a/src/core/Akka.Streams.Tests/IO/OutputStreamSourceSpec.cs b/src/core/Akka.Streams.Tests/IO/OutputStreamSourceSpec.cs index 903841bb02c..02b76420356 100644 --- a/src/core/Akka.Streams.Tests/IO/OutputStreamSourceSpec.cs +++ b/src/core/Akka.Streams.Tests/IO/OutputStreamSourceSpec.cs @@ -67,7 +67,7 @@ await this.AssertAllStagesStoppedAsync(async () => var s = await probe.ExpectSubscriptionAsync(); await outputStream.WriteAsync(_bytesArray, 0, _bytesArray.Length) - .ShouldCompleteWithin(Timeout); + .WaitAsync(Timeout); s.Request(1); await probe.ExpectNextAsync(_byteString); outputStream.Dispose(); @@ -89,14 +89,14 @@ await this.AssertAllStagesStoppedAsync(async () => var s = await probe.ExpectSubscriptionAsync(); await outputStream.WriteAsync(_bytesArray, 0, _bytesArray.Length) - .ShouldCompleteWithin(Timeout); + .WaitAsync(Timeout); var f = outputStream.FlushAsync(); await ExpectTimeout(f, Timeout); await probe.ExpectNoMsgAsync(TimeSpan.Zero); s.Request(1); - await f.ShouldCompleteWithin(Timeout); + await f.WaitAsync(Timeout); await probe.AsyncBuilder().ExpectNext(_byteString).ExecuteAsync(); } @@ -118,14 +118,14 @@ await this.AssertAllStagesStoppedAsync(async () => var s = await probe.ExpectSubscriptionAsync(); await outputStream.WriteAsync(_bytesArray, 0, _byteString.Count) - .ShouldCompleteWithin(Timeout); + .WaitAsync(Timeout); var f = outputStream.FlushAsync(); s.Request(1); - await f.ShouldCompleteWithin(Timeout); + await f.WaitAsync(Timeout); await probe.ExpectNextAsync(_byteString); var f2 = outputStream.FlushAsync(); - await f2.ShouldCompleteWithin(Timeout); + await f2.WaitAsync(Timeout); } await probe.ExpectCompleteAsync(); @@ -148,7 +148,7 @@ await this.AssertAllStagesStoppedAsync(async () => foreach (var _ in Enumerable.Range(1, 16)) await outputStream.WriteAsync(_bytesArray, 0, _byteString.Count) - .ShouldCompleteWithin(Timeout); + .WaitAsync(Timeout); //blocked call var f = outputStream.WriteAsync(_bytesArray, 0, _byteString.Count); @@ -157,7 +157,7 @@ await outputStream.WriteAsync(_bytesArray, 0, _byteString.Count) await probe.ExpectNoMsgAsync(TimeSpan.Zero); s.Request(17); - await f.ShouldCompleteWithin(Timeout); + await f.WaitAsync(Timeout); await probe.ExpectNextNAsync(Enumerable.Repeat(_byteString, 17).ToList()); } @@ -178,8 +178,8 @@ await this.AssertAllStagesStoppedAsync(async () => outputStream.Dispose(); await probe.ExpectCompleteAsync(); - await outputStream.WriteAsync(_bytesArray, 0, _byteString.Count) - .ShouldThrowWithin(Timeout); + await AssertThrowsAsync(() => outputStream.WriteAsync(_bytesArray, 0, _byteString.Count)) + .WaitAsync(Timeout); }, _materializer); } @@ -219,7 +219,7 @@ await this.AssertAllStagesStoppedAsync(async () => var s = await probe.ExpectSubscriptionAsync(); await outputStream.WriteAsync(_bytesArray, 0, _bytesArray.Length) - .ShouldCompleteWithin(Timeout); + .WaitAsync(Timeout); s.Request(1); await sourceProbe.ExpectMsgAsync(); @@ -229,8 +229,8 @@ await outputStream.WriteAsync(_bytesArray, 0, _bytesArray.Length) await sourceProbe.ExpectMsgAsync(); await Task.Delay(500); - await outputStream.WriteAsync(_bytesArray, 0, _bytesArray.Length) - .ShouldThrowWithin(Timeout); + await AssertThrowsAsync(() => outputStream.WriteAsync(_bytesArray, 0, _bytesArray.Length)) + .WaitAsync(Timeout); }, _materializer); } diff --git a/src/core/Akka.Streams.Tests/IO/TcpSpec.cs b/src/core/Akka.Streams.Tests/IO/TcpSpec.cs index 21434e8043e..e6c0e34ac83 100644 --- a/src/core/Akka.Streams.Tests/IO/TcpSpec.cs +++ b/src/core/Akka.Streams.Tests/IO/TcpSpec.cs @@ -105,7 +105,7 @@ public async Task Outgoing_TCP_stream_must_be_able_to_read_a_sequence_of_ByteStr serverConnection.ConfirmedClose(); // Reduced timeout - otherwise we're just waiting longer for the failure - var result = await resultFuture.ShouldCompleteWithin(3.Seconds()); + var result = await resultFuture.WaitAsync(3.Seconds()); result.ShouldBe(expectedOutput); } @@ -124,7 +124,7 @@ await this.AssertAllStagesStoppedAsync(async () => .ToMaterialized(Sink.Ignore(), Keep.Left) .Run(Materializer); - await Awaiting(() => task.ShouldCompleteWithin(3.Seconds())) + await Awaiting(() => task.WaitAsync(3.Seconds())) .Should().ThrowAsync().WithMessage("Connection failed*"); }, Materializer); } @@ -438,7 +438,7 @@ await this.AssertAllStagesStoppedAsync(async () => Sink.ForEach(conn => conn.Flow.Join(writeButIgnoreRead).Run(Materializer)), Keep.Left) .Run(Materializer); - await task.ShouldCompleteWithin(3.Seconds()); + await task.WaitAsync(3.Seconds()); var binding = task.Result; var (promise, result) = Source.Maybe() @@ -446,11 +446,11 @@ await this.AssertAllStagesStoppedAsync(async () => .ToMaterialized(Sink.Aggregate(ByteString.Empty, (s, s1) => s + s1), Keep.Both) .Run(Materializer); - await result.ShouldCompleteWithin(5.Seconds()); + await result.WaitAsync(5.Seconds()); result.Result.Should().BeEquivalentTo(ByteString.FromString("Early response")); promise.SetResult(null); // close client upstream, no more data - await binding.Unbind().ShouldCompleteWithin(3.Seconds()); + await binding.Unbind().WaitAsync(3.Seconds()); }, Materializer); } @@ -470,7 +470,7 @@ public async Task Outgoing_TCP_stream_must_Echo_should_work_even_if_server_is_in var result = await Source.From(Enumerable.Repeat(0, 1000) .Select(i => ByteString.FromBytes([Convert.ToByte(i)]))) .Via(Sys.TcpStream().OutgoingConnection(serverAddress, halfClose: true)) - .RunAggregate(0, (i, s) => i + s.Count, Materializer).ShouldCompleteWithin(10.Seconds()); + .RunAggregate(0, (i, s) => i + s.Count, Materializer).WaitAsync(10.Seconds()); result.Should().Be(1000); @@ -507,7 +507,7 @@ await AwaitAssertAsync(async () => // Getting rid of existing connection actors by using a blunt instrument system2.ActorSelection(system2.Tcp().Path / "tcp-client-connection-*").Tell(Kill.Instance); - await result.ShouldCompleteWithin(3.Seconds()); + await result.WaitAsync(3.Seconds()); }, interval:TimeSpan.FromSeconds(4)); }); @@ -515,7 +515,7 @@ await AwaitAssertAsync(async () => }) .Should().ThrowAsync(); - await binding.Result.Unbind().ShouldCompleteWithin(3.Seconds()); + await binding.Result.Unbind().WaitAsync(3.Seconds()); } finally { @@ -540,10 +540,10 @@ public async Task Outgoing_TCP_stream_must_not_thrown_on_unbind_after_system_has // and is possible to communicate with await Source.Single(ByteString.FromString("")) .Via(sys2.TcpStream().OutgoingConnection(address)) - .RunWith(Sink.Ignore(), mat2).ShouldCompleteWithin(10.Seconds()); + .RunWith(Sink.Ignore(), mat2).WaitAsync(10.Seconds()); - await sys2.Terminate().ShouldCompleteWithin(10.Seconds()); - await binding.Unbind().ShouldCompleteWithin(10.Seconds()); + await sys2.Terminate().WaitAsync(10.Seconds()); + await binding.Unbind().WaitAsync(10.Seconds()); } finally { @@ -573,7 +573,7 @@ public async Task Tcp_listen_stream_must_be_able_to_implement_echo() .Run(Materializer); // make sure that the server has bound to the socket - var binding = await bindTask.ShouldCompleteWithin(3.Seconds()); + var binding = await bindTask.WaitAsync(3.Seconds()); var testInput = Enumerable.Range(0, 255) .Select(i => ByteString.FromBytes([Convert.ToByte(i)])) @@ -584,11 +584,11 @@ public async Task Tcp_listen_stream_must_be_able_to_implement_echo() var result = await Source.From(testInput) .Via(Sys.TcpStream().OutgoingConnection(serverAddress)) .RunAggregate(ByteString.Empty, (agg, b) => agg.Concat(b), Materializer) - .ShouldCompleteWithin(10.Seconds()); + .WaitAsync(10.Seconds()); result.Should().BeEquivalentTo(expectedOutput); - await binding.Unbind().ShouldCompleteWithin(3.Seconds()); - await echoServerFinish.ShouldCompleteWithin(3.Seconds()); + await binding.Unbind().WaitAsync(3.Seconds()); + await echoServerFinish.WaitAsync(3.Seconds()); } [Fact] @@ -601,7 +601,7 @@ public async Task Tcp_listen_stream_must_work_with_a_chain_of_echoes() .Run(Materializer); // make sure that the server has bound to the socket - var binding = await bindTask.ShouldCompleteWithin(3.Seconds()); + var binding = await bindTask.WaitAsync(3.Seconds()); var echoConnection = Sys.TcpStream().OutgoingConnection(serverAddress); @@ -617,11 +617,11 @@ public async Task Tcp_listen_stream_must_work_with_a_chain_of_echoes() .Via(echoConnection) .Via(echoConnection) .RunAggregate(ByteString.Empty, (agg, b) => agg.Concat(b), Materializer) - .ShouldCompleteWithin(10.Seconds()); + .WaitAsync(10.Seconds()); result.Should().BeEquivalentTo(expectedOutput); - await binding.Unbind().ShouldCompleteWithin(3.Seconds()); - await echoServerFinish.ShouldCompleteWithin(3.Seconds()); + await binding.Unbind().WaitAsync(3.Seconds()); + await echoServerFinish.WaitAsync(3.Seconds()); } [Fact] @@ -634,7 +634,7 @@ public async Task Tcp_stream_must_be_able_to_be_unbound_multiple_times() .Run(Materializer); // make sure that the server has bound to the socket - var binding = await bindTask.ShouldCompleteWithin(3.Seconds()); + var binding = await bindTask.WaitAsync(3.Seconds()); await Task.WhenAll( binding.Unbind(), @@ -644,9 +644,9 @@ await Task.WhenAll( binding.Unbind(), binding.Unbind(), binding.Unbind()) - .ShouldCompleteWithin(3.Seconds()); + .WaitAsync(3.Seconds()); - await echoServerFinish.ShouldCompleteWithin(3.Seconds()); + await echoServerFinish.WaitAsync(3.Seconds()); } [Fact] @@ -661,7 +661,7 @@ await EventFilter.Exception().ExpectAsync(2, async () => // bind succeed, we have local address var binding1 = await bind.To(Sink.FromSubscriber(probe1)).Run(Materializer) - .ShouldCompleteWithin(3.Seconds()); + .WaitAsync(3.Seconds()); await probe1.ExpectSubscriptionAsync(); @@ -673,22 +673,22 @@ await EventFilter.Exception().ExpectAsync(2, async () => var binding3F = bind.To(Sink.FromSubscriber(probe3)).Run(Materializer); (await probe3.ExpectSubscriptionAndErrorAsync()).Should().BeOfType(); - await Awaiting(() => binding2F.ShouldCompleteWithin(3.Seconds())) + await Awaiting(() => binding2F.WaitAsync(3.Seconds())) .Should().ThrowAsync(); - await Awaiting(() => binding3F.ShouldCompleteWithin(3.Seconds())) + await Awaiting(() => binding3F.WaitAsync(3.Seconds())) .Should().ThrowAsync(); // Now unbind first - await binding1.Unbind().ShouldCompleteWithin(3.Seconds()); + await binding1.Unbind().WaitAsync(3.Seconds()); probe1.ExpectComplete(); var probe4 = this.CreateManualSubscriberProbe(); // bind succeeded, we have local address - var binding4 = await bind.To(Sink.FromSubscriber(probe4)).Run(Materializer).ShouldCompleteWithin(3.Seconds()); + var binding4 = await bind.To(Sink.FromSubscriber(probe4)).Run(Materializer).WaitAsync(3.Seconds()); await probe4.ExpectSubscriptionAsync(); // clean up - await binding4.Unbind().ShouldCompleteWithin(5.Seconds()); + await binding4.Unbind().WaitAsync(5.Seconds()); }); } @@ -713,7 +713,7 @@ await this.AssertAllStagesStoppedAsync(async () => .Run(Materializer); // make sure server is running first - await bindingTask.ShouldCompleteWithin(3.Seconds()); + await bindingTask.WaitAsync(3.Seconds()); var result = bindingTask.Result; // then connect, should trigger a block and then @@ -721,7 +721,7 @@ await this.AssertAllStagesStoppedAsync(async () => .Via(Sys.TcpStream().OutgoingConnection(serverAddress)) .RunAggregate(0, (i, s) => i + s.Count, Materializer); - (await total.ShouldCompleteWithin(5.Seconds())).Should().Be(1000); + (await total.WaitAsync(5.Seconds())).Should().Be(1000); }, Materializer); } @@ -750,12 +750,12 @@ await this.AssertAllStagesStoppedAsync(async () => var total = folder.Run(Materializer); - await firstClientConnected.Task.ShouldCompleteWithin(2.Seconds()); + await firstClientConnected.Task.WaitAsync(2.Seconds()); var rejected = folder.Run(Materializer); - (await total.ShouldCompleteWithin(10.Seconds())).Should().Be(100); + (await total.WaitAsync(10.Seconds())).Should().Be(100); - await rejected.ShouldThrowWithin(3.Seconds()); + await AssertThrowsAsync(() => rejected).WaitAsync(3.Seconds()); }, Materializer); } } diff --git a/src/core/Akka.Streams.Tests/Implementation/Fusing/ActorGraphInterpreterSpec.cs b/src/core/Akka.Streams.Tests/Implementation/Fusing/ActorGraphInterpreterSpec.cs index 4ebceda6430..a1c14ed6cb6 100644 --- a/src/core/Akka.Streams.Tests/Implementation/Fusing/ActorGraphInterpreterSpec.cs +++ b/src/core/Akka.Streams.Tests/Implementation/Fusing/ActorGraphInterpreterSpec.cs @@ -47,7 +47,7 @@ await this.AssertAllStagesStoppedAsync(async() => .Via(identity) .Grouped(200) .RunWith(Sink.First>(), Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().Equal(Enumerable.Range(1, 100)); }, Materializer); } @@ -66,7 +66,7 @@ await this.AssertAllStagesStoppedAsync(async() => .Grouped(200) .RunWith(Sink.First>(), Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().Equal(Enumerable.Range(1, 100)); }, Materializer); } @@ -84,7 +84,7 @@ await this.AssertAllStagesStoppedAsync(async() => .Grouped(100) .RunWith(Sink.First>(), Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().Equal(Enumerable.Range(1, 10)); }, Materializer); } @@ -103,7 +103,7 @@ await this.AssertAllStagesStoppedAsync(async() => .Grouped(100) .RunWith(Sink.First>(), Materializer); - var complete = await task.ShouldCompleteWithin(3.Seconds()); + var complete = await task.WaitAsync(3.Seconds()); complete.Should().Equal(Enumerable.Range(1, 10)); }, Materializer); } @@ -135,9 +135,9 @@ await this.AssertAllStagesStoppedAsync(async() => return ClosedShape.Instance; })).Run(Materializer); - var complete = await tasks.Item1.ShouldCompleteWithin(3.Seconds()); + var complete = await tasks.Item1.WaitAsync(3.Seconds()); complete.Should().Equal(Enumerable.Range(1, 100)); - var complete1 = await tasks.Item2.ShouldCompleteWithin(3.Seconds()); + var complete1 = await tasks.Item2.WaitAsync(3.Seconds()); complete1.Should().Equal(Enumerable.Range(1, 10)); }, Materializer); } diff --git a/src/core/Akka.Streams.Tests/Implementation/StreamLayoutSpec.cs b/src/core/Akka.Streams.Tests/Implementation/StreamLayoutSpec.cs index 3032a9356d2..1f8da2e5275 100644 --- a/src/core/Akka.Streams.Tests/Implementation/StreamLayoutSpec.cs +++ b/src/core/Akka.Streams.Tests/Implementation/StreamLayoutSpec.cs @@ -259,7 +259,7 @@ public async Task StreamLayout_should_not_fail_materialization_when_building_a_l var t = g.ToMaterialized(Sink.Seq(), Keep.Both).Run(_materializer); var materialized = t.Item1; - var result = await t.Item2.ShouldCompleteWithin(VeryPatient); + var result = await t.Item2.WaitAsync(VeryPatient); materialized.Should().Be(1); result.Count.Should().Be(1); @@ -274,7 +274,7 @@ public async Task StreamLayout_should_not_fail_materialization_when_building_a_l var t = g.RunWith(Source.Single(42).MapMaterializedValue(_ => 1), Sink.Seq(), _materializer); var materialized = t.Item1; - var result = await t.Item2.ShouldCompleteWithin(VeryPatient); + var result = await t.Item2.WaitAsync(VeryPatient); materialized.Should().Be(1); result.Count.Should().Be(1); @@ -289,7 +289,7 @@ public async Task StreamLayout_should_not_fail_materialization_when_building_a_l var t = g.ToMaterialized(Sink.Seq(), Keep.Both).Run(_materializer); var materialized = t.Item1; - var result = await t.Item2.ShouldCompleteWithin(VeryPatient); + var result = await t.Item2.WaitAsync(VeryPatient); materialized.Should().Be(1); result.Count.Should().Be(1); @@ -305,7 +305,7 @@ public async Task StreamLayout_should_not_fail_fusing_and_materialization_when_b var m = g.ToMaterialized(Sink.Seq(), Keep.Both); var t = m.Run(_materializer); var materialized = t.Item1; - var result = await t.Item2.ShouldCompleteWithin(VeryPatient); + var result = await t.Item2.WaitAsync(VeryPatient); materialized.Should().Be(1); result.Count.Should().Be(1); @@ -320,7 +320,7 @@ public async Task StreamLayout_should_not_fail_fusing_and_materialization_when_b var t = g.RunWith(Source.Single(42).MapMaterializedValue(_ => 1), Sink.Seq(), _materializer); var materialized = t.Item1; - var result = await t.Item2.ShouldCompleteWithin(VeryPatient); + var result = await t.Item2.WaitAsync(VeryPatient); materialized.Should().Be(1); result.Count.Should().Be(1); @@ -335,7 +335,7 @@ public async Task StreamLayout_should_not_fail_fusing_and_materialization_when_b var t = g.ToMaterialized(Sink.Seq(), Keep.Both).Run(_materializer); var materialized = t.Item1; - var result = await t.Item2.ShouldCompleteWithin(VeryPatient); + var result = await t.Item2.WaitAsync(VeryPatient); materialized.Should().Be(1); result.Count.Should().Be(1); diff --git a/src/core/Akka.Streams.Tests/Implementation/TimeoutsSpec.cs b/src/core/Akka.Streams.Tests/Implementation/TimeoutsSpec.cs index deae5ab9f7a..1355bce6b0d 100644 --- a/src/core/Akka.Streams.Tests/Implementation/TimeoutsSpec.cs +++ b/src/core/Akka.Streams.Tests/Implementation/TimeoutsSpec.cs @@ -39,7 +39,7 @@ await this.AssertAllStagesStoppedAsync(async () => .InitialTimeout(TimeSpan.FromSeconds(2)).Grouped(200) .RunWith(Sink.First>(), Materializer); - await t.ShouldCompleteWithin(3.Seconds()); + await t.WaitAsync(3.Seconds()); t.Result.Should().BeEquivalentTo(Enumerable.Range(1, 100)); }, Materializer); } @@ -54,7 +54,7 @@ await this.AssertAllStagesStoppedAsync(async () => .InitialTimeout(TimeSpan.FromSeconds(2)).Grouped(200) .RunWith(Sink.First>(), Materializer); - await Awaiting(() => task.ShouldCompleteWithin(3.Seconds())) + await Awaiting(() => task.WaitAsync(3.Seconds())) .Should().ThrowAsync().WithMessage("test"); }, Materializer); } @@ -87,7 +87,7 @@ await this.AssertAllStagesStoppedAsync(async () => .CompletionTimeout(TimeSpan.FromSeconds(2)).Grouped(200) .RunWith(Sink.First>(), Materializer); - await t.ShouldCompleteWithin(3.Seconds()); + await t.WaitAsync(3.Seconds()); t.Result.Should().BeEquivalentTo(Enumerable.Range(1, 100)); }, Materializer); } @@ -102,7 +102,7 @@ await this.AssertAllStagesStoppedAsync(async () => .CompletionTimeout(TimeSpan.FromSeconds(2)).Grouped(200) .RunWith(Sink.First>(), Materializer); - await Awaiting(() => task.ShouldCompleteWithin(3.Seconds())) + await Awaiting(() => task.WaitAsync(3.Seconds())) .Should().ThrowAsync().WithMessage("test"); }, Materializer); } @@ -147,7 +147,7 @@ await this.AssertAllStagesStoppedAsync(async () => .IdleTimeout(TimeSpan.FromSeconds(2)).Grouped(200) .RunWith(Sink.First>(), Materializer); - await t.ShouldCompleteWithin(3.Seconds()); + await t.WaitAsync(3.Seconds()); t.Result.Should().BeEquivalentTo(Enumerable.Range(1, 100)); }, Materializer); } @@ -162,7 +162,7 @@ await this.AssertAllStagesStoppedAsync(async () => .IdleTimeout(TimeSpan.FromSeconds(2)).Grouped(200) .RunWith(Sink.First>(), Materializer); - await Awaiting(() => task.ShouldCompleteWithin(3.Seconds())) + await Awaiting(() => task.WaitAsync(3.Seconds())) .Should().ThrowAsync().WithMessage("test"); }, Materializer); } @@ -206,7 +206,7 @@ await this.AssertAllStagesStoppedAsync(async () => .Grouped(200) .RunWith(Sink.First>(), Materializer); - await task.ShouldCompleteWithin(3.Seconds()); + await task.WaitAsync(3.Seconds()); task.Result.Should().BeEquivalentTo(Enumerable.Range(1, 100)); }, Materializer); } @@ -367,7 +367,7 @@ await this.AssertAllStagesStoppedAsync(async () => .Via(timeoutIdentity).Grouped(200) .RunWith(Sink.First>(), Materializer); - await t.ShouldCompleteWithin(3.Seconds()); + await t.WaitAsync(3.Seconds()); t.Result.Should().BeEquivalentTo(Enumerable.Range(1, 100)); }, Materializer); } @@ -400,8 +400,8 @@ await this.AssertAllStagesStoppedAsync(async () => upstreamWriter.SendComplete(); downstreamWriter.SendComplete(); - await upFinished.ShouldCompleteWithin(3.Seconds()); - await downFinished.ShouldCompleteWithin(3.Seconds()); + await upFinished.WaitAsync(3.Seconds()); + await downFinished.WaitAsync(3.Seconds()); }, Materializer); } diff --git a/src/core/Akka.Streams.Tests/ScriptedTest.cs b/src/core/Akka.Streams.Tests/ScriptedTest.cs index 3444ab786f7..58fbbcbece3 100644 --- a/src/core/Akka.Streams.Tests/ScriptedTest.cs +++ b/src/core/Akka.Streams.Tests/ScriptedTest.cs @@ -341,7 +341,7 @@ await this.AssertAllStagesStoppedAsync(async () => else { // guard against deadlocks, assuming that a test would not take more than 30 seconds. - await Run().ShouldCompleteWithin(30.Seconds()); + await Run().WaitAsync(30.Seconds()); } } diff --git a/src/core/Akka.TestKit/Akka.TestKit.csproj b/src/core/Akka.TestKit/Akka.TestKit.csproj index cdf190ce309..3f7c8a72c17 100644 --- a/src/core/Akka.TestKit/Akka.TestKit.csproj +++ b/src/core/Akka.TestKit/Akka.TestKit.csproj @@ -29,7 +29,6 @@ - diff --git a/src/core/Akka.TestKit/Extensions/TaskExtensions.cs b/src/core/Akka.TestKit/Extensions/TaskExtensions.cs index 22321b0352d..a4d2584ce8b 100644 --- a/src/core/Akka.TestKit/Extensions/TaskExtensions.cs +++ b/src/core/Akka.TestKit/Extensions/TaskExtensions.cs @@ -9,8 +9,6 @@ using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; -using FluentAssertions; -using static FluentAssertions.FluentActions; namespace Akka.TestKit.Extensions { @@ -74,89 +72,5 @@ public static async Task WithTimeout(this Task parentTask, TimeSpan tim } } } - - /// - /// Guard a with a timeout and checks to see if - /// the matches the provided expected value. - /// - /// The Task to be guarded - /// The expected Task.Result - /// The allowed time span for the operation. - /// - /// A formatted phrase as is supported by explaining why the assertion - /// is needed. If the phrase does not start with the word because, it is prepended automatically. - /// - /// - /// Zero or more objects to format using the placeholders in . - /// - /// - public static async Task ShouldCompleteWithin( - this Task task, T expected, TimeSpan timeout, string because = "", params object[] becauseArgs) - { - await Awaiting(async () => - { - var result = await task; - result.Should().Be(expected); - }).Should().CompleteWithinAsync(timeout, because, becauseArgs); - } - - public static async Task ShouldThrowWithin( - this Task task, T expected, TimeSpan timeout, string because = "", params object[] becauseArgs) - where T: Exception - { - (await Awaiting(async () => - { - await task.ShouldCompleteWithin(timeout); - }).Should().ThrowAsync()).And.Should().Be(expected); - } - - public static async Task ShouldThrowWithin( - this Task task, TimeSpan timeout, string because = "", params object[] becauseArgs) - where T: Exception - { - var exception = await Awaiting(async () => - { - await task.ShouldCompleteWithin(timeout); - }).Should().ThrowAsync(); - return (T) exception.And.Should().Subject; - } - - /// - /// Guard a with a timeout and returns the . - /// - /// The Task to be guarded - /// The allowed time span for the operation. - /// - /// A formatted phrase as is supported by explaining why the assertion - /// is needed. If the phrase does not start with the word because, it is prepended automatically. - /// - /// - /// Zero or more objects to format using the placeholders in . - /// - /// - public static async Task ShouldCompleteWithin( - this Task task, TimeSpan timeout, string because = "", params object[] becauseArgs) - { - return (await Awaiting(async () => await task).Should().CompleteWithinAsync(timeout), because, becauseArgs) - .Item1.Subject; - } - - /// - /// Guard a with a timeout. - /// - /// The Task to be guarded - /// The allowed time span for the operation. - /// - /// A formatted phrase as is supported by explaining why the assertion - /// is needed. If the phrase does not start with the word because, it is prepended automatically. - /// - /// - /// Zero or more objects to format using the placeholders in . - /// - public static async Task ShouldCompleteWithin( - this Task task, TimeSpan timeout, string because = "", params object[] becauseArgs) - { - await Awaiting(async () => await task).Should().CompleteWithinAsync(timeout, because, becauseArgs); - } } } diff --git a/src/core/Akka.TestKit/ITestKitAssertions.cs b/src/core/Akka.TestKit/ITestKitAssertions.cs index 7ac0f4710d3..ba59e86da1e 100644 --- a/src/core/Akka.TestKit/ITestKitAssertions.cs +++ b/src/core/Akka.TestKit/ITestKitAssertions.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System; +using System.Threading.Tasks; namespace Akka.TestKit { @@ -54,5 +55,13 @@ public interface ITestKitAssertions /// A template string to display if the assertion fails. /// An optional object array that contains zero or more objects to format. void AssertEqual(T expected, T actual, Func comparer, string format = "", params object[] args); + + Exception AssertThrows(Action action); + + TException AssertThrows(Action action) where TException : Exception; + + Task AssertThrowsAsync(Func action); + + Task AssertThrowsAsync(Func action) where TException : Exception; } } diff --git a/src/core/Akka.TestKit/TestKitBase_Within.cs b/src/core/Akka.TestKit/TestKitBase_Within.cs index bc9732a45c7..b08b2b6f50b 100644 --- a/src/core/Akka.TestKit/TestKitBase_Within.cs +++ b/src/core/Akka.TestKit/TestKitBase_Within.cs @@ -9,7 +9,6 @@ using System.Threading; using System.Threading.Tasks; using Akka.TestKit.Internal; -using FluentAssertions.Extensions; using Nito.AsyncEx.Synchronous; namespace Akka.TestKit @@ -307,7 +306,7 @@ public async Task WithinAsync( var executionTask = function(); // Limit the execution time block to the maximum allowed execution time. // 200 milliseconds is added because Task.Delay() timer is not precise and can return prematurely. - var resultTask = await Task.WhenAny(executionTask, Task.Delay(max + 200.Milliseconds(), cts.Token)); + var resultTask = await Task.WhenAny(executionTask, Task.Delay(max + TimeSpan.FromMilliseconds(200), cts.Token)); if (resultTask == executionTask) { diff --git a/src/core/Akka.Tests.Shared.Internals/AkkaSpec.cs b/src/core/Akka.Tests.Shared.Internals/AkkaSpec.cs index 2cb43a5e7a4..840cbb2ad64 100644 --- a/src/core/Akka.Tests.Shared.Internals/AkkaSpec.cs +++ b/src/core/Akka.Tests.Shared.Internals/AkkaSpec.cs @@ -17,13 +17,9 @@ using Akka.Configuration; using Akka.TestKit.Internal.StringMatcher; using Akka.TestKit.TestEvent; -using Akka.Util; using Akka.Util.Internal; -using FluentAssertions; -using Xunit; using Xunit.Abstractions; using Xunit.Sdk; -using static FluentAssertions.FluentActions; // ReSharper disable once CheckNamespace namespace Akka.TestKit @@ -281,13 +277,12 @@ protected T ExpectMsgPf(string hint, TestKitBase probe, Func pf) /// If the passed action does not complete abruptly with an exception that's an instance of the specified type. protected T Intercept(Action actionThatThrows) where T : Exception { - return Invoking(actionThatThrows) - .Should().ThrowExactly().And; + return Assertions.AssertThrows(actionThatThrows); } - protected async Task InterceptAsync(Func funcThatThrows) where T : Exception + protected Task InterceptAsync(Func funcThatThrows) where T : Exception { - return (await funcThatThrows.Should().ThrowExactlyAsync()).And; + return Assertions.AssertThrowsAsync(funcThatThrows); } /// @@ -311,10 +306,30 @@ protected void AssertThrows(Action actionThatThrows) where T : Exception Intercept(actionThatThrows); } - [Obsolete("Use AssertThrows instead.")] - protected void Intercept(Action actionThatThrows) + protected async Task AssertThrowsAsync(Func funcThatThrows, Exception expected) { - Invoking(actionThatThrows).Should().Throw(); + var exception = await Assertions.AssertThrowsAsync(funcThatThrows); + + // NOTE: + // This is how FluentAssertions do exception equality, more or less + // It unwraps AggregateException and checks to see if any of the internal exceptions + // matches the expected exception. + // Without this code, some unit tests will fail. + if (exception is AggregateException ae) + { + exception = ae.InnerExceptions[0]; + } + Assertions.AssertEqual(expected, exception); + } + + protected Task AssertThrowsAsync(Func funcThatThrows) where T : Exception + { + return Assertions.AssertThrowsAsync(funcThatThrows); + } + + protected Task AssertThrowsAsync(Func funcThatThrows) + { + return Assertions.AssertThrowsAsync(funcThatThrows); } protected void MuteDeadLetters(params Type[] messageClasses) diff --git a/src/core/Akka.Tests/Actor/Scheduler/TaskBasedScheduler_TellScheduler_Schedule_Tests.cs b/src/core/Akka.Tests/Actor/Scheduler/TaskBasedScheduler_TellScheduler_Schedule_Tests.cs index c8b9aeb7c4d..aeaa7e9ae8b 100644 --- a/src/core/Akka.Tests/Actor/Scheduler/TaskBasedScheduler_TellScheduler_Schedule_Tests.cs +++ b/src/core/Akka.Tests/Actor/Scheduler/TaskBasedScheduler_TellScheduler_Schedule_Tests.cs @@ -19,6 +19,7 @@ namespace Akka.Tests.Actor.Scheduler // ReSharper disable once InconsistentNaming public class DefaultScheduler_TellScheduler_Schedule_Tests : AkkaSpec { +#pragma warning disable xUnit1008 [LocalTheory(SkipLocal = "Tests that messages are sent with the specified interval, however due to inaccuracy " + "of Task.Delay this often fails. Run this especially if you've made changes to DedicatedThreadScheduler")] [InlineData(10, 1000)] diff --git a/src/core/Akka.Tests/Actor/SupervisorHierarchySpec.cs b/src/core/Akka.Tests/Actor/SupervisorHierarchySpec.cs index fc8857b18f2..fe7ec850ce3 100644 --- a/src/core/Akka.Tests/Actor/SupervisorHierarchySpec.cs +++ b/src/core/Akka.Tests/Actor/SupervisorHierarchySpec.cs @@ -140,7 +140,7 @@ await EventFilter.Exception().ExpectOneAsync(async () => // manager + all workers should be restarted by only killing a worker // manager doesn't trap exits, so boss will restart manager - await countDown.WaitAsync().ShouldCompleteWithin(5.Seconds()); + await countDown.WaitAsync().WaitAsync(5.Seconds()); //countDown.Wait(TimeSpan.FromSeconds(5)).ShouldBe(true); }); @@ -176,8 +176,8 @@ await EventFilter.Exception().ExpectAsync(2, () => boss.Tell("killCrasher"); return Task.CompletedTask; }); - await countDownMessages.WaitAsync().ShouldCompleteWithin(2.Seconds()); - await countDownMax.WaitAsync().ShouldCompleteWithin(2.Seconds()); + await countDownMessages.WaitAsync().WaitAsync(2.Seconds()); + await countDownMax.WaitAsync().WaitAsync(2.Seconds()); } private async Task Helper_A_supervisor_hierarchy_must_resume_children_after_Resume()