diff --git a/src/contrib/cluster/Akka.Cluster.Sharding.Tests/CoordinatedShutdownShardingSpec.cs b/src/contrib/cluster/Akka.Cluster.Sharding.Tests/CoordinatedShutdownShardingSpec.cs index 7200930ade6..21ea9941665 100644 --- a/src/contrib/cluster/Akka.Cluster.Sharding.Tests/CoordinatedShutdownShardingSpec.cs +++ b/src/contrib/cluster/Akka.Cluster.Sharding.Tests/CoordinatedShutdownShardingSpec.cs @@ -103,9 +103,9 @@ protected override void BeforeTermination() /// /// Using region 2 as it is not shutdown in either test. /// - private void PingEntities() + private async Task PingEntities() { - AwaitAssert(() => + await AwaitAssertAsync(() => { _region2.Tell(1, _probe2.Ref); _probe2.ExpectMsg(1.Seconds()).Should().Be(1); @@ -117,22 +117,22 @@ private void PingEntities() } [Fact] - public void Sharding_and_CoordinatedShutdown_must_run_successfully() + public async Task Sharding_and_CoordinatedShutdown_must_run_successfully() { - InitCluster(); - RunCoordinatedShutdownWhenLeaving(); - RunCoordinatedShutdownWhenDowning(); + await InitCluster(); + await RunCoordinatedShutdownWhenLeaving(); + await RunCoordinatedShutdownWhenDowning(); } - private void InitCluster() + private async Task InitCluster() { Cluster.Get(_sys1).Join(Cluster.Get(_sys1).SelfAddress); // coordinator will initially run on sys1 - AwaitAssert(() => Cluster.Get(_sys1).SelfMember.Status.Should().Be(MemberStatus.Up)); + await AwaitAssertAsync(() => Cluster.Get(_sys1).SelfMember.Status.Should().Be(MemberStatus.Up)); Cluster.Get(_sys2).Join(Cluster.Get(_sys1).SelfAddress); - Within(10.Seconds(), () => + await WithinAsync(10.Seconds(), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { Cluster.Get(_sys1).State.Members.Count.Should().Be(2); Cluster.Get(_sys1).State.Members.All(x => x.Status == MemberStatus.Up).Should().BeTrue(); @@ -142,9 +142,9 @@ private void InitCluster() }); Cluster.Get(_sys3).Join(Cluster.Get(_sys1).SelfAddress); - Within(10.Seconds(), () => + await WithinAsync(10.Seconds(), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { Cluster.Get(_sys1).State.Members.Count.Should().Be(3); Cluster.Get(_sys1).State.Members.All(x => x.Status == MemberStatus.Up).Should().BeTrue(); @@ -155,59 +155,59 @@ private void InitCluster() }); }); - PingEntities(); + await PingEntities(); } - private void RunCoordinatedShutdownWhenLeaving() + private async Task RunCoordinatedShutdownWhenLeaving() { Cluster.Get(_sys3).Leave(Cluster.Get(_sys1).SelfAddress); _probe1.ExpectMsg("CS-unbind-1"); - Within(20.Seconds(), () => + await WithinAsync(20.Seconds(), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { Cluster.Get(_sys2).State.Members.Count.Should().Be(2); Cluster.Get(_sys3).State.Members.Count.Should().Be(2); }); }); - Within(10.Seconds(), () => + await WithinAsync(10.Seconds(), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { Cluster.Get(_sys1).IsTerminated.Should().BeTrue(); _sys1.WhenTerminated.IsCompleted.Should().BeTrue(); }); }); - PingEntities(); + await PingEntities(); } - private void RunCoordinatedShutdownWhenDowning() + private async Task RunCoordinatedShutdownWhenDowning() { // coordinator is on Sys2 Cluster.Get(_sys2).Down(Cluster.Get(_sys3).SelfAddress); _probe3.ExpectMsg("CS-unbind-3"); - Within(20.Seconds(), () => + await WithinAsync(20.Seconds(), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { Cluster.Get(_sys2).State.Members.Count.Should().Be(1); }); }); - Within(10.Seconds(), () => + await WithinAsync(10.Seconds(), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { Cluster.Get(_sys3).IsTerminated.Should().BeTrue(); _sys3.WhenTerminated.IsCompleted.Should().BeTrue(); }); }); - PingEntities(); + await PingEntities(); } } } diff --git a/src/contrib/cluster/Akka.Cluster.Sharding.Tests/PersistentShardSpec.cs b/src/contrib/cluster/Akka.Cluster.Sharding.Tests/PersistentShardSpec.cs index b6b3082f7e1..6ba8d325ec5 100644 --- a/src/contrib/cluster/Akka.Cluster.Sharding.Tests/PersistentShardSpec.cs +++ b/src/contrib/cluster/Akka.Cluster.Sharding.Tests/PersistentShardSpec.cs @@ -53,7 +53,7 @@ public PersistentShardSpec(ITestOutputHelper helper) : base(SpecConfig, helper) } [Fact] - public void Persistent_Shard_must_remember_entities_started_with_StartEntity() + public async Task Persistent_Shard_must_remember_entities_started_with_StartEntity() { Func ep = id => Props.Create(() => new EntityActor(id)); @@ -82,7 +82,7 @@ public void Persistent_Shard_must_remember_entities_started_with_StartEntity() var secondIncarnation = Sys.ActorOf(props); secondIncarnation.Tell(Shard.GetShardStats.Instance); - AwaitAssert(() => + await AwaitAssertAsync(() => { ExpectMsgAllOf(new Shard.ShardStats("shard-1", 1)); }); diff --git a/src/contrib/cluster/Akka.Cluster.Tools.Tests/Singleton/ClusterSingletonLeavingSpeedSpec.cs b/src/contrib/cluster/Akka.Cluster.Tools.Tests/Singleton/ClusterSingletonLeavingSpeedSpec.cs index 8b45e3ab3e3..f4a2fb7753c 100644 --- a/src/contrib/cluster/Akka.Cluster.Tools.Tests/Singleton/ClusterSingletonLeavingSpeedSpec.cs +++ b/src/contrib/cluster/Akka.Cluster.Tools.Tests/Singleton/ClusterSingletonLeavingSpeedSpec.cs @@ -10,6 +10,7 @@ using System.Collections.Immutable; using System.Diagnostics; using System.Linq; +using System.Threading.Tasks; using Akka.Actor; using Akka.Cluster.Tools.Singleton; using Akka.Configuration; @@ -72,7 +73,7 @@ public ClusterSingletonLeavingSpeedSpec() : base(@" _probes = _systems.Select(i => CreateTestProbe()).ToArray(); } - public void Join(ActorSystem from, ActorSystem to, IActorRef probe) + public async Task JoinAsync(ActorSystem from, ActorSystem to, IActorRef probe) { from.ActorOf(ClusterSingletonManager.Props( TheSingleton.props(probe), @@ -81,9 +82,9 @@ public void Join(ActorSystem from, ActorSystem to, IActorRef probe) Cluster.Get(from).Join(Cluster.Get(to).SelfAddress); - Within(TimeSpan.FromSeconds(15), () => + await WithinAsync(TimeSpan.FromSeconds(15), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { Cluster.Get(from).State.Members.Select(x => x.UniqueAddress).Should().Contain(Cluster.Get(from).SelfUniqueAddress); Cluster.Get(from) @@ -96,24 +97,24 @@ public void Join(ActorSystem from, ActorSystem to, IActorRef probe) } [Fact] - public void ClusterSingleton_that_is_leaving_must() + public async Task ClusterSingleton_that_is_leaving_must() { - ClusterSingleton_that_is_leaving_must_join_cluster(); - ClusterSingleton_that_is_leaving_must_quickly_hand_over_to_next_oldest(); + await ClusterSingleton_that_is_leaving_must_join_cluster(); + await ClusterSingleton_that_is_leaving_must_quickly_hand_over_to_next_oldest(); } - private void ClusterSingleton_that_is_leaving_must_join_cluster() + private async Task ClusterSingleton_that_is_leaving_must_join_cluster() { for (int i = 0; i < _systems.Length; i++) - Join(_systems[i], _systems[0], _probes[i]); + await JoinAsync(_systems[i], _systems[0], _probes[i]); // leader is most likely on system, lowest port - Join(Sys, _systems[0], TestActor); + await JoinAsync(Sys, _systems[0], TestActor); _probes[0].ExpectMsg("started"); } - private void ClusterSingleton_that_is_leaving_must_quickly_hand_over_to_next_oldest() + private async Task ClusterSingleton_that_is_leaving_must_quickly_hand_over_to_next_oldest() { List<(TimeSpan, TimeSpan)> durations = new List<(TimeSpan, TimeSpan)>(); Stopwatch sw = new Stopwatch(); @@ -132,9 +133,9 @@ private void ClusterSingleton_that_is_leaving_must_quickly_hand_over_to_next_old var startedDuration = sw.Elapsed; - Within(TimeSpan.FromSeconds(15), () => + await WithinAsync(TimeSpan.FromSeconds(15), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { Cluster.Get(_systems[i]).IsTerminated.Should().BeTrue(); Cluster.Get(Sys).State.Members.Select(m => m.Address).Should().NotContain(leaveAddress); diff --git a/src/contrib/cluster/Akka.Cluster.Tools.Tests/Singleton/ClusterSingletonRestart2Spec.cs b/src/contrib/cluster/Akka.Cluster.Tools.Tests/Singleton/ClusterSingletonRestart2Spec.cs index 6b8c3727b10..a7cf5125c07 100644 --- a/src/contrib/cluster/Akka.Cluster.Tools.Tests/Singleton/ClusterSingletonRestart2Spec.cs +++ b/src/contrib/cluster/Akka.Cluster.Tools.Tests/Singleton/ClusterSingletonRestart2Spec.cs @@ -44,7 +44,7 @@ public ClusterSingletonRestart2Spec() : base(@" .WithFallback(Sys.Settings.Config)); } - public void Join(ActorSystem from, ActorSystem to) + public async Task JoinAsync(ActorSystem from, ActorSystem to) { if (Cluster.Get(from).SelfRoles.Contains("singleton")) { @@ -54,9 +54,9 @@ public void Join(ActorSystem from, ActorSystem to) } - Within(TimeSpan.FromSeconds(45), () => + await WithinAsync(TimeSpan.FromSeconds(45), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { Cluster.Get(from).Join(Cluster.Get(to).SelfAddress); Cluster.Get(from).State.Members.Select(x => x.UniqueAddress).Should().Contain(Cluster.Get(from).SelfUniqueAddress); @@ -70,18 +70,18 @@ public void Join(ActorSystem from, ActorSystem to) } [Fact] - public void Restarting_cluster_node_during_hand_over_must_restart_singletons_in_restarted_node() + public async Task Restarting_cluster_node_during_hand_over_must_restart_singletons_in_restarted_node() { - Join(_sys1, _sys1); - Join(_sys2, _sys1); - Join(_sys3, _sys1); + await JoinAsync(_sys1, _sys1); + await JoinAsync(_sys2, _sys1); + await JoinAsync(_sys3, _sys1); var proxy3 = _sys3.ActorOf( ClusterSingletonProxy.Props("user/echo", ClusterSingletonProxySettings.Create(_sys3).WithRole("singleton")), "proxy3"); - Within(TimeSpan.FromSeconds(5), () => + await WithinAsync(TimeSpan.FromSeconds(5), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { var probe = CreateTestProbe(_sys3); proxy3.Tell("hello", probe.Ref); @@ -104,14 +104,14 @@ public void Restarting_cluster_node_during_hand_over_must_restart_singletons_in_ .WithFallback(_sys1.Settings.Config); _sys4 = ActorSystem.Create(_sys1.Name, sys4Config); - Join(_sys4, _sys3); + await JoinAsync(_sys4, _sys3); // let it stabilize Task.Delay(TimeSpan.FromSeconds(5)).Wait(); - Within(TimeSpan.FromSeconds(10), () => + await WithinAsync(TimeSpan.FromSeconds(10), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { var probe = CreateTestProbe(_sys3); proxy3.Tell("hello2", probe.Ref); diff --git a/src/contrib/cluster/Akka.Cluster.Tools.Tests/Singleton/ClusterSingletonRestartSpec.cs b/src/contrib/cluster/Akka.Cluster.Tools.Tests/Singleton/ClusterSingletonRestartSpec.cs index 80cdace2d6a..cb91bacac47 100644 --- a/src/contrib/cluster/Akka.Cluster.Tools.Tests/Singleton/ClusterSingletonRestartSpec.cs +++ b/src/contrib/cluster/Akka.Cluster.Tools.Tests/Singleton/ClusterSingletonRestartSpec.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Immutable; using System.Linq; +using System.Threading.Tasks; using Akka.Actor; using Akka.Cluster.Tools.Singleton; using Akka.Configuration; @@ -39,15 +40,15 @@ public ClusterSingletonRestartSpec() : base(@" _sys2 = ActorSystem.Create(Sys.Name, Sys.Settings.Config); } - public void Join(ActorSystem from, ActorSystem to) + public async Task JoinAsync(ActorSystem from, ActorSystem to) { from.ActorOf(ClusterSingletonManager.Props(Echo.Props, PoisonPill.Instance, ClusterSingletonManagerSettings.Create(from)), "echo"); - Within(TimeSpan.FromSeconds(10), () => + await WithinAsync(TimeSpan.FromSeconds(10), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { Cluster.Get(from).Join(Cluster.Get(to).SelfAddress); Cluster.Get(from).State.Members.Select(x => x.UniqueAddress).Should().Contain(Cluster.Get(from).SelfUniqueAddress); @@ -61,17 +62,17 @@ public void Join(ActorSystem from, ActorSystem to) } [Fact] - public void Restarting_cluster_node_with_same_hostname_and_port_must_handover_to_next_oldest() + public async Task Restarting_cluster_node_with_same_hostname_and_port_must_handover_to_next_oldest() { - Join(_sys1, _sys1); - Join(_sys2, _sys1); + await JoinAsync(_sys1, _sys1); + await JoinAsync(_sys2, _sys1); var proxy2 = _sys2.ActorOf( ClusterSingletonProxy.Props("user/echo", ClusterSingletonProxySettings.Create(_sys2)), "proxy2"); - Within(TimeSpan.FromSeconds(5), () => + await WithinAsync(TimeSpan.FromSeconds(5), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { var probe = CreateTestProbe(_sys2); proxy2.Tell("hello", probe.Ref); @@ -88,11 +89,11 @@ public void Restarting_cluster_node_with_same_hostname_and_port_must_handover_to .WithFallback(_sys1.Settings.Config); _sys3 = ActorSystem.Create(_sys1.Name, sys3Config); - Join(_sys3, _sys2); + await JoinAsync(_sys3, _sys2); - Within(TimeSpan.FromSeconds(5), () => + await WithinAsync(TimeSpan.FromSeconds(5), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { var probe = CreateTestProbe(_sys2); proxy2.Tell("hello2", probe.Ref); @@ -102,9 +103,9 @@ public void Restarting_cluster_node_with_same_hostname_and_port_must_handover_to Cluster.Get(_sys2).Leave(Cluster.Get(_sys2).SelfAddress); - Within(TimeSpan.FromSeconds(15), () => + await WithinAsync(TimeSpan.FromSeconds(15), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { Cluster.Get(_sys3) .State.Members.Select(x => x.UniqueAddress) @@ -117,9 +118,9 @@ public void Restarting_cluster_node_with_same_hostname_and_port_must_handover_to _sys3.ActorOf(ClusterSingletonProxy.Props("user/echo", ClusterSingletonProxySettings.Create(_sys3)), "proxy3"); - Within(TimeSpan.FromSeconds(5), () => + await WithinAsync(TimeSpan.FromSeconds(5), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { var probe = CreateTestProbe(_sys3); proxy3.Tell("hello3", probe.Ref); diff --git a/src/contrib/cluster/Akka.DistributedData.Tests/LocalConcurrencySpec.cs b/src/contrib/cluster/Akka.DistributedData.Tests/LocalConcurrencySpec.cs index 37d4ef5a3ed..0a3758a68c8 100644 --- a/src/contrib/cluster/Akka.DistributedData.Tests/LocalConcurrencySpec.cs +++ b/src/contrib/cluster/Akka.DistributedData.Tests/LocalConcurrencySpec.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System.Collections.Immutable; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Xunit; @@ -46,7 +47,7 @@ public LocalConcurrencySpec(ITestOutputHelper output) } [Fact] - public void Updates_from_same_node_should_be_possible_to_do_from_two_actors() + public async Task Updates_from_same_node_should_be_possible_to_do_from_two_actors() { var updater1 = ActorOf(Props.Create(), "updater1"); var updater2 = ActorOf(Props.Create(), "updater2"); @@ -64,7 +65,7 @@ public void Updates_from_same_node_should_be_possible_to_do_from_two_actors() } var expected = b.ToImmutable(); - AwaitAssert(() => + await AwaitAssertAsync(() => { _replicator.Tell(Dsl.Get(Updater.Key, ReadLocal.Instance)); var msg = ExpectMsg(); diff --git a/src/contrib/dependencyinjection/Akka.DI.TestKit/DiResolverSpec.cs b/src/contrib/dependencyinjection/Akka.DI.TestKit/DiResolverSpec.cs index 0af0c185ed2..4c43caf247c 100644 --- a/src/contrib/dependencyinjection/Akka.DI.TestKit/DiResolverSpec.cs +++ b/src/contrib/dependencyinjection/Akka.DI.TestKit/DiResolverSpec.cs @@ -331,61 +331,61 @@ public void DependencyResolver_should_inject_instances_into_DiChildActor() } [Fact] - public void DependencyResolver_should_inject_into_normal_mailbox_Actor() + public async Task DependencyResolver_should_inject_into_normal_mailbox_Actor() { var stashActorProps = Sys.DI().Props(); var stashActor = Sys.ActorOf(stashActorProps); var internalRef = (RepointableActorRef)stashActor; - AwaitCondition(() => internalRef.IsStarted); + await AwaitConditionAsync(() => internalRef.IsStarted); Assert.IsType(internalRef.Underlying.AsInstanceOf().Mailbox.MessageQueue); } [Fact] - public void DependencyResolver_should_inject_into_UnboundedStash_Actor() + public async Task DependencyResolver_should_inject_into_UnboundedStash_Actor() { var stashActorProps = Sys.DI().Props(); var stashActor = Sys.ActorOf(stashActorProps); var internalRef = (RepointableActorRef)stashActor; - AwaitCondition(() => internalRef.IsStarted); + await AwaitConditionAsync(() => internalRef.IsStarted); Assert.IsType(internalRef.Underlying.AsInstanceOf().Mailbox.MessageQueue); } [Fact] - public void DependencyResolver_should_inject_into_BoundedStash_Actor() + public async Task DependencyResolver_should_inject_into_BoundedStash_Actor() { var stashActorProps = Sys.DI().Props(); var stashActor = Sys.ActorOf(stashActorProps); var internalRef = (RepointableActorRef)stashActor; - AwaitCondition(() => internalRef.IsStarted); + await AwaitConditionAsync(() => internalRef.IsStarted); Assert.IsType(internalRef.Underlying.AsInstanceOf().Mailbox.MessageQueue); } [Fact] - public void DependencyResolver_should_dispose_IDisposable_instances_on_Actor_Termination() + public async Task DependencyResolver_should_dispose_IDisposable_instances_on_Actor_Termination() { var disposableActorProps = Sys.DI().Props(); var disposableActor = Sys.ActorOf(disposableActorProps); var currentDisposeCounter = _disposeCounter.Current; Assert.True(disposableActor.GracefulStop(TimeSpan.FromSeconds(1)).Result); - AwaitAssert(() => Assert.True(currentDisposeCounter + 1 == _disposeCounter.Current), TimeSpan.FromSeconds(2), TimeSpan.FromMilliseconds(50)); + await AwaitAssertAsync(() => Assert.True(currentDisposeCounter + 1 == _disposeCounter.Current), TimeSpan.FromSeconds(2), TimeSpan.FromMilliseconds(50)); } [Fact] - public void DependencyResolver_should_dispose_IDisposable_instances_on_Actor_Restart() + public async Task DependencyResolver_should_dispose_IDisposable_instances_on_Actor_Restart() { var disposableActorProps = Sys.DI().Props(); var disposableActor = Sys.ActorOf(disposableActorProps); var currentDisposeCounter = _disposeCounter.Current; disposableActor.Tell(new DisposableActor.Restart()); - AwaitAssert(() => Assert.True(currentDisposeCounter + 1 == _disposeCounter.Current), TimeSpan.FromSeconds(2), TimeSpan.FromMilliseconds(50)); + await AwaitAssertAsync(() => Assert.True(currentDisposeCounter + 1 == _disposeCounter.Current), TimeSpan.FromSeconds(2), TimeSpan.FromMilliseconds(50)); } #endregion diff --git a/src/core/Akka.Cluster.TestKit/MultiNodeClusterSpec.cs b/src/core/Akka.Cluster.TestKit/MultiNodeClusterSpec.cs index b7b4fff671d..4f50414141d 100644 --- a/src/core/Akka.Cluster.TestKit/MultiNodeClusterSpec.cs +++ b/src/core/Akka.Cluster.TestKit/MultiNodeClusterSpec.cs @@ -11,6 +11,7 @@ using System.Collections.Immutable; using System.Linq; using System.Text.RegularExpressions; +using System.Threading.Tasks; using Akka.Actor; using Akka.Cluster.Tests.MultiNode; using Akka.Configuration; @@ -271,13 +272,13 @@ public void AwaitClusterUp(params RoleName[] roles) EnterBarrier(roles.Select(r => r.Name).Aggregate((a, b) => a + "-" + b) + "-joined"); } - public void JoinWithin(RoleName joinNode, TimeSpan? max = null, TimeSpan? interval = null) + public async Task JoinWithinAsync(RoleName joinNode, TimeSpan? max = null, TimeSpan? interval = null) { if (max == null) max = RemainingOrDefault; if (interval == null) interval = TimeSpan.FromSeconds(1); Cluster.Join(GetAddress(joinNode)); - AwaitCondition(() => + await AwaitConditionAsync(() => { ClusterView.RefreshCurrentState(); if (MemberInState(GetAddress(joinNode), new[] { MemberStatus.Up }) && @@ -287,7 +288,6 @@ public void JoinWithin(RoleName joinNode, TimeSpan? max = null, TimeSpan? interv Cluster.Join(GetAddress(joinNode)); return false; }, max, interval); - } private bool MemberInState(Address member, IEnumerable status) diff --git a/src/core/Akka.Cluster.Tests/ClusterSpec.cs b/src/core/Akka.Cluster.Tests/ClusterSpec.cs index 21fd1c99a85..434b2ce0552 100644 --- a/src/core/Akka.Cluster.Tests/ClusterSpec.cs +++ b/src/core/Akka.Cluster.Tests/ClusterSpec.cs @@ -66,16 +66,16 @@ public void A_cluster_must_use_the_address_of_the_remote_transport() } [Fact] - public void A_cluster_must_initially_become_singleton_cluster_when_joining_itself_and_reach_convergence() + public async Task A_cluster_must_initially_become_singleton_cluster_when_joining_itself_and_reach_convergence() { ClusterView.Members.Count.Should().Be(0); _cluster.Join(_selfAddress); LeaderActions(); // Joining -> Up - AwaitCondition(() => ClusterView.IsSingletonCluster); + await AwaitConditionAsync(() => ClusterView.IsSingletonCluster); ClusterView.Self.Address.Should().Be(_selfAddress); ClusterView.Members.Select(m => m.Address).ToImmutableHashSet() .Should().BeEquivalentTo(ImmutableHashSet.Create(_selfAddress)); - AwaitAssert(() => ClusterView.Status.Should().Be(MemberStatus.Up)); + await AwaitAssertAsync(() => ClusterView.Status.Should().Be(MemberStatus.Up)); } [Fact] @@ -167,7 +167,7 @@ public void BugFix_2442_RegisterOnMemberUp_should_fire_if_node_already_up() } [Fact] - public void A_cluster_must_complete_LeaveAsync_task_upon_being_removed() + public async Task A_cluster_must_complete_LeaveAsync_task_upon_being_removed() { var sys2 = ActorSystem.Create("ClusterSpec2", ConfigurationFactory.ParseString(@" akka.actor.provider = ""cluster"" @@ -192,14 +192,14 @@ public void A_cluster_must_complete_LeaveAsync_task_upon_being_removed() var removed = (ClusterEvent.MemberRemoved)probe.FishForMessage(m => m is ClusterEvent.MemberRemoved); removed.PreviousStatus.ShouldBeEquivalentTo(MemberStatus.Exiting); - AwaitCondition(() => leaveTask.IsCompleted); + await AwaitConditionAsync(() => leaveTask.IsCompleted); // A second call for LeaveAsync should complete immediately (should be the same task as before) Cluster.Get(sys2).LeaveAsync().IsCompleted.Should().BeTrue(); } [Fact] - public void A_cluster_must_return_completed_LeaveAsync_task_if_member_already_removed() + public async Task A_cluster_must_return_completed_LeaveAsync_task_if_member_already_removed() { // Join cluster _cluster.Join(_selfAddress); @@ -222,11 +222,11 @@ public void A_cluster_must_return_completed_LeaveAsync_task_if_member_already_re }); // LeaveAsync() task expected to complete immediately - AwaitCondition(() => _cluster.LeaveAsync().IsCompleted); + await AwaitConditionAsync(() => _cluster.LeaveAsync().IsCompleted); } [Fact] - public void A_cluster_must_cancel_LeaveAsync_task_if_CancellationToken_fired_before_node_left() + public async Task A_cluster_must_cancel_LeaveAsync_task_if_CancellationToken_fired_before_node_left() { // Join cluster _cluster.Join(_selfAddress); @@ -245,9 +245,9 @@ public void A_cluster_must_cancel_LeaveAsync_task_if_CancellationToken_fired_bef // Cancelling the first task cts.Cancel(); - AwaitCondition(() => task1.IsCanceled, null, "Task should be cancelled"); + await AwaitConditionAsync(() => task1.IsCanceled, null, "Task should be cancelled"); - Within(TimeSpan.FromSeconds(10), () => + await WithinAsync(TimeSpan.FromSeconds(10), async () => { // Second task should continue awaiting for cluster leave task2.IsCompleted.Should().BeFalse(); @@ -260,16 +260,16 @@ public void A_cluster_must_cancel_LeaveAsync_task_if_CancellationToken_fired_bef ExpectMsg().Member.Address.Should().Be(_selfAddress); // Second task should complete (not cancelled) - AwaitCondition(() => task2.IsCompleted && !task2.IsCanceled, null, "Task should be completed, but not cancelled."); + await AwaitConditionAsync(() => task2.IsCompleted && !task2.IsCanceled, null, "Task should be completed, but not cancelled."); }); // Subsequent LeaveAsync() tasks expected to complete immediately (not cancelled) var task3 = _cluster.LeaveAsync(); - AwaitCondition(() => task3.IsCompleted && !task3.IsCanceled, null, "Task should be completed, but not cancelled."); + await AwaitConditionAsync(() => task3.IsCompleted && !task3.IsCanceled, null, "Task should be completed, but not cancelled."); } [Fact] - public void A_cluster_must_be_allowed_to_join_and_leave_with_local_address() + public async Task A_cluster_must_be_allowed_to_join_and_leave_with_local_address() { var sys2 = ActorSystem.Create("ClusterSpec2", ConfigurationFactory.ParseString(@"akka.actor.provider = ""Akka.Cluster.ClusterActorRefProvider, Akka.Cluster"" akka.remote.dot-netty.tcp.port = 0")); @@ -278,9 +278,9 @@ public void A_cluster_must_be_allowed_to_join_and_leave_with_local_address() { var @ref = sys2.ActorOf(Props.Empty); Cluster.Get(sys2).Join(@ref.Path.Address); // address doesn't contain full address information - Within(5.Seconds(), () => + await WithinAsync(5.Seconds(), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { Cluster.Get(sys2).State.Members.Count.Should().Be(1); Cluster.Get(sys2).State.Members.First().Status.Should().Be(MemberStatus.Up); @@ -289,9 +289,9 @@ public void A_cluster_must_be_allowed_to_join_and_leave_with_local_address() Cluster.Get(sys2).Leave(@ref.Path.Address); - Within(5.Seconds(), () => + await WithinAsync(5.Seconds(), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { Cluster.Get(sys2).IsTerminated.Should().BeTrue(); }); @@ -489,7 +489,7 @@ public void A_cluster_must_leave_via_CoordinatedShutdownRun_when_member_status_i } [Fact] - public void A_cluster_must_terminate_ActorSystem_via_leave_CoordinatedShutdown() + public async Task A_cluster_must_terminate_ActorSystem_via_leave_CoordinatedShutdown() { var sys2 = ActorSystem.Create("ClusterSpec2", ConfigurationFactory.ParseString(@" akka.actor.provider = ""cluster"" @@ -511,7 +511,7 @@ public void A_cluster_must_terminate_ActorSystem_via_leave_CoordinatedShutdown() // MemberExited might not be published before MemberRemoved var removed = (ClusterEvent.MemberRemoved)probe.FishForMessage(m => m is ClusterEvent.MemberRemoved); removed.PreviousStatus.ShouldBeEquivalentTo(MemberStatus.Exiting); - AwaitCondition(() => sys2.WhenTerminated.IsCompleted, TimeSpan.FromSeconds(10)); + await AwaitConditionAsync(() => sys2.WhenTerminated.IsCompleted, TimeSpan.FromSeconds(10)); Cluster.Get(sys2).IsTerminated.Should().BeTrue(); CoordinatedShutdown.Get(sys2).ShutdownReason.Should().BeOfType(); } @@ -522,7 +522,7 @@ public void A_cluster_must_terminate_ActorSystem_via_leave_CoordinatedShutdown() } [Fact] - public void A_cluster_must_terminate_ActorSystem_via_Down_CoordinatedShutdown() + public async Task A_cluster_must_terminate_ActorSystem_via_Down_CoordinatedShutdown() { var sys3 = ActorSystem.Create("ClusterSpec3", ConfigurationFactory.ParseString(@" akka.actor.provider = ""cluster"" @@ -544,7 +544,7 @@ public void A_cluster_must_terminate_ActorSystem_via_Down_CoordinatedShutdown() probe.ExpectMsg(); probe.ExpectMsg(); - AwaitCondition(() => sys3.WhenTerminated.IsCompleted, TimeSpan.FromSeconds(10)); + await AwaitConditionAsync(() => sys3.WhenTerminated.IsCompleted, TimeSpan.FromSeconds(10)); Cluster.Get(sys3).IsTerminated.Should().BeTrue(); CoordinatedShutdown.Get(sys3).ShutdownReason.Should().BeOfType(); } diff --git a/src/core/Akka.Cluster.Tests/DowningProviderSpec.cs b/src/core/Akka.Cluster.Tests/DowningProviderSpec.cs index a9a8263c3d8..796874c1659 100644 --- a/src/core/Akka.Cluster.Tests/DowningProviderSpec.cs +++ b/src/core/Akka.Cluster.Tests/DowningProviderSpec.cs @@ -7,6 +7,7 @@ using System; using System.Threading; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.TestKit; @@ -87,7 +88,7 @@ public void Downing_provider_should_use_AutoDowning_if_auto_down_unreachable_aft } [Fact] - public void Downing_provider_should_use_specified_downing_provider() + public async Task Downing_provider_should_use_specified_downing_provider() { var config = ConfigurationFactory.ParseString( @"akka.cluster.downing-provider-class = ""Akka.Cluster.Tests.DummyDowningProvider, Akka.Cluster.Tests"""); @@ -95,14 +96,14 @@ public void Downing_provider_should_use_specified_downing_provider() { var downingProvider = Cluster.Get(system).DowningProvider; downingProvider.Should().BeOfType(); - AwaitCondition(() => + await AwaitConditionAsync(() => (downingProvider as DummyDowningProvider).ActorPropsAccessed.Value, TimeSpan.FromSeconds(3)); } } [Fact] - public void Downing_provider_should_stop_the_cluster_if_the_downing_provider_throws_exception_in_props() + public async Task Downing_provider_should_stop_the_cluster_if_the_downing_provider_throws_exception_in_props() { var config = ConfigurationFactory.ParseString( @"akka.cluster.downing-provider-class = ""Akka.Cluster.Tests.FailingDowningProvider, Akka.Cluster.Tests"""); @@ -112,7 +113,7 @@ public void Downing_provider_should_stop_the_cluster_if_the_downing_provider_thr var cluster = Cluster.Get(system); cluster.Join(cluster.SelfAddress); - AwaitCondition(() => cluster.IsTerminated, TimeSpan.FromSeconds(3)); + await AwaitConditionAsync(() => cluster.IsTerminated, TimeSpan.FromSeconds(3)); Shutdown(system); } diff --git a/src/core/Akka.Cluster.Tests/ShutdownAfterJoinSeedNodesSpec.cs b/src/core/Akka.Cluster.Tests/ShutdownAfterJoinSeedNodesSpec.cs index e4461abfac1..230c6d9ef02 100644 --- a/src/core/Akka.Cluster.Tests/ShutdownAfterJoinSeedNodesSpec.cs +++ b/src/core/Akka.Cluster.Tests/ShutdownAfterJoinSeedNodesSpec.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Immutable; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.TestKit; @@ -46,7 +47,7 @@ protected override void AfterTermination() } [Fact] - public void Joining_seed_nodes_must_be_aborted_after_shutdown_after_unsuccessful_join_seed_nodes() + public async Task Joining_seed_nodes_must_be_aborted_after_shutdown_after_unsuccessful_join_seed_nodes() { var seedNodes = ImmutableList.Create( Cluster.Get(_seed1).SelfAddress, @@ -57,8 +58,8 @@ public void Joining_seed_nodes_must_be_aborted_after_shutdown_after_unsuccessful Cluster.Get(_seed2).JoinSeedNodes(seedNodes); Cluster.Get(_ordinary1).JoinSeedNodes(seedNodes); - AwaitCondition(() => _seed2.WhenTerminated.IsCompleted, Cluster.Get(_seed2).Settings.ShutdownAfterUnsuccessfulJoinSeedNodes + TimeSpan.FromSeconds(10)); - AwaitCondition(() => _ordinary1.WhenTerminated.IsCompleted, Cluster.Get(_ordinary1).Settings.ShutdownAfterUnsuccessfulJoinSeedNodes + TimeSpan.FromSeconds(10)); + await AwaitConditionAsync(() => _seed2.WhenTerminated.IsCompleted, Cluster.Get(_seed2).Settings.ShutdownAfterUnsuccessfulJoinSeedNodes + TimeSpan.FromSeconds(10)); + await AwaitConditionAsync(() => _ordinary1.WhenTerminated.IsCompleted, Cluster.Get(_ordinary1).Settings.ShutdownAfterUnsuccessfulJoinSeedNodes + TimeSpan.FromSeconds(10)); } } } diff --git a/src/core/Akka.Docs.Tests/Streams/KillSwitchDocTests.cs b/src/core/Akka.Docs.Tests/Streams/KillSwitchDocTests.cs index e1260dabcb2..8a68de38461 100644 --- a/src/core/Akka.Docs.Tests/Streams/KillSwitchDocTests.cs +++ b/src/core/Akka.Docs.Tests/Streams/KillSwitchDocTests.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Akka.Streams; using Akka.Streams.Dsl; using Akka.TestKit.Xunit2; @@ -24,7 +25,7 @@ private void DoSomethingElse() } [Fact] - public void Unique_kill_switch_must_control_graph_completion_with_shutdown() + public async Task Unique_kill_switch_must_control_graph_completion_with_shutdown() { #region unique-shutdown var countingSrc = Source.From(Enumerable.Range(1, int.MaxValue)).Delay(1.Seconds(), DelayOverflowStrategy.Backpressure); @@ -39,7 +40,7 @@ public void Unique_kill_switch_must_control_graph_completion_with_shutdown() killSwitch.Shutdown(); - AwaitCondition(() => last.IsCompleted); + await AwaitConditionAsync(() => last.IsCompleted); #endregion } @@ -64,7 +65,7 @@ public void Unique_kill_switch_must_control_graph_completion_with_abort() } [Fact] - public void Shared_kill_switch_must_control_graph_completion_with_shutdown() + public async Task Shared_kill_switch_must_control_graph_completion_with_shutdown() { #region shared-shutdown var countingSrc = Source.From(Enumerable.Range(1, int.MaxValue)).Delay(1.Seconds(), DelayOverflowStrategy.Backpressure); @@ -84,8 +85,8 @@ public void Shared_kill_switch_must_control_graph_completion_with_shutdown() sharedKillSwitch.Shutdown(); - AwaitCondition(() => last.IsCompleted); - AwaitCondition(() => delayedLast.IsCompleted); + await AwaitConditionAsync(() => last.IsCompleted); + await AwaitConditionAsync(() => delayedLast.IsCompleted); #endregion } diff --git a/src/core/Akka.Docs.Tests/Testkit/TestKitSampleTest.cs b/src/core/Akka.Docs.Tests/Testkit/TestKitSampleTest.cs index e2b7397dba2..6ffb64fa226 100644 --- a/src/core/Akka.Docs.Tests/Testkit/TestKitSampleTest.cs +++ b/src/core/Akka.Docs.Tests/Testkit/TestKitSampleTest.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Akka.Actor; using Akka.TestKit.Xunit2; using Xunit; @@ -31,7 +32,7 @@ public class TestKitSampleTest : TestKit private TimeSpan EpsilonValueForWithins => new TimeSpan(0, 0, 1); // https://github.com/akkadotnet/akka.net/issues/2130 [Fact] - public void Test() + public async Task Test() { var subject = this.Sys.ActorOf(); @@ -44,12 +45,12 @@ public void Test() ExpectMsg("done", TimeSpan.FromSeconds(1)); // the action needs to finish within 3 seconds - Within(TimeSpan.FromSeconds(3), () => { + await WithinAsync(TimeSpan.FromSeconds(3), async () => { subject.Tell("hello", this.TestActor); // This is a demo: would normally use expectMsgEquals(). // Wait time is bounded by 3-second deadline above. - AwaitCondition(() => probe.HasMessages); + await AwaitConditionAsync(() => probe.HasMessages); // response must have been enqueued to us before probe ExpectMsg("world", TimeSpan.FromSeconds(0)); diff --git a/src/core/Akka.Docs.Tutorials/Tutorial3/DeviceGroupSpec.cs b/src/core/Akka.Docs.Tutorials/Tutorial3/DeviceGroupSpec.cs index 88f330bd089..57047f08120 100644 --- a/src/core/Akka.Docs.Tutorials/Tutorial3/DeviceGroupSpec.cs +++ b/src/core/Akka.Docs.Tutorials/Tutorial3/DeviceGroupSpec.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Akka.Actor; using Akka.TestKit.Xunit2; using FluentAssertions; @@ -83,7 +84,7 @@ public void DeviceGroup_actor_must_be_able_to_list_active_devices() } [Fact] - public void DeviceGroup_actor_must_be_able_to_list_active_devices_after_one_shuts_down() + public async Task DeviceGroup_actor_must_be_able_to_list_active_devices_after_one_shuts_down() { var probe = CreateTestProbe(); var groupActor = Sys.ActorOf(DeviceGroup.Props("group")); @@ -106,7 +107,7 @@ public void DeviceGroup_actor_must_be_able_to_list_active_devices_after_one_shut // using awaitAssert to retry because it might take longer for the groupActor // to see the Terminated, that order is undefined - probe.AwaitAssert(() => + await probe.AwaitAssertAsync(() => { groupActor.Tell(new RequestDeviceList(requestId: 1), probe.Ref); probe.ExpectMsg(s => s.RequestId == 1 && s.Ids.Contains("device2")); diff --git a/src/core/Akka.Docs.Tutorials/Tutorial4/DeviceGroupSpec.cs b/src/core/Akka.Docs.Tutorials/Tutorial4/DeviceGroupSpec.cs index c661bea3a16..94f810cf037 100644 --- a/src/core/Akka.Docs.Tutorials/Tutorial4/DeviceGroupSpec.cs +++ b/src/core/Akka.Docs.Tutorials/Tutorial4/DeviceGroupSpec.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Akka.Actor; using Akka.TestKit.Xunit2; using Akka.Util.Internal; @@ -79,7 +80,7 @@ public void DeviceGroup_actor_must_be_able_to_list_active_devices() } [Fact] - public void DeviceGroup_actor_must_be_able_to_list_active_devices_after_one_shuts_down() + public async Task DeviceGroup_actor_must_be_able_to_list_active_devices_after_one_shuts_down() { var probe = CreateTestProbe(); var groupActor = Sys.ActorOf(DeviceGroup.Props("group")); @@ -102,7 +103,7 @@ public void DeviceGroup_actor_must_be_able_to_list_active_devices_after_one_shut // using awaitAssert to retry because it might take longer for the groupActor // to see the Terminated, that order is undefined - probe.AwaitAssert(() => + await probe.AwaitAssertAsync(() => { groupActor.Tell(new RequestDeviceList(requestId: 1), probe.Ref); probe.ExpectMsg(s => s.RequestId == 1 && s.Ids.Contains("device2")); diff --git a/src/core/Akka.Persistence.TCK/Query/CurrentEventsByPersistenceIdSpec.cs b/src/core/Akka.Persistence.TCK/Query/CurrentEventsByPersistenceIdSpec.cs index 090c1c5dd7c..e448df5151f 100644 --- a/src/core/Akka.Persistence.TCK/Query/CurrentEventsByPersistenceIdSpec.cs +++ b/src/core/Akka.Persistence.TCK/Query/CurrentEventsByPersistenceIdSpec.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.Persistence.Query; @@ -85,39 +86,39 @@ public virtual void ReadJournal_CurrentEventsByPersistenceId_should_not_see_new_ } [Fact] - public virtual void ReadJournal_CurrentEventsByPersistenceId_should_return_empty_stream_for_cleaned_journal_from_0_to_MaxLong() + public virtual async Task ReadJournal_CurrentEventsByPersistenceId_should_return_empty_stream_for_cleaned_journal_from_0_to_MaxLong() { var queries = ReadJournal.AsInstanceOf(); var pref = Setup("g1"); pref.Tell(new TestActor.DeleteCommand(3)); - AwaitAssert(() => ExpectMsg("3-deleted")); + await AwaitAssertAsync(() => ExpectMsg("3-deleted")); var src = queries.CurrentEventsByPersistenceId("g1", 0, long.MaxValue); src.Select(x => x.Event).RunWith(this.SinkProbe(), Materializer).Request(1).ExpectComplete(); } [Fact] - public virtual void ReadJournal_CurrentEventsByPersistenceId_should_return_empty_stream_for_cleaned_journal_from_0_to_0() + public virtual async Task ReadJournal_CurrentEventsByPersistenceId_should_return_empty_stream_for_cleaned_journal_from_0_to_0() { var queries = ReadJournal.AsInstanceOf(); var pref = Setup("g2"); pref.Tell(new TestActor.DeleteCommand(3)); - AwaitAssert(() => ExpectMsg("3-deleted")); + await AwaitAssertAsync(() => ExpectMsg("3-deleted")); var src = queries.CurrentEventsByPersistenceId("g2", 0, 0); src.Select(x => x.Event).RunWith(this.SinkProbe(), Materializer).Request(1).ExpectComplete(); } [Fact] - public virtual void ReadJournal_CurrentEventsByPersistenceId_should_return_remaining_values_after_partial_journal_cleanup() + public virtual async Task ReadJournal_CurrentEventsByPersistenceId_should_return_remaining_values_after_partial_journal_cleanup() { var queries = ReadJournal.AsInstanceOf(); var pref = Setup("h"); pref.Tell(new TestActor.DeleteCommand(2)); - AwaitAssert(() => ExpectMsg("2-deleted")); + await AwaitAssertAsync(() => ExpectMsg("2-deleted")); var src = queries.CurrentEventsByPersistenceId("h", 0L, long.MaxValue); src.Select(x => x.Event).RunWith(this.SinkProbe(), Materializer) diff --git a/src/core/Akka.Persistence.Tests/PersistentActorRecoveryTimeoutSpec.cs b/src/core/Akka.Persistence.Tests/PersistentActorRecoveryTimeoutSpec.cs index a9dbe3f319c..870551935de 100644 --- a/src/core/Akka.Persistence.Tests/PersistentActorRecoveryTimeoutSpec.cs +++ b/src/core/Akka.Persistence.Tests/PersistentActorRecoveryTimeoutSpec.cs @@ -100,7 +100,7 @@ public PersistentActorRecoveryTimeoutSpec() { // initialize journal early Persistence.Instance.Apply(Sys).JournalFor("akka.persistence.journal.stepping-inmem"); - AwaitAssert(() => SteppingMemoryJournal.GetRef(JournalId), TimeSpan.FromSeconds(3)); + AwaitAssertAsync(() => SteppingMemoryJournal.GetRef(JournalId), TimeSpan.FromSeconds(3)).Wait(); _journal = SteppingMemoryJournal.GetRef(JournalId); } diff --git a/src/core/Akka.Persistence.Tests/PersistentActorStashingSpec.cs b/src/core/Akka.Persistence.Tests/PersistentActorStashingSpec.cs index fd8e74ed803..1ffd8fd4236 100644 --- a/src/core/Akka.Persistence.Tests/PersistentActorStashingSpec.cs +++ b/src/core/Akka.Persistence.Tests/PersistentActorStashingSpec.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Threading.Tasks; using Akka.Actor; using Akka.Persistence.Tests.Journal; using Xunit; @@ -443,10 +444,10 @@ public SteppingMemoryPersistentActorStashingSpec() } [Fact] - public void Stashing_in_a_PersistentActor_mixed_with_PersistAsync_should_handle_async_callback_not_happening_until_next_message_has_been_stashed() + public async Task Stashing_in_a_PersistentActor_mixed_with_PersistAsync_should_handle_async_callback_not_happening_until_next_message_has_been_stashed() { var pref = Sys.ActorOf(Props.Create(() => new AsyncStashingActor(Name))); - AwaitAssert(() => SteppingMemoryJournal.GetRef("persistence-stash"), TimeSpan.FromSeconds(3)); + await AwaitAssertAsync(() => SteppingMemoryJournal.GetRef("persistence-stash"), TimeSpan.FromSeconds(3)); var journal = SteppingMemoryJournal.GetRef("persistence-stash"); // initial read highest @@ -463,9 +464,9 @@ public void Stashing_in_a_PersistentActor_mixed_with_PersistAsync_should_handle_ SteppingMemoryJournal.Step(journal); SteppingMemoryJournal.Step(journal); - Within(TimeSpan.FromSeconds(3), () => + await WithinAsync(TimeSpan.FromSeconds(3), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { pref.Tell(GetState.Instance); ExpectMsgInOrder("a", "c", "b"); @@ -474,10 +475,10 @@ public void Stashing_in_a_PersistentActor_mixed_with_PersistAsync_should_handle_ } [Fact] - public void Stashing_in_a_PersistentActor_mixed_with_PersistAsync_should_handle_async_callback_not_happening_until_next_message_has_been_stashed_within_handler() + public async Task Stashing_in_a_PersistentActor_mixed_with_PersistAsync_should_handle_async_callback_not_happening_until_next_message_has_been_stashed_within_handler() { var pref = Sys.ActorOf(Props.Create(() => new AsyncStashingWithinHandlerActor(Name))); - AwaitAssert(() => SteppingMemoryJournal.GetRef("persistence-stash"), TimeSpan.FromSeconds(3)); + await AwaitAssertAsync(() => SteppingMemoryJournal.GetRef("persistence-stash"), TimeSpan.FromSeconds(3)); var journal = SteppingMemoryJournal.GetRef("persistence-stash"); // initial read highest @@ -494,9 +495,9 @@ public void Stashing_in_a_PersistentActor_mixed_with_PersistAsync_should_handle_ SteppingMemoryJournal.Step(journal); SteppingMemoryJournal.Step(journal); - Within(TimeSpan.FromSeconds(3), () => + await WithinAsync(TimeSpan.FromSeconds(3), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { pref.Tell(GetState.Instance); ExpectMsgInOrder("a", "c", "b"); diff --git a/src/core/Akka.Remote.TestKit.Tests/ControllerSpec.cs b/src/core/Akka.Remote.TestKit.Tests/ControllerSpec.cs index 94c1e0f6a1b..e3e7cdb2619 100644 --- a/src/core/Akka.Remote.TestKit.Tests/ControllerSpec.cs +++ b/src/core/Akka.Remote.TestKit.Tests/ControllerSpec.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Net; +using System.Threading.Tasks; using Akka.Actor; using Akka.TestKit; using Xunit; @@ -32,7 +33,7 @@ public ControllerSpec() private readonly RoleName B = new RoleName("b"); [Fact] - public void Controller_must_publish_its_nodes() + public async Task Controller_must_publish_its_nodes() { var c = Sys.ActorOf(Props.Create(() => new Controller(1, new IPEndPoint(IPAddress.Loopback, 0)))); c.Tell(new Controller.NodeInfo(A, Address.Parse("akka://sys"), TestActor)); @@ -41,7 +42,7 @@ public void Controller_must_publish_its_nodes() ExpectMsg>(); c.Tell(Controller.GetNodes.Instance); ExpectMsg>(names => XAssert.Equivalent(names, new[] {A, B})); - AwaitAssert(() => + await AwaitAssertAsync(() => { Watch(c); c.Tell(PoisonPill.Instance); diff --git a/src/core/Akka.Remote.TestKit/MultiNodeSpec.cs b/src/core/Akka.Remote.TestKit/MultiNodeSpec.cs index c50ee59319b..8e797b4831b 100644 --- a/src/core/Akka.Remote.TestKit/MultiNodeSpec.cs +++ b/src/core/Akka.Remote.TestKit/MultiNodeSpec.cs @@ -15,7 +15,7 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Text; - +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.Configuration.Hocon; @@ -436,7 +436,10 @@ public void MultiNodeSpecAfterAll() { TestConductor.RemoveNode(_myself); Within(TestConductor.Settings.BarrierTimeout, () => - AwaitCondition(() => TestConductor.GetNodes().Result.All(n => n.Equals(_myself)))); + { + // Method is used in Dispose method, so have to make it synchronous + AwaitConditionAsync(() => TestConductor.GetNodes().Result.All(n => n.Equals(_myself))).Wait(); + }); } Shutdown(Sys); @@ -506,6 +509,16 @@ public void RunOn(Action thunk, params RoleName[] nodes) if (nodes.Length == 0) throw new ArgumentException("No node given to run on."); if (IsNode(nodes)) thunk(); } + + /// + /// Execute the given block of code only on the given nodes (names according + /// to the `roleMap`). + /// + public async Task RunOnAsync(Func thunkAsync, params RoleName[] nodes) + { + if (nodes.Length == 0) throw new ArgumentException("No node given to run on."); + if (IsNode(nodes)) await thunkAsync(); + } /// /// Verify that the running node matches one of the given nodes diff --git a/src/core/Akka.Remote.Tests.MultiNode/RemoteGatePiercingSpec.cs b/src/core/Akka.Remote.Tests.MultiNode/RemoteGatePiercingSpec.cs index 83969c39e30..ddfb52980d4 100644 --- a/src/core/Akka.Remote.Tests.MultiNode/RemoteGatePiercingSpec.cs +++ b/src/core/Akka.Remote.Tests.MultiNode/RemoteGatePiercingSpec.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.Remote.TestKit; @@ -73,7 +74,7 @@ protected RemoteGatePiercingSpec(RemoteGatePiercingMultiNetSpec config) : base(c protected override int InitialParticipantsValueFactory { get; } = 2; [MultiNodeFact] - public void RemoteGatePiercing_must_allow_restarted_node_to_pass_through_gate() + public async Task RemoteGatePiercing_must_allow_restarted_node_to_pass_through_gate() { Sys.ActorOf("subject"); EnterBarrier("actors-started"); @@ -96,15 +97,15 @@ public void RemoteGatePiercing_must_allow_restarted_node_to_pass_through_gate() EnterBarrier("gate-pierced"); }, _config.First); - RunOn(() => + await RunOnAsync(async () => { EnterBarrier("actors-communicate"); EnterBarrier("gated"); // Pierce the gate - Within(TimeSpan.FromSeconds(30), () => + await WithinAsync(TimeSpan.FromSeconds(30), async () => { - AwaitAssert(() => _identify(_config.First, "subject")); + await AwaitAssertAsync(() => _identify(_config.First, "subject")); }); EnterBarrier("gate-pierced"); diff --git a/src/core/Akka.Remote.Tests.MultiNode/RemoteNodeDeathWatchSpec.cs b/src/core/Akka.Remote.Tests.MultiNode/RemoteNodeDeathWatchSpec.cs index c3beeae7d84..c71567497fc 100644 --- a/src/core/Akka.Remote.Tests.MultiNode/RemoteNodeDeathWatchSpec.cs +++ b/src/core/Akka.Remote.Tests.MultiNode/RemoteNodeDeathWatchSpec.cs @@ -8,6 +8,7 @@ using System; using System.Linq; using System.Threading; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.Remote.TestKit; @@ -141,13 +142,13 @@ protected RemoteNodeDeathWatchSpec(RemoteNodeDeathWatchMultiNetSpec config, Type protected abstract Action Sleep { get; } - private void AssertCleanup(TimeSpan? timeout = null) + private async Task AssertCleanup(TimeSpan? timeout = null) { timeout = timeout ?? TimeSpan.FromSeconds(5); - Within(timeout.Value, () => + await WithinAsync(timeout.Value, async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { _remoteWatcher.Value.Tell(RemoteWatcher.Stats.Empty); ExpectMsg(s => Equals(s, RemoteWatcher.Stats.Empty)); @@ -156,20 +157,20 @@ private void AssertCleanup(TimeSpan? timeout = null) } [MultiNodeFact] - public void RemoteNodeDeathWatchSpecs() + public async Task RemoteNodeDeathWatchSpecs() { Console.WriteLine($"Executing with {Scenario} scenario"); - RemoteNodeDeathWatch_must_receive_Terminated_when_remote_actor_is_stopped(); - RemoteNodeDeathWatch_must_cleanup_after_watch_unwatch(); - RemoteNodeDeathWatch_must_cleanup_after_bi_directional_watch_unwatch(); - RemoteNodeDeathWatch_must_cleanup_after_bi_directional_watch_stop_unwatch(); - RemoteNodeDeathWatch_must_cleanup_after_stop(); - RemoteNodeDeathWatch_must_receive_Terminated_when_watched_node_crash(); - RemoteNodeDeathWatch_must_cleanup_when_watching_node_crash(); + await RemoteNodeDeathWatch_must_receive_Terminated_when_remote_actor_is_stopped(); + await RemoteNodeDeathWatch_must_cleanup_after_watch_unwatch(); + await RemoteNodeDeathWatch_must_cleanup_after_bi_directional_watch_unwatch(); + await RemoteNodeDeathWatch_must_cleanup_after_bi_directional_watch_stop_unwatch(); + await RemoteNodeDeathWatch_must_cleanup_after_stop(); + await RemoteNodeDeathWatch_must_receive_Terminated_when_watched_node_crash(); + await RemoteNodeDeathWatch_must_cleanup_when_watching_node_crash(); } - private void RemoteNodeDeathWatch_must_receive_Terminated_when_remote_actor_is_stopped() + private async Task RemoteNodeDeathWatch_must_receive_Terminated_when_remote_actor_is_stopped() { RunOn(() => { @@ -210,14 +211,14 @@ private void RemoteNodeDeathWatch_must_receive_Terminated_when_remote_actor_is_s EnterBarrier("terminated-verified-1"); // verify that things are cleaned up, and heartbeating is stopped - AssertCleanup(); + await AssertCleanup(); ExpectNoMsg(TimeSpan.FromSeconds(2)); - AssertCleanup(); + await AssertCleanup(); EnterBarrier("after-1"); } - private void RemoteNodeDeathWatch_must_cleanup_after_watch_unwatch() + private async Task RemoteNodeDeathWatch_must_cleanup_after_watch_unwatch() { RunOn(() => { @@ -246,14 +247,14 @@ private void RemoteNodeDeathWatch_must_cleanup_after_watch_unwatch() }, _config.Second, _config.Third); // verify that things are cleaned up, and heartbeating is stopped - AssertCleanup(); + await AssertCleanup(); ExpectNoMsg(TimeSpan.FromSeconds(2)); - AssertCleanup(); + await AssertCleanup(); EnterBarrier("after-2"); } - private void RemoteNodeDeathWatch_must_cleanup_after_bi_directional_watch_unwatch() + private async Task RemoteNodeDeathWatch_must_cleanup_after_bi_directional_watch_unwatch() { RunOn(() => { @@ -282,14 +283,14 @@ private void RemoteNodeDeathWatch_must_cleanup_after_bi_directional_watch_unwatc }, _config.Third); // verify that things are cleaned up, and heartbeating is stopped - AssertCleanup(); + await AssertCleanup(); ExpectNoMsg(TimeSpan.FromSeconds(2)); - AssertCleanup(); + await AssertCleanup(); EnterBarrier("after-3"); } - private void RemoteNodeDeathWatch_must_cleanup_after_bi_directional_watch_stop_unwatch() + private async Task RemoteNodeDeathWatch_must_cleanup_after_bi_directional_watch_stop_unwatch() { RunOn(() => { @@ -332,16 +333,16 @@ private void RemoteNodeDeathWatch_must_cleanup_after_bi_directional_watch_stop_u }, _config.Third); // verify that things are cleaned up, and heartbeating is stopped - AssertCleanup(); + await AssertCleanup(); ExpectNoMsg(TimeSpan.FromSeconds(2)); - AssertCleanup(); + await AssertCleanup(); EnterBarrier("after-4"); } - private void RemoteNodeDeathWatch_must_cleanup_after_stop() + private async Task RemoteNodeDeathWatch_must_cleanup_after_stop() { - RunOn(() => + await RunOnAsync(async () => { var p1 = CreateTestProbe(); var p2 = CreateTestProbe(); @@ -380,12 +381,12 @@ private void RemoteNodeDeathWatch_must_cleanup_after_stop() EnterBarrier("terminated-verified-5"); // verify that things are cleaned up, and heartbeating is stopped - AssertCleanup(); + await AssertCleanup(); ExpectNoMsg(TimeSpan.FromSeconds(2)); - AssertCleanup(); + await AssertCleanup(); }, _config.First); - RunOn(() => + await RunOnAsync(async () => { var p1 = CreateTestProbe(); var p2 = CreateTestProbe(); @@ -425,12 +426,12 @@ private void RemoteNodeDeathWatch_must_cleanup_after_stop() EnterBarrier("terminated-verified-5"); // verify that things are cleaned up, and heartbeating is stopped - AssertCleanup(); + await AssertCleanup(); ExpectNoMsg(TimeSpan.FromSeconds(2)); p1.ExpectNoMsg(100); p2.ExpectNoMsg(100); p3.ExpectNoMsg(100); - AssertCleanup(); + await AssertCleanup(); }, _config.Second); RunOn(() => @@ -444,9 +445,9 @@ private void RemoteNodeDeathWatch_must_cleanup_after_stop() EnterBarrier("after-5"); } - private void RemoteNodeDeathWatch_must_receive_Terminated_when_watched_node_crash() + private async Task RemoteNodeDeathWatch_must_receive_Terminated_when_watched_node_crash() { - RunOn(() => + await RunOnAsync(async () => { var watcher = Sys.ActorOf(Props.Create(() => new ProbeActor(TestActor)), "watcher6"); var watcher2 = Sys.ActorOf(Props.Create(() => new ProbeActor(Sys.DeadLetters))); @@ -473,9 +474,9 @@ private void RemoteNodeDeathWatch_must_receive_Terminated_when_watched_node_cras ExpectMsg(TimeSpan.FromSeconds(15)).T.ActorRef.ShouldBe(subject); // verify that things are cleaned up, and heartbeating is stopped - AssertCleanup(); + await AssertCleanup(); ExpectNoMsg(TimeSpan.FromSeconds(2)); - AssertCleanup(); + await AssertCleanup(); }, _config.First); RunOn(() => @@ -496,7 +497,7 @@ private void RemoteNodeDeathWatch_must_receive_Terminated_when_watched_node_cras EnterBarrier("after-6"); } - private void RemoteNodeDeathWatch_must_cleanup_when_watching_node_crash() + private async Task RemoteNodeDeathWatch_must_cleanup_when_watching_node_crash() { RunOn(() => { @@ -510,7 +511,7 @@ private void RemoteNodeDeathWatch_must_cleanup_when_watching_node_crash() EnterBarrier("watch-established-7"); }, _config.Third); - RunOn(() => + await RunOnAsync(async () => { Sys.ActorOf(Props.Create(() => new ProbeActor(TestActor)), "subject7"); EnterBarrier("actors-started-7"); @@ -524,9 +525,9 @@ private void RemoteNodeDeathWatch_must_cleanup_when_watching_node_crash() TestConductor.Exit(_config.Third, 0).Wait(); // verify that things are cleaned up, and heartbeating is stopped - AssertCleanup(TimeSpan.FromSeconds(20)); + await AssertCleanup(TimeSpan.FromSeconds(20)); ExpectNoMsg(TimeSpan.FromSeconds(2)); - AssertCleanup(); + await AssertCleanup(); }, _config.First); EnterBarrier("after-7"); diff --git a/src/core/Akka.Remote.Tests.MultiNode/RemoteNodeRestartDeathWatchSpec.cs b/src/core/Akka.Remote.Tests.MultiNode/RemoteNodeRestartDeathWatchSpec.cs index 75f530b3645..756ccb60784 100644 --- a/src/core/Akka.Remote.Tests.MultiNode/RemoteNodeRestartDeathWatchSpec.cs +++ b/src/core/Akka.Remote.Tests.MultiNode/RemoteNodeRestartDeathWatchSpec.cs @@ -7,6 +7,7 @@ using System; using System.Text; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.Remote.TestKit; @@ -46,10 +47,9 @@ protected IActorRef Identify(RoleName role, string actorName) [MultiNodeFact] - public void Must_receive_terminated_when_remote_actor_system_is_restarted() + public async Task Must_receive_terminated_when_remote_actor_system_is_restarted() { - - RunOn(() => + await RunOnAsync(async () => { var secondAddress = Node(_specConfig.Second).Address; EnterBarrier("actors-started"); @@ -66,10 +66,10 @@ public void Must_receive_terminated_when_remote_actor_system_is_restarted() .GetResult(); TestConductor.Shutdown(_specConfig.Second).GetAwaiter().GetResult(); ExpectTerminated(subject, TimeSpan.FromSeconds(15)); - Within(TimeSpan.FromSeconds(5), () => + await WithinAsync(TimeSpan.FromSeconds(5), async () => { // retry because the Subject actor might not be started yet - AwaitAssert(() => + await AwaitAssertAsync(() => { Sys.ActorSelection(new RootActorPath(secondAddress)/"user"/ "subject").Tell("shutdown"); diff --git a/src/core/Akka.Remote.Tests.MultiNode/RemoteNodeRestartGateSpec.cs b/src/core/Akka.Remote.Tests.MultiNode/RemoteNodeRestartGateSpec.cs index 131ce92159d..c47b0dd339f 100644 --- a/src/core/Akka.Remote.Tests.MultiNode/RemoteNodeRestartGateSpec.cs +++ b/src/core/Akka.Remote.Tests.MultiNode/RemoteNodeRestartGateSpec.cs @@ -8,6 +8,7 @@ using System; using System.Text; using System.Text.RegularExpressions; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.Remote.TestKit; @@ -48,12 +49,12 @@ private IActorRef Identify(RoleName role, string actorName) [MultiNodeFact] - public void RemoteNodeRestart_must_allow_restarted_node_to_pass_through_gate() + public async Task RemoteNodeRestart_must_allow_restarted_node_to_pass_through_gate() { Sys.ActorOf(Props.Create(() => new Subject()), "subject"); EnterBarrier("subject-started"); - RunOn(() => + await RunOnAsync(async () => { var secondAddress = Node(_specConfig.Second).Address; @@ -69,9 +70,9 @@ public void RemoteNodeRestart_must_allow_restarted_node_to_pass_through_gate() EnterBarrier("gated"); TestConductor.Shutdown(_specConfig.Second).Wait(); - Within(TimeSpan.FromSeconds(10), () => + await WithinAsync(TimeSpan.FromSeconds(10), async () => { - AwaitAssert( + await AwaitAssertAsync( () => { Sys.ActorSelection(new RootActorPath(secondAddress) / "user" / "subject") @@ -82,7 +83,7 @@ public void RemoteNodeRestart_must_allow_restarted_node_to_pass_through_gate() Sys.ActorSelection(new RootActorPath(secondAddress) / "user" / "subject").Tell("shutdown"); }, _specConfig.First); - RunOn(() => + await RunOnAsync(async () => { var addr = Sys.AsInstanceOf().Provider.DefaultAddress; var firstAddress = Node(_specConfig.First).Address; @@ -104,10 +105,9 @@ public void RemoteNodeRestart_must_allow_restarted_node_to_pass_through_gate() var probe = CreateTestProbe(freshSystem); // Pierce the gate - Within(TimeSpan.FromSeconds(30), () => + await WithinAsync(TimeSpan.FromSeconds(30), async () => { - AwaitAssert(() => - + await AwaitAssertAsync(() => { freshSystem.ActorSelection(new RootActorPath(firstAddress) / "user" / "subject") .Tell(new Identify("subject"), probe); diff --git a/src/core/Akka.Remote.Tests.MultiNode/RemoteNodeShutdownAndComesBackSpec.cs b/src/core/Akka.Remote.Tests.MultiNode/RemoteNodeShutdownAndComesBackSpec.cs index 9d1987e6527..6badc233861 100644 --- a/src/core/Akka.Remote.Tests.MultiNode/RemoteNodeShutdownAndComesBackSpec.cs +++ b/src/core/Akka.Remote.Tests.MultiNode/RemoteNodeShutdownAndComesBackSpec.cs @@ -8,6 +8,7 @@ using System; using System.Text; using System.Threading; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.Remote.TestKit; @@ -72,9 +73,9 @@ protected RemoteNodeShutdownAndComesBackSpec(RemoteNodeShutdownAndComesBackMulti protected override int InitialParticipantsValueFactory { get; } = 2; [MultiNodeFact] - public void RemoteNodeShutdownAndComesBack_must_properly_reset_system_message_buffer_state_when_new_system_with_same_Address_comes_up() + public async Task RemoteNodeShutdownAndComesBack_must_properly_reset_system_message_buffer_state_when_new_system_with_same_Address_comes_up() { - RunOn(() => + await RunOnAsync(async () => { var secondAddress = Node(_config.Second).Address; Sys.ActorOf("subject"); @@ -112,10 +113,10 @@ public void RemoteNodeShutdownAndComesBack_must_properly_reset_system_message_bu // the system message send state // Now wait until second system becomes alive again - Within(TimeSpan.FromSeconds(30), () => + await WithinAsync(TimeSpan.FromSeconds(30), async () => { // retry because the Subject actor might not be started yet - AwaitAssert(() => + await AwaitAssertAsync(() => { var p = CreateTestProbe(); Sys.ActorSelection(new RootActorPath(secondAddress) / "user" / "subject").Tell(new Identify("subject"), p.Ref); diff --git a/src/core/Akka.Remote.Tests.MultiNode/RemoteQuarantinePiercingSpec.cs b/src/core/Akka.Remote.Tests.MultiNode/RemoteQuarantinePiercingSpec.cs index 3bb32dbd59f..a15328d6dc9 100644 --- a/src/core/Akka.Remote.Tests.MultiNode/RemoteQuarantinePiercingSpec.cs +++ b/src/core/Akka.Remote.Tests.MultiNode/RemoteQuarantinePiercingSpec.cs @@ -7,6 +7,7 @@ using System; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.Remote.TestKit; @@ -66,14 +67,14 @@ protected RemoteQuarantinePiercingSpec(RemoteQuarantinePiercingSpecConfig specCo } [MultiNodeFact] - public void RemoteQuarantinePiercingSpecs() + public async Task RemoteQuarantinePiercingSpecs() { - RemoteNodeShutdownAndComesBack_must_allow_piercing_through_the_quarantine_when_remote_UID_is_new(); + await RemoteNodeShutdownAndComesBack_must_allow_piercing_through_the_quarantine_when_remote_UID_is_new(); } - private void RemoteNodeShutdownAndComesBack_must_allow_piercing_through_the_quarantine_when_remote_UID_is_new() + private async Task RemoteNodeShutdownAndComesBack_must_allow_piercing_through_the_quarantine_when_remote_UID_is_new() { - RunOn(() => + await RunOnAsync(async () => { var secondAddress = Node(_specConfig.Second).Address; EnterBarrier("actors-started"); @@ -95,10 +96,10 @@ private void RemoteNodeShutdownAndComesBack_must_allow_piercing_through_the_quar TestConductor.Shutdown(_specConfig.Second).Wait(TimeSpan.FromSeconds(30)); // Now wait until second system becomes alive again - Within(30.Seconds(), () => + await WithinAsync(30.Seconds(), async () => { // retry because the Subject actor might not be started yet - AwaitAssert(() => + await AwaitAssertAsync(() => { Sys.ActorSelection(new RootActorPath(secondAddress) / "user" / "subject").Tell("identify"); var tuple2 = ExpectMsg<(int, IActorRef)>(TimeSpan.FromSeconds(1)); diff --git a/src/core/Akka.Remote.Tests.MultiNode/RemoteReDeploymentSpec.cs b/src/core/Akka.Remote.Tests.MultiNode/RemoteReDeploymentSpec.cs index 596e6912072..5c34ede9218 100644 --- a/src/core/Akka.Remote.Tests.MultiNode/RemoteReDeploymentSpec.cs +++ b/src/core/Akka.Remote.Tests.MultiNode/RemoteReDeploymentSpec.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.Event; @@ -66,7 +67,7 @@ protected override int InitialParticipantsValueFactory } [MultiNodeFact] - public void RemoteReDeployment_must_terminate_the_child_when_its_parent_system_is_replaced_by_a_new_one() + public async Task RemoteReDeployment_must_terminate_the_child_when_its_parent_system_is_replaced_by_a_new_one() { var echo = Sys.ActorOf(EchoProps(TestActor), "echo"); EnterBarrier("echo-started"); @@ -87,7 +88,7 @@ public void RemoteReDeployment_must_terminate_the_child_when_its_parent_system_i EnterBarrier("first-deployed"); - RunOn(() => + await RunOnAsync(async () => { TestConductor.Blackhole(_config.Second, _config.First, ThrottleTransportAdapter.Direction.Both) .Wait(); @@ -106,7 +107,7 @@ public void RemoteReDeployment_must_terminate_the_child_when_its_parent_system_i { ExpectNoMsg(SleepAfterKill); } - AwaitAssert(() => Node(_config.Second), TimeSpan.FromSeconds(10), TimeSpan.FromMilliseconds(100)); + await AwaitAssertAsync(() => Node(_config.Second), TimeSpan.FromSeconds(10), TimeSpan.FromMilliseconds(100)); }, _config.First); ActorSystem tempSys = null; diff --git a/src/core/Akka.Remote.Tests.MultiNode/RemoteRestartedQuarantinedSpec.cs b/src/core/Akka.Remote.Tests.MultiNode/RemoteRestartedQuarantinedSpec.cs index 0dffd513d37..3190f5fb209 100644 --- a/src/core/Akka.Remote.Tests.MultiNode/RemoteRestartedQuarantinedSpec.cs +++ b/src/core/Akka.Remote.Tests.MultiNode/RemoteRestartedQuarantinedSpec.cs @@ -7,6 +7,7 @@ using System; using System.Text; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.Remote.TestKit; @@ -80,12 +81,12 @@ protected RemoteRestartedQuarantinedSpec(RemoteRestartedQuarantinedMultiNetSpec protected override int InitialParticipantsValueFactory { get; } = 2; [MultiNodeFact] - public void A_restarted_quarantined_system_should_not_crash_the_other_system() + public async Task A_restarted_quarantined_system_should_not_crash_the_other_system() { Sys.ActorOf("subject"); EnterBarrier("subject-started"); - RunOn(() => + await RunOnAsync(async () => { var secondAddress = Node(_config.Second).Address; var uid = _identifyWithUid(_config.Second, "subject").Item1; @@ -97,9 +98,9 @@ public void A_restarted_quarantined_system_should_not_crash_the_other_system() TestConductor.Shutdown(_config.Second).Wait(); - Within(TimeSpan.FromSeconds(30), () => + await WithinAsync(TimeSpan.FromSeconds(30), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { Sys.ActorSelection(new RootActorPath(secondAddress)/"user"/"subject") .Tell(new Identify("subject")); @@ -110,7 +111,7 @@ public void A_restarted_quarantined_system_should_not_crash_the_other_system() Sys.ActorSelection(new RootActorPath(secondAddress) / "user" / "subject").Tell("shutdown"); }, _config.First); - RunOn(() => + await RunOnAsync(async () => { var addr = ((ExtendedActorSystem) Sys).Provider.DefaultAddress; var firstAddress = Node(_config.First).Address; @@ -121,9 +122,9 @@ public void A_restarted_quarantined_system_should_not_crash_the_other_system() EnterBarrier("quarantined"); // Check that quarantine is intact - Within(TimeSpan.FromSeconds(30), () => + await WithinAsync(TimeSpan.FromSeconds(30), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { EventFilter.Warning(null, null, "The remote system has quarantined this system") .ExpectOne(10.Seconds(), () => actorRef.Tell("boo!")); diff --git a/src/core/Akka.Remote.Tests.MultiNode/TransportFailSpec.cs b/src/core/Akka.Remote.Tests.MultiNode/TransportFailSpec.cs index 25a0ccba41a..6f3929ac06e 100644 --- a/src/core/Akka.Remote.Tests.MultiNode/TransportFailSpec.cs +++ b/src/core/Akka.Remote.Tests.MultiNode/TransportFailSpec.cs @@ -94,7 +94,7 @@ private IActorRef Identify(RoleName role, string actorName) } [MultiNodeFact] - public void TransportFail_should_reconnect() + public async Task TransportFail_should_reconnect() { RunOn(() => { @@ -117,22 +117,22 @@ public void TransportFail_should_reconnect() TransportFailSpecConfig.FdAvailable.GetAndSet(false); // wait for ungated (also later awaitAssert retry) - Task.Delay(RARP.For(Sys).Provider.RemoteSettings.RetryGateClosedFor).Wait(); + await Task.Delay(RARP.For(Sys).Provider.RemoteSettings.RetryGateClosedFor); TransportFailSpecConfig.FdAvailable.GetAndSet(true); - RunOn(() => + await RunOnAsync(async () => { EnterBarrier("actors-started2"); var quarantineProbe = CreateTestProbe(); Sys.EventStream.Subscribe(quarantineProbe.Ref, typeof(QuarantinedEvent)); IActorRef subject2 = null; - AwaitAssert(() => + await AwaitAssertAsync(async () => { // TODO: harden - Within(TimeSpan.FromSeconds(3), () => + await WithinAsync(TimeSpan.FromSeconds(3), async () => { - AwaitCondition(() => + await AwaitConditionAsync(() => { subject2 = Identify(_config.Second, "subject2"); return subject2 != null; diff --git a/src/core/Akka.Remote.Tests/ActorsLeakSpec.cs b/src/core/Akka.Remote.Tests/ActorsLeakSpec.cs index 044919cd7b9..c39f0c3df5b 100644 --- a/src/core/Akka.Remote.Tests/ActorsLeakSpec.cs +++ b/src/core/Akka.Remote.Tests/ActorsLeakSpec.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; +using System.Threading.Tasks; using Akka.Actor; using Akka.Actor.Internal; using Akka.Configuration; @@ -86,7 +87,7 @@ private void AssertActors(ImmutableHashSet expected, ImmutableHashSet } [Fact] - public void Remoting_must_not_leak_actors() + public async Task Remoting_must_not_leak_actors() { var actorRef = Sys.ActorOf(EchoActor.Props(this, true), "echo"); var echoPath = new RootActorPath(RARP.For(Sys).Provider.DefaultAddress)/"user"/"echo"; @@ -231,7 +232,7 @@ public void Remoting_must_not_leak_actors() */ EventFilter.Exception().ExpectOne(() => { }); - AwaitAssert(() => + await AwaitAssertAsync(() => { AssertActors(initialActors, targets.SelectMany(CollectLiveActors).ToImmutableHashSet()); }, 10.Seconds()); diff --git a/src/core/Akka.Remote.Tests/RemoteWatcherSpec.cs b/src/core/Akka.Remote.Tests/RemoteWatcherSpec.cs index 77e9b1cb306..97ee4f2d307 100644 --- a/src/core/Akka.Remote.Tests/RemoteWatcherSpec.cs +++ b/src/core/Akka.Remote.Tests/RemoteWatcherSpec.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System; +using System.Threading.Tasks; using Akka.Actor; using Akka.TestKit; using Akka.Util.Internal; @@ -270,7 +271,7 @@ public void A_RemoteWatcher_must_have_correct_interaction_when_watching() } [Fact] - public void A_RemoteWatcher_must_generate_address_terminated_when_missing_heartbeats() + public async Task A_RemoteWatcher_must_generate_address_terminated_when_missing_heartbeats() { var p = CreateTestProbe(); var q = CreateTestProbe(); @@ -293,9 +294,9 @@ public void A_RemoteWatcher_must_generate_address_terminated_when_missing_heartb ExpectMsg(); monitorA.Tell(_heartbeatRspB, monitorB); - Within(TimeSpan.FromSeconds(10), () => + await WithinAsync(TimeSpan.FromSeconds(10), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { monitorA.Tell(RemoteWatcher.HeartbeatTick.Instance, TestActor); ExpectMsg(); @@ -311,7 +312,7 @@ public void A_RemoteWatcher_must_generate_address_terminated_when_missing_heartb } [Fact] - public void A_RemoteWatcher_must_generate_address_terminated_when_missing_first_heartbeat() + public async Task A_RemoteWatcher_must_generate_address_terminated_when_missing_first_heartbeat() { var p = CreateTestProbe(); var q = CreateTestProbe(); @@ -332,9 +333,9 @@ public void A_RemoteWatcher_must_generate_address_terminated_when_missing_first_ ExpectMsg(); // no HeartbeatRsp sent - Within(TimeSpan.FromSeconds(20), () => + await WithinAsync(TimeSpan.FromSeconds(20), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { monitorA.Tell(RemoteWatcher.HeartbeatTick.Instance, TestActor); ExpectMsg(); @@ -351,8 +352,7 @@ public void A_RemoteWatcher_must_generate_address_terminated_when_missing_first_ } [Fact] - public void - A_RemoteWatcher_must_generate_address_terminated_for_new_watch_after_broken_connection_was_reestablished_and_broken_again() + public async Task A_RemoteWatcher_must_generate_address_terminated_for_new_watch_after_broken_connection_was_reestablished_and_broken_again() { var p = CreateTestProbe(); var q = CreateTestProbe(); @@ -375,9 +375,9 @@ public void ExpectMsg(); monitorA.Tell(_heartbeatRspB, monitorB); - Within(TimeSpan.FromSeconds(10), () => + await WithinAsync(TimeSpan.FromSeconds(10), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { monitorA.Tell(RemoteWatcher.HeartbeatTick.Instance, TestActor); ExpectMsg(); @@ -391,7 +391,7 @@ public void //real AddressTerminated would trigger Terminated for b6, simulate that here _remoteSystem.Stop(b); - AwaitAssert(() => + await AwaitAssertAsync(() => { monitorA.Tell(RemoteWatcher.Stats.Empty, TestActor); ExpectMsg(RemoteWatcher.Stats.Empty); @@ -423,9 +423,9 @@ public void q.ExpectNoMsg(TimeSpan.FromSeconds(1)); //then stop heartbeating again; should generate a new AddressTerminated - Within(TimeSpan.FromSeconds(10), () => + await WithinAsync(TimeSpan.FromSeconds(10), async () => { - AwaitAssert(() => + await AwaitAssertAsync(() => { monitorA.Tell(RemoteWatcher.HeartbeatTick.Instance, TestActor); ExpectMsg(); diff --git a/src/core/Akka.Remote.Tests/RemotingSpec.cs b/src/core/Akka.Remote.Tests/RemotingSpec.cs index 5e7240067ce..443a6c5298f 100644 --- a/src/core/Akka.Remote.Tests/RemotingSpec.cs +++ b/src/core/Akka.Remote.Tests/RemotingSpec.cs @@ -463,7 +463,7 @@ public async Task Bug_884_Remoting_must_support_reply_to_child_of_Routee() } [Fact] - public void Stash_inbound_connections_until_UID_is_known_for_pending_outbound() + public async Task Stash_inbound_connections_until_UID_is_known_for_pending_outbound() { var localAddress = new Address("akka.test", "system1", "localhost", 1); var rawLocalAddress = new Address("test", "system1", "localhost", 1); @@ -495,7 +495,7 @@ public void Stash_inbound_connections_until_UID_is_known_for_pending_outbound() (new ActorAssociationEventListener(remoteTransportProbe))); // Hijack associations through the test transport - AwaitCondition(() => registry.TransportsReady(rawLocalAddress, rawRemoteAddress)); + await AwaitConditionAsync(() => registry.TransportsReady(rawLocalAddress, rawRemoteAddress)); var testTransport = registry.TransportFor(rawLocalAddress).Value.Item1; testTransport.WriteBehavior.PushConstant(true); @@ -514,7 +514,7 @@ public void Stash_inbound_connections_until_UID_is_known_for_pending_outbound() var inboundHandle = inboundHandleTask.Result; inboundHandle.ReadHandlerSource.SetResult(new ActorHandleEventListener(inboundHandleProbe)); - AwaitAssert(() => + await AwaitAssertAsync(() => { registry.GetRemoteReadHandlerFor(inboundHandle.AsInstanceOf()).Should().NotBeNull(); }); @@ -545,7 +545,7 @@ public void Stash_inbound_connections_until_UID_is_known_for_pending_outbound() } [Fact] - public void Properly_quarantine_stashed_inbound_connections() + public async Task Properly_quarantine_stashed_inbound_connections() { var localAddress = new Address("akka.test", "system1", "localhost", 1); var rawLocalAddress = new Address("test", "system1", "localhost", 1); @@ -577,7 +577,7 @@ public void Properly_quarantine_stashed_inbound_connections() (new ActorAssociationEventListener(remoteTransportProbe))); // Hijack associations through the test transport - AwaitCondition(() => registry.TransportsReady(rawLocalAddress, rawRemoteAddress)); + await AwaitConditionAsync(() => registry.TransportsReady(rawLocalAddress, rawRemoteAddress)); var testTransport = registry.TransportFor(rawLocalAddress).Value.Item1; testTransport.WriteBehavior.PushConstant(true); @@ -596,7 +596,7 @@ public void Properly_quarantine_stashed_inbound_connections() var inboundHandle = inboundHandleTask.Result; inboundHandle.ReadHandlerSource.SetResult(new ActorHandleEventListener(inboundHandleProbe)); - AwaitAssert(() => + await AwaitAssertAsync(() => { registry.GetRemoteReadHandlerFor(inboundHandle.AsInstanceOf()).Should().NotBeNull(); }); @@ -628,10 +628,10 @@ public void Properly_quarantine_stashed_inbound_connections() } [Fact] - public void Drop_sent_messages_over_payload_size() + public async Task Drop_sent_messages_over_payload_size() { var oversized = ByteStringOfSize(MaxPayloadBytes + 1); - EventFilter.Exception(start: "Discarding oversized payload sent to ").ExpectOne(() => + await EventFilter.Exception(start: "Discarding oversized payload sent to ").ExpectOneAsync(() => { VerifySend(oversized, () => { @@ -641,9 +641,9 @@ public void Drop_sent_messages_over_payload_size() } [Fact] - public void Drop_received_messages_over_payload_size() + public async Task Drop_received_messages_over_payload_size() { - EventFilter.Exception(start: "Discarding oversized payload received").ExpectOne(() => + await EventFilter.Exception(start: "Discarding oversized payload received").ExpectOneAsync(() => { VerifySend(MaxPayloadBytes + 1, () => { diff --git a/src/core/Akka.Remote.Tests/Transport/AkkaProtocolSpec.cs b/src/core/Akka.Remote.Tests/Transport/AkkaProtocolSpec.cs index 05bc9665aa3..a4a89999ba0 100644 --- a/src/core/Akka.Remote.Tests/Transport/AkkaProtocolSpec.cs +++ b/src/core/Akka.Remote.Tests/Transport/AkkaProtocolSpec.cs @@ -135,18 +135,18 @@ public override void HeartBeat() #region Tests [Fact] - public void ProtocolStateActor_must_register_itself_as_reader_on_injected_handles() + public async Task ProtocolStateActor_must_register_itself_as_reader_on_injected_handles() { var collaborators = GetCollaborators(); Sys.ActorOf(ProtocolStateActor.InboundProps(new HandshakeInfo(_localAddress, 42), collaborators.Handle, new ActorAssociationEventListener(TestActor), new AkkaProtocolSettings(config), codec, collaborators.FailureDetector)); - AwaitCondition(() => collaborators.Handle.ReadHandlerSource.Task.IsCompleted, DefaultTimeout); + await AwaitConditionAsync(() => collaborators.Handle.ReadHandlerSource.Task.IsCompleted, DefaultTimeout); } [Fact] - public void ProtocolStateActor_must_in_inbound_mode_accept_payload_after_Associate_PDU_received() + public async Task ProtocolStateActor_must_in_inbound_mode_accept_payload_after_Associate_PDU_received() { var collaborators = GetCollaborators(); var reader = @@ -156,7 +156,7 @@ public void ProtocolStateActor_must_in_inbound_mode_accept_payload_after_Associa reader.Tell(testAssociate(33), Self); - AwaitCondition(() => collaborators.FailureDetector.called, DefaultTimeout); + await AwaitConditionAsync(() => collaborators.FailureDetector.called, DefaultTimeout); var wrappedHandle = ExpectMsgPf(DefaultTimeout, "expected InboundAssociation", o => { @@ -172,7 +172,7 @@ public void ProtocolStateActor_must_in_inbound_mode_accept_payload_after_Associa Assert.True(collaborators.FailureDetector.called); // Heartbeat was sent in response to Associate - AwaitCondition(() => LastActivityIsHeartbeat(collaborators.Registry), DefaultTimeout); + await AwaitConditionAsync(() => LastActivityIsHeartbeat(collaborators.Registry), DefaultTimeout); reader.Tell(testPayload, Self); ExpectMsg(inbound => @@ -182,7 +182,7 @@ public void ProtocolStateActor_must_in_inbound_mode_accept_payload_after_Associa } [Fact] - public void ProtocolStateActor_must_in_inbound_mode_disassociate_when_an_unexpected_message_arrives_instead_of_Associate() + public async Task ProtocolStateActor_must_in_inbound_mode_disassociate_when_an_unexpected_message_arrives_instead_of_Associate() { var collaborators = GetCollaborators(); @@ -197,7 +197,7 @@ public void ProtocolStateActor_must_in_inbound_mode_disassociate_when_an_unexpec //this associate will now be ignored reader.Tell(testAssociate(33), Self); - AwaitCondition(() => + await AwaitConditionAsync(() => { var snapshots = collaborators.Registry.LogSnapshot(); return snapshots.Any(x => x is DisassociateAttempt); @@ -205,7 +205,7 @@ public void ProtocolStateActor_must_in_inbound_mode_disassociate_when_an_unexpec } [Fact] - public void ProtocolStateActor_must_in_outbound_mode_delay_readiness_until_handshake_finished() + public async Task ProtocolStateActor_must_in_outbound_mode_delay_readiness_until_handshake_finished() { var collaborators = GetCollaborators(); collaborators.Transport.AssociateBehavior.PushConstant(collaborators.Handle); @@ -216,11 +216,11 @@ public void ProtocolStateActor_must_in_outbound_mode_delay_readiness_until_hands statusPromise, collaborators.Transport, new AkkaProtocolSettings(config), codec, collaborators.FailureDetector)); - AwaitCondition(() => LastActivityIsAssociate(collaborators.Registry, 42), DefaultTimeout); + await AwaitConditionAsync(() => LastActivityIsAssociate(collaborators.Registry, 42), DefaultTimeout); Assert.True(collaborators.FailureDetector.called); //keeps sending heartbeats - AwaitCondition(() => LastActivityIsHeartbeat(collaborators.Registry), DefaultTimeout); + await AwaitConditionAsync(() => LastActivityIsHeartbeat(collaborators.Registry), DefaultTimeout); Assert.False(statusPromise.Task.IsCompleted); @@ -239,7 +239,7 @@ public void ProtocolStateActor_must_in_outbound_mode_delay_readiness_until_hands } [Fact] - public void ProtocolStateActor_must_handle_explicit_disassociate_messages() + public async Task ProtocolStateActor_must_handle_explicit_disassociate_messages() { var collaborators = GetCollaborators(); collaborators.Transport.AssociateBehavior.PushConstant(collaborators.Handle); @@ -250,7 +250,7 @@ public void ProtocolStateActor_must_handle_explicit_disassociate_messages() statusPromise, collaborators.Transport, new AkkaProtocolSettings(config), codec, collaborators.FailureDetector)); - AwaitCondition(() => LastActivityIsAssociate(collaborators.Registry, 42), DefaultTimeout); + await AwaitConditionAsync(() => LastActivityIsAssociate(collaborators.Registry, 42), DefaultTimeout); reader.Tell(testAssociate(33), Self); @@ -280,7 +280,7 @@ public void ProtocolStateActor_must_handle_explicit_disassociate_messages() } [Fact] - public void ProtocolStateActor_must_handle_transport_level_disassociations() + public async Task ProtocolStateActor_must_handle_transport_level_disassociations() { var collaborators = GetCollaborators(); collaborators.Transport.AssociateBehavior.PushConstant(collaborators.Handle); @@ -291,7 +291,7 @@ public void ProtocolStateActor_must_handle_transport_level_disassociations() statusPromise, collaborators.Transport, new AkkaProtocolSettings(config), codec, collaborators.FailureDetector)); - AwaitCondition(() => LastActivityIsAssociate(collaborators.Registry, 42), DefaultTimeout); + await AwaitConditionAsync(() => LastActivityIsAssociate(collaborators.Registry, 42), DefaultTimeout); reader.Tell(testAssociate(33), Self); @@ -321,7 +321,7 @@ public void ProtocolStateActor_must_handle_transport_level_disassociations() } [Fact] - public void ProtocolStateActor_must_disassociate_when_failure_detector_signals_failure() + public async Task ProtocolStateActor_must_disassociate_when_failure_detector_signals_failure() { var collaborators = GetCollaborators(); collaborators.Transport.AssociateBehavior.PushConstant(collaborators.Handle); @@ -332,7 +332,7 @@ public void ProtocolStateActor_must_disassociate_when_failure_detector_signals_f statusPromise, collaborators.Transport, new AkkaProtocolSettings(config), codec, collaborators.FailureDetector)); - AwaitCondition(() => LastActivityIsAssociate(collaborators.Registry, 42), DefaultTimeout); + await AwaitConditionAsync(() => LastActivityIsAssociate(collaborators.Registry, 42), DefaultTimeout); stateActor.Tell(testAssociate(33), Self); @@ -349,7 +349,7 @@ public void ProtocolStateActor_must_disassociate_when_failure_detector_signals_f wrappedHandle.ReadHandlerSource.SetResult(new ActorHandleEventListener(TestActor)); //wait for one heartbeat - AwaitCondition(() => LastActivityIsHeartbeat(collaborators.Registry), DefaultTimeout); + await AwaitConditionAsync(() => LastActivityIsHeartbeat(collaborators.Registry), DefaultTimeout); collaborators.FailureDetector.isAvailable = false; @@ -365,7 +365,7 @@ public void ProtocolStateActor_must_disassociate_when_failure_detector_signals_f } [Fact] - public void ProtocolStateActor_must_handle_correctly_when_the_handler_is_registered_only_after_the_association_is_already_closed() + public async Task ProtocolStateActor_must_handle_correctly_when_the_handler_is_registered_only_after_the_association_is_already_closed() { var collaborators = GetCollaborators(); collaborators.Transport.AssociateBehavior.PushConstant(collaborators.Handle); @@ -376,7 +376,7 @@ public void ProtocolStateActor_must_handle_correctly_when_the_handler_is_registe statusPromise, collaborators.Transport, new AkkaProtocolSettings(config), codec, collaborators.FailureDetector)); - AwaitCondition(() => LastActivityIsAssociate(collaborators.Registry, 42), DefaultTimeout); + await AwaitConditionAsync(() => LastActivityIsAssociate(collaborators.Registry, 42), DefaultTimeout); stateActor.Tell(testAssociate(33), Self); diff --git a/src/core/Akka.Remote.Tests/Transport/AkkaProtocolStressTest.cs b/src/core/Akka.Remote.Tests/Transport/AkkaProtocolStressTest.cs index 79bcfcf9b88..766602bf270 100644 --- a/src/core/Akka.Remote.Tests/Transport/AkkaProtocolStressTest.cs +++ b/src/core/Akka.Remote.Tests/Transport/AkkaProtocolStressTest.cs @@ -7,6 +7,7 @@ using System; using System.Text.RegularExpressions; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.Remote.Transport; @@ -179,7 +180,7 @@ public AkkaProtocolStressTest() : base(AkkaProtocolStressTestConfig) #region Tests [Fact(Skip = "Extremely racy")] - public void AkkaProtocolTransport_must_guarantee_at_most_once_delivery_and_message_ordering_despite_packet_loss() + public async Task AkkaProtocolTransport_must_guarantee_at_most_once_delivery_and_message_ordering_despite_packet_loss() { //todo mute both systems for deadletters for any type of message EventFilter.DeadLetter().Mute(); @@ -188,7 +189,7 @@ public void AkkaProtocolTransport_must_guarantee_at_most_once_delivery_and_messa RARP.For(Sys) .Provider.Transport.ManagementCommand(new FailureInjectorTransportAdapter.One(AddressB, new FailureInjectorTransportAdapter.Drop(0.1, 0.1))); - AwaitCondition(() => mc.IsCompleted && mc.Result, TimeSpan.FromSeconds(3)); + await AwaitConditionAsync(() => mc.IsCompleted && mc.Result, TimeSpan.FromSeconds(3)); var here = Here; diff --git a/src/core/Akka.Remote.Tests/Transport/DotNettyTransportShutdownSpec.cs b/src/core/Akka.Remote.Tests/Transport/DotNettyTransportShutdownSpec.cs index d361f53ddd2..455d20d16d0 100644 --- a/src/core/Akka.Remote.Tests/Transport/DotNettyTransportShutdownSpec.cs +++ b/src/core/Akka.Remote.Tests/Transport/DotNettyTransportShutdownSpec.cs @@ -89,8 +89,8 @@ public async Task DotNettyTcpTransport_should_cleanly_terminate_active_endpoints var inboundHandle = p2.ExpectMsg().Association; // wait for the inbound association handle to show up inboundHandle.ReadHandlerSource.SetResult(new ActorHandleEventListener(p2)); - AwaitCondition(() => t1.ConnectionGroup.Count == 2); - AwaitCondition(() => t2.ConnectionGroup.Count == 2); + await AwaitConditionAsync(() => t1.ConnectionGroup.Count == 2); + await AwaitConditionAsync(() => t2.ConnectionGroup.Count == 2); var chan1 = t1.ConnectionGroup.Single(x => !x.Id.Equals(t1.ServerChannel.Id)); var chan2 = t2.ConnectionGroup.Single(x => !x.Id.Equals(t2.ServerChannel.Id)); @@ -100,8 +100,8 @@ public async Task DotNettyTcpTransport_should_cleanly_terminate_active_endpoints // verify that the connections are terminated p1.ExpectMsg(); - AwaitCondition(() => t1.ConnectionGroup.Count == 1); - AwaitCondition(() => t2.ConnectionGroup.Count == 1); + await AwaitConditionAsync(() => t1.ConnectionGroup.Count == 1); + await AwaitConditionAsync(() => t2.ConnectionGroup.Count == 1); // verify that the connection channels were terminated on both ends chan1.CloseCompletion.IsCompleted.Should().BeTrue(); @@ -136,8 +136,8 @@ public async Task DotNettyTcpTransport_should_cleanly_terminate_active_endpoints var inboundHandle = p2.ExpectMsg().Association; // wait for the inbound association handle to show up inboundHandle.ReadHandlerSource.SetResult(new ActorHandleEventListener(p2)); - AwaitCondition(() => t1.ConnectionGroup.Count == 2); - AwaitCondition(() => t2.ConnectionGroup.Count == 2); + await AwaitConditionAsync(() => t1.ConnectionGroup.Count == 2); + await AwaitConditionAsync(() => t2.ConnectionGroup.Count == 2); var chan1 = t1.ConnectionGroup.Single(x => !x.Id.Equals(t1.ServerChannel.Id)); var chan2 = t2.ConnectionGroup.Single(x => !x.Id.Equals(t2.ServerChannel.Id)); @@ -147,8 +147,8 @@ public async Task DotNettyTcpTransport_should_cleanly_terminate_active_endpoints p2.ExpectMsg(); // verify that the connections are terminated - AwaitCondition(() => t1.ConnectionGroup.Count == 0, null, message: $"Expected 0 open connection but found {t1.ConnectionGroup.Count}"); - AwaitCondition(() => t2.ConnectionGroup.Count == 1, null,message: $"Expected 1 open connection but found {t2.ConnectionGroup.Count}"); + await AwaitConditionAsync(() => t1.ConnectionGroup.Count == 0, null, message: $"Expected 0 open connection but found {t1.ConnectionGroup.Count}"); + await AwaitConditionAsync(() => t2.ConnectionGroup.Count == 1, null,message: $"Expected 1 open connection but found {t2.ConnectionGroup.Count}"); // verify that the connection channels were terminated on both ends chan1.CloseCompletion.IsCompleted.Should().BeTrue(); @@ -183,8 +183,8 @@ public async Task DotNettyTcpTransport_should_cleanly_terminate_active_endpoints var inboundHandle = p2.ExpectMsg().Association; // wait for the inbound association handle to show up inboundHandle.ReadHandlerSource.SetResult(new ActorHandleEventListener(p2)); - AwaitCondition(() => t1.ConnectionGroup.Count == 2); - AwaitCondition(() => t2.ConnectionGroup.Count == 2); + await AwaitConditionAsync(() => t1.ConnectionGroup.Count == 2); + await AwaitConditionAsync(() => t2.ConnectionGroup.Count == 2); var chan1 = t1.ConnectionGroup.Single(x => !x.Id.Equals(t1.ServerChannel.Id)); var chan2 = t2.ConnectionGroup.Single(x => !x.Id.Equals(t2.ServerChannel.Id)); @@ -193,8 +193,8 @@ public async Task DotNettyTcpTransport_should_cleanly_terminate_active_endpoints inboundHandle.Disassociate(); // verify that the connections are terminated - AwaitCondition(() => t1.ConnectionGroup.Count == 1, null, message: $"Expected 1 open connection but found {t1.ConnectionGroup.Count}"); - AwaitCondition(() => t2.ConnectionGroup.Count == 1, null, message: $"Expected 1 open connection but found {t2.ConnectionGroup.Count}"); + await AwaitConditionAsync(() => t1.ConnectionGroup.Count == 1, null, message: $"Expected 1 open connection but found {t1.ConnectionGroup.Count}"); + await AwaitConditionAsync(() => t2.ConnectionGroup.Count == 1, null, message: $"Expected 1 open connection but found {t2.ConnectionGroup.Count}"); // verify that the connection channels were terminated on both ends chan1.CloseCompletion.IsCompleted.Should().BeTrue(); @@ -229,8 +229,8 @@ public async Task DotNettyTcpTransport_should_cleanly_terminate_active_endpoints var inboundHandle = p2.ExpectMsg().Association; // wait for the inbound association handle to show up inboundHandle.ReadHandlerSource.SetResult(new ActorHandleEventListener(p2)); - AwaitCondition(() => t1.ConnectionGroup.Count == 2); - AwaitCondition(() => t2.ConnectionGroup.Count == 2); + await AwaitConditionAsync(() => t1.ConnectionGroup.Count == 2); + await AwaitConditionAsync(() => t2.ConnectionGroup.Count == 2); var chan1 = t1.ConnectionGroup.Single(x => !x.Id.Equals(t1.ServerChannel.Id)); var chan2 = t2.ConnectionGroup.Single(x => !x.Id.Equals(t2.ServerChannel.Id)); @@ -239,8 +239,8 @@ public async Task DotNettyTcpTransport_should_cleanly_terminate_active_endpoints await t2.Shutdown(); // verify that the connections are terminated - AwaitCondition(() => t1.ConnectionGroup.Count == 1, null, message: $"Expected 1 open connection but found {t1.ConnectionGroup.Count}"); - AwaitCondition(() => t2.ConnectionGroup.Count == 0, null, message: $"Expected 0 open connection but found {t2.ConnectionGroup.Count}"); + await AwaitConditionAsync(() => t1.ConnectionGroup.Count == 1, null, message: $"Expected 1 open connection but found {t1.ConnectionGroup.Count}"); + await AwaitConditionAsync(() => t2.ConnectionGroup.Count == 0, null, message: $"Expected 0 open connection but found {t2.ConnectionGroup.Count}"); // verify that the connection channels were terminated on both ends chan1.CloseCompletion.IsCompleted.Should().BeTrue(); @@ -272,7 +272,7 @@ await Assert.ThrowsAsync(async () => }); - AwaitCondition(() => t1.ConnectionGroup.Count == 1); + await AwaitConditionAsync(() => t1.ConnectionGroup.Count == 1); } finally { diff --git a/src/core/Akka.Remote.Tests/Transport/GenericTransportSpec.cs b/src/core/Akka.Remote.Tests/Transport/GenericTransportSpec.cs index 33438fb77b3..e9758b484e2 100644 --- a/src/core/Akka.Remote.Tests/Transport/GenericTransportSpec.cs +++ b/src/core/Akka.Remote.Tests/Transport/GenericTransportSpec.cs @@ -79,7 +79,7 @@ public void Transport_must_return_an_Address_and_promise_when_listen_is_called() } [Fact] - public void Transport_must_associate_successfully_with_another_transport_of_its_kind() + public async Task Transport_must_associate_successfully_with_another_transport_of_its_kind() { var registry = new AssociationRegistry(); var transportA = NewTransportA(registry); @@ -89,7 +89,7 @@ public void Transport_must_associate_successfully_with_another_transport_of_its_ AwaitResult(transportA.Listen()).Item2.SetResult(new ActorAssociationEventListener(TestActor)); AwaitResult(transportB.Listen()).Item2.SetResult(new ActorAssociationEventListener(TestActor)); - AwaitCondition(() => registry.TransportsReady(addressATest, addressBTest)); + await AwaitConditionAsync(() => registry.TransportsReady(addressATest, addressBTest)); transportA.Associate(addressB); ExpectMsgPf(DefaultTimeout, "Expect InboundAssociation from A", o => @@ -103,17 +103,17 @@ public void Transport_must_associate_successfully_with_another_transport_of_its_ }); Assert.Contains(registry.LogSnapshot().OfType(), x => x.LocalAddress == addressATest && x.RemoteAddress == addressBTest); - AwaitCondition(() => registry.ExistsAssociation(addressATest, addressBTest)); + await AwaitConditionAsync(() => registry.ExistsAssociation(addressATest, addressBTest)); } [Fact] - public void Transport_must_fail_to_associate_with_nonexisting_address() + public async Task Transport_must_fail_to_associate_with_nonexisting_address() { var registry = new AssociationRegistry(); var transportA = NewTransportA(registry); AwaitResult(transportA.Listen()).Item2.SetResult(new ActorAssociationEventListener(TestActor)); - AwaitCondition(() => registry.TransportsReady(addressATest)); + await AwaitConditionAsync(() => registry.TransportsReady(addressATest)); // Transport throws InvalidAssociationException when trying to associate with non-existing system XAssert.Throws(() => @@ -122,7 +122,7 @@ public void Transport_must_fail_to_associate_with_nonexisting_address() } [Fact] - public void Transport_must_successfully_send_PDUs() + public async Task Transport_must_successfully_send_PDUs() { var registry = new AssociationRegistry(); var transportA = NewTransportA(registry); @@ -131,7 +131,7 @@ public void Transport_must_successfully_send_PDUs() AwaitResult(transportA.Listen()).Item2.SetResult(new ActorAssociationEventListener(TestActor)); AwaitResult(transportB.Listen()).Item2.SetResult(new ActorAssociationEventListener(TestActor)); - AwaitCondition(() => registry.TransportsReady(addressATest, addressBTest)); + await AwaitConditionAsync(() => registry.TransportsReady(addressATest, addressBTest)); var associate = transportA.Associate(addressB); var handleB = ExpectMsgPf(DefaultTimeout, "Expect InboundAssociation from A", o => @@ -152,7 +152,7 @@ public void Transport_must_successfully_send_PDUs() var payload = ByteString.CopyFromUtf8("PDU"); var pdu = withAkkaProtocol ? new AkkaPduProtobuffCodec(Sys).ConstructPayload(payload) : payload; - AwaitCondition(() => registry.ExistsAssociation(addressATest, addressBTest)); + await AwaitConditionAsync(() => registry.ExistsAssociation(addressATest, addressBTest)); handleA.Write(payload); ExpectMsgPf(DefaultTimeout, "Expect InboundPayload from A", o => @@ -169,7 +169,7 @@ public void Transport_must_successfully_send_PDUs() } [Fact] - public void Transport_must_successfully_disassociate() + public async Task Transport_must_successfully_disassociate() { var registry = new AssociationRegistry(); var transportA = NewTransportA(registry); @@ -178,7 +178,7 @@ public void Transport_must_successfully_disassociate() AwaitResult(transportA.Listen()).Item2.SetResult(new ActorAssociationEventListener(TestActor)); AwaitResult(transportB.Listen()).Item2.SetResult(new ActorAssociationEventListener(TestActor)); - AwaitCondition(() => registry.TransportsReady(addressATest, addressBTest)); + await AwaitConditionAsync(() => registry.TransportsReady(addressATest, addressBTest)); var associate = transportA.Associate(addressB); var handleB = ExpectMsgPf(DefaultTimeout, "Expect InboundAssociation from A", o => @@ -196,15 +196,15 @@ public void Transport_must_successfully_disassociate() handleA.ReadHandlerSource.SetResult(new ActorHandleEventListener(TestActor)); handleB.ReadHandlerSource.SetResult(new ActorHandleEventListener(TestActor)); - AwaitCondition(() => registry.ExistsAssociation(addressATest, addressBTest)); + await AwaitConditionAsync(() => registry.ExistsAssociation(addressATest, addressBTest)); handleA.Disassociate(); ExpectMsgPf(DefaultTimeout, "Should receive Disassociated", o => o as Disassociated); - AwaitCondition(() => !registry.ExistsAssociation(addressATest, addressBTest)); + await AwaitConditionAsync(() => !registry.ExistsAssociation(addressATest, addressBTest)); - AwaitCondition(() => + await AwaitConditionAsync(() => registry.LogSnapshot().OfType().Any(x => x.Requestor == addressATest && x.Remote == addressBTest) ); } diff --git a/src/core/Akka.Remote.Tests/Transport/ThrottlerTransportAdapterSpec.cs b/src/core/Akka.Remote.Tests/Transport/ThrottlerTransportAdapterSpec.cs index bad50988f2b..1b13b4d156a 100644 --- a/src/core/Akka.Remote.Tests/Transport/ThrottlerTransportAdapterSpec.cs +++ b/src/core/Akka.Remote.Tests/Transport/ThrottlerTransportAdapterSpec.cs @@ -7,6 +7,7 @@ using System; using System.Text.RegularExpressions; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.Remote.Transport; @@ -195,7 +196,7 @@ public void ThrottlerTransportAdapter_must_maintain_average_message_rate() } [Fact] - public void ThrottlerTransportAdapter_must_survive_blackholing() + public async Task ThrottlerTransportAdapter_must_survive_blackholing() { Here.Tell(new ThrottlingTester.Lost("BlackHole 1")); ExpectMsg(new ThrottlingTester.Lost("BlackHole 1")); @@ -215,7 +216,7 @@ public void ThrottlerTransportAdapter_must_survive_blackholing() // after we remove the Blackhole we can't be certain of the state // of the connection, repeat until success here.Tell(new ThrottlingTester.Lost("BlackHole 3")); - AwaitCondition(() => + await AwaitConditionAsync(() => { var received = ReceiveOne(TimeSpan.Zero); if (received != null && received.Equals(new ThrottlingTester.Lost("BlackHole 3"))) diff --git a/src/core/Akka.Streams.TestKit.Tests/BaseTwoStreamsSetup.cs b/src/core/Akka.Streams.TestKit.Tests/BaseTwoStreamsSetup.cs index e2ce12696ed..95819cdb110 100644 --- a/src/core/Akka.Streams.TestKit.Tests/BaseTwoStreamsSetup.cs +++ b/src/core/Akka.Streams.TestKit.Tests/BaseTwoStreamsSetup.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.TestKit; using FluentAssertions; @@ -62,9 +63,9 @@ protected IPublisher SoonToCompletePublisher() } [Fact] - public void Should_work_with_two_immediately_completed_publishers() + public async Task Should_work_with_two_immediately_completed_publishers() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber = Setup(CompletedPublisher(), CompletedPublisher()); subscriber.ExpectSubscriptionAndComplete(); @@ -72,9 +73,9 @@ public void Should_work_with_two_immediately_completed_publishers() } [Fact] - public void Should_work_with_two_delayed_completed_publishers() + public async Task Should_work_with_two_delayed_completed_publishers() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber = Setup(SoonToCompletePublisher(), SoonToCompletePublisher()); subscriber.ExpectSubscriptionAndComplete(); @@ -82,9 +83,9 @@ public void Should_work_with_two_delayed_completed_publishers() } [Fact] - public void Should_work_with_one_immediately_completed_and_one_delayed_completed_publisher() + public async Task Should_work_with_one_immediately_completed_and_one_delayed_completed_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber = Setup(CompletedPublisher(), SoonToCompletePublisher()); subscriber.ExpectSubscriptionAndComplete(); @@ -92,9 +93,9 @@ public void Should_work_with_one_immediately_completed_and_one_delayed_completed } [Fact] - public void Should_work_with_two_immediately_failed_publishers() + public async Task Should_work_with_two_immediately_failed_publishers() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber = Setup(FailedPublisher(), FailedPublisher()); subscriber.ExpectSubscriptionAndError().Should().Be(TestException()); @@ -102,9 +103,9 @@ public void Should_work_with_two_immediately_failed_publishers() } [Fact] - public void Should_work_with_two_delayed_failed_publishers() + public async Task Should_work_with_two_delayed_failed_publishers() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber = Setup(SoonToFailPublisher(), SoonToFailPublisher()); subscriber.ExpectSubscriptionAndError().Should().Be(TestException()); @@ -114,9 +115,9 @@ public void Should_work_with_two_delayed_failed_publishers() // Warning: The two test cases below are somewhat implementation specific and might fail if the implementation // is changed. They are here to be an early warning though. [Fact] - public void Should_work_with_one_immediately_failed_and_one_delayed_failed_publisher_case_1() + public async Task Should_work_with_one_immediately_failed_and_one_delayed_failed_publisher_case_1() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber = Setup(SoonToFailPublisher(), FailedPublisher()); subscriber.ExpectSubscriptionAndError().Should().Be(TestException()); @@ -124,9 +125,9 @@ public void Should_work_with_one_immediately_failed_and_one_delayed_failed_publi } [Fact] - public void Should_work_with_one_immediately_failed_and_one_delayed_failed_publisher_case_2() + public async Task Should_work_with_one_immediately_failed_and_one_delayed_failed_publisher_case_2() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber = Setup(FailedPublisher(), SoonToFailPublisher()); subscriber.ExpectSubscriptionAndError().Should().Be(TestException()); diff --git a/src/core/Akka.Streams.TestKit.Tests/TestPublisherSubscriberSpec.cs b/src/core/Akka.Streams.TestKit.Tests/TestPublisherSubscriberSpec.cs index ad4aeb7a8a1..0fd258fb9fb 100644 --- a/src/core/Akka.Streams.TestKit.Tests/TestPublisherSubscriberSpec.cs +++ b/src/core/Akka.Streams.TestKit.Tests/TestPublisherSubscriberSpec.cs @@ -5,6 +5,7 @@ // //----------------------------------------------------------------------- +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.TestKit; using FluentAssertions; @@ -24,9 +25,9 @@ public TestPublisherSubscriberSpec(ITestOutputHelper output = null) : base(outpu } [Fact] - public void TestPublisher_and_TestSubscriber_should_have_all_events_accessible_from_manual_probes() + public async Task TestPublisher_and_TestSubscriber_should_have_all_events_accessible_from_manual_probes() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstream = this.CreateManualPublisherProbe(); var downstream = this.CreateManualSubscriberProbe(); diff --git a/src/core/Akka.Streams.TestKit.Tests/Utils.cs b/src/core/Akka.Streams.TestKit.Tests/Utils.cs index 9e98ccb251f..ddaded1f3c9 100644 --- a/src/core/Akka.Streams.TestKit.Tests/Utils.cs +++ b/src/core/Akka.Streams.TestKit.Tests/Utils.cs @@ -22,16 +22,16 @@ public static class Utils public static Config UnboundedMailboxConfig { get; } = ConfigurationFactory.ParseString(@"akka.actor.default-mailbox.mailbox-type = ""Akka.Dispatch.UnboundedMailbox, Akka"""); - public static void AssertAllStagesStopped(this AkkaSpec spec, Action block, IMaterializer materializer) + public static async Task AssertAllStagesStoppedAsync(this AkkaSpec spec, Action block, IMaterializer materializer) { - AssertAllStagesStopped(spec, () => + await AssertAllStagesStoppedAsync(spec, () => { block(); return NotUsed.Instance; }, materializer); } - public static T AssertAllStagesStopped(this AkkaSpec spec, Func block, IMaterializer materializer) + public static async Task AssertAllStagesStoppedAsync(this AkkaSpec spec, Func block, IMaterializer materializer) { var impl = materializer as ActorMaterializerImpl; if (impl == null) @@ -42,12 +42,12 @@ public static T AssertAllStagesStopped(this AkkaSpec spec, Func block, IMa probe.ExpectMsg(); var result = block(); - probe.Within(TimeSpan.FromSeconds(5), () => + await probe.WithinAsync(TimeSpan.FromSeconds(5), async () => { IImmutableSet children = ImmutableHashSet.Empty; try { - probe.AwaitAssert(() => + await probe.AwaitAssertAsync(() => { impl.Supervisor.Tell(StreamSupervisor.GetChildren.Instance, probe.Ref); children = probe.ExpectMsg().Refs; diff --git a/src/core/Akka.Streams.Tests/Actor/ActorPublisherSpec.cs b/src/core/Akka.Streams.Tests/Actor/ActorPublisherSpec.cs index 45aed4b8f20..dbd809963e2 100644 --- a/src/core/Akka.Streams.Tests/Actor/ActorPublisherSpec.cs +++ b/src/core/Akka.Streams.Tests/Actor/ActorPublisherSpec.cs @@ -10,6 +10,7 @@ using System.Collections.Immutable; using System.Linq; using System.Threading; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.Pattern; @@ -282,10 +283,10 @@ public void ActorPublisher_should_signal_onComplete_when_actor_is_stopped() } [Fact] - public void ActorPublisher_should_work_together_with_Flow_and_ActorSubscriber() + public async Task ActorPublisher_should_work_together_with_Flow_and_ActorSubscriber() { var materializer = Sys.Materializer(); - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = CreateTestProbe(); var source = Source.ActorPublisher(Sender.Props); @@ -374,10 +375,10 @@ public void ActorPublisher_should_work_in_a_GraphDsl() } [Fact] - public void ActorPublisher_should_be_able_to_define_a_subscription_timeout_after_which_it_should_shut_down() + public async Task ActorPublisher_should_be_able_to_define_a_subscription_timeout_after_which_it_should_shut_down() { var materializer = Sys.Materializer(); - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var timeout = TimeSpan.FromMilliseconds(150); var a = ActorOf(TimeoutingPublisher.Props(TestActor, timeout)); diff --git a/src/core/Akka.Streams.Tests/Dsl/ActorRefBackpressureSinkSpec.cs b/src/core/Akka.Streams.Tests/Dsl/ActorRefBackpressureSinkSpec.cs index fbebae3edb1..4cce8fc5280 100644 --- a/src/core/Akka.Streams.Tests/Dsl/ActorRefBackpressureSinkSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/ActorRefBackpressureSinkSpec.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.Streams.Dsl; @@ -78,9 +79,9 @@ public ActorRefBackpressureSinkSpec(ITestOutputHelper output) : base(output, Con private IActorRef CreateActor() => Sys.ActorOf(Props.Create(typeof(T), TestActor).WithDispatcher("akka.test.stream-dispatcher")); [Fact] - public void ActorBackpressureSink_should_send_the_elements_to_the_ActorRef() + public async Task ActorBackpressureSink_should_send_the_elements_to_the_ActorRef() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var fw = CreateActor(); Source.From(Enumerable.Range(1, 3)) @@ -94,9 +95,9 @@ public void ActorBackpressureSink_should_send_the_elements_to_the_ActorRef() } [Fact] - public void ActorBackpressureSink_should_send_the_elements_to_the_ActorRef2() + public async Task ActorBackpressureSink_should_send_the_elements_to_the_ActorRef2() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var fw = CreateActor(); var probe = @@ -116,9 +117,9 @@ public void ActorBackpressureSink_should_send_the_elements_to_the_ActorRef2() } [Fact] - public void ActorBackpressureSink_should_cancel_stream_when_actor_terminates() + public async Task ActorBackpressureSink_should_cancel_stream_when_actor_terminates() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var fw = CreateActor(); var publisher = @@ -134,9 +135,9 @@ public void ActorBackpressureSink_should_cancel_stream_when_actor_terminates() } [Fact] - public void ActorBackpressureSink_should_send_message_only_when_backpressure_received() + public async Task ActorBackpressureSink_should_send_message_only_when_backpressure_received() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var fw = CreateActor(); var publisher = this.SourceProbe() @@ -161,9 +162,9 @@ public void ActorBackpressureSink_should_send_message_only_when_backpressure_rec } [Fact] - public void ActorBackpressureSink_should_keep_on_sending_even_after_the_buffer_has_been_full() + public async Task ActorBackpressureSink_should_keep_on_sending_even_after_the_buffer_has_been_full() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var bufferSize = 16; var streamElementCount = bufferSize + 4; @@ -192,9 +193,9 @@ public void ActorBackpressureSink_should_keep_on_sending_even_after_the_buffer_h } [Fact] - public void ActorBackpressureSink_should_work_with_one_element_buffer() + public async Task ActorBackpressureSink_should_work_with_one_element_buffer() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var fw = CreateActor(); var publisher = diff --git a/src/core/Akka.Streams.Tests/Dsl/ActorRefSourceSpec.cs b/src/core/Akka.Streams.Tests/Dsl/ActorRefSourceSpec.cs index c61a58acafb..608b30bf882 100644 --- a/src/core/Akka.Streams.Tests/Dsl/ActorRefSourceSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/ActorRefSourceSpec.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Threading.Tasks; using Akka.Actor; using Akka.Streams.Dsl; using Akka.Streams.TestKit; @@ -86,9 +87,9 @@ public void A_ActorRefSource_must_drop_new_when_full_and_with_DropNew_strategy() } [Fact] - public void A_ActorRefSource_must_terminate_when_the_stream_is_cancelled() + public async Task A_ActorRefSource_must_terminate_when_the_stream_is_cancelled() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s = this.CreateManualSubscriberProbe(); var actorRef = Source.ActorRef(0, OverflowStrategy.Fail) @@ -102,9 +103,9 @@ public void A_ActorRefSource_must_terminate_when_the_stream_is_cancelled() } [Fact] - public void A_ActorRefSource_must_not_fail_when_0_buffer_space_and_demand_is_signalled() + public async Task A_ActorRefSource_must_not_fail_when_0_buffer_space_and_demand_is_signalled() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s = this.CreateManualSubscriberProbe(); var actorRef = Source.ActorRef(0, OverflowStrategy.DropHead) @@ -119,9 +120,9 @@ public void A_ActorRefSource_must_not_fail_when_0_buffer_space_and_demand_is_sig } [Fact] - public void A_ActorRefSource_must_completes_the_stream_immediately_when_receiving_PoisonPill() + public async Task A_ActorRefSource_must_completes_the_stream_immediately_when_receiving_PoisonPill() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s = this.CreateManualSubscriberProbe(); var actorRef = Source.ActorRef(10, OverflowStrategy.Fail) @@ -134,9 +135,9 @@ public void A_ActorRefSource_must_completes_the_stream_immediately_when_receivin } [Fact] - public void A_ActorRefSource_must_signal_buffered_elements_and_complete_the_stream_after_receiving_Status_Success() + public async Task A_ActorRefSource_must_signal_buffered_elements_and_complete_the_stream_after_receiving_Status_Success() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s = this.CreateManualSubscriberProbe(); var actorRef = Source.ActorRef(10, OverflowStrategy.Fail) @@ -154,9 +155,9 @@ public void A_ActorRefSource_must_signal_buffered_elements_and_complete_the_stre } [Fact] - public void A_ActorRefSource_must_not_buffer_elements_after_receiving_Status_Success() + public async Task A_ActorRefSource_must_not_buffer_elements_after_receiving_Status_Success() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s = this.CreateManualSubscriberProbe(); var actorRef = Source.ActorRef(3, OverflowStrategy.DropBuffer) @@ -178,9 +179,9 @@ public void A_ActorRefSource_must_not_buffer_elements_after_receiving_Status_Suc } [Fact] - public void A_ActorRefSource_must_after_receiving_Status_Success_allow_for_earlier_completion_with_PoisonPill() + public async Task A_ActorRefSource_must_after_receiving_Status_Success_allow_for_earlier_completion_with_PoisonPill() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s = this.CreateManualSubscriberProbe(); var actorRef = Source.ActorRef(3, OverflowStrategy.DropBuffer) @@ -199,9 +200,9 @@ public void A_ActorRefSource_must_after_receiving_Status_Success_allow_for_earli } [Fact] - public void A_ActorRefSource_must_fail_the_stream_when_receiving_Status_Failure() + public async Task A_ActorRefSource_must_fail_the_stream_when_receiving_Status_Failure() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s = this.CreateManualSubscriberProbe(); var actorRef = Source.ActorRef(10, OverflowStrategy.Fail) @@ -215,9 +216,9 @@ public void A_ActorRefSource_must_fail_the_stream_when_receiving_Status_Failure( } [Fact] - public void A_ActorRefSource_must_set_actor_name_equal_to_stage_name() + public async Task A_ActorRefSource_must_set_actor_name_equal_to_stage_name() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s = this.CreateManualSubscriberProbe(); const string name = "SomeCustomName"; diff --git a/src/core/Akka.Streams.Tests/Dsl/BidiFlowSpec.cs b/src/core/Akka.Streams.Tests/Dsl/BidiFlowSpec.cs index f3229856ec5..e4784252ed5 100644 --- a/src/core/Akka.Streams.Tests/Dsl/BidiFlowSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/BidiFlowSpec.cs @@ -162,9 +162,9 @@ public void A_BidiFlow_must_materialize_its_value() } [Fact] - public void A_BidiFlow_must_combine_materialization_values() + public async Task A_BidiFlow_must_combine_materialization_values() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var left = Flow.FromGraph(GraphDsl.Create(Sink.First(), (b, sink) => { diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowAggregateAsyncSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowAggregateAsyncSpec.cs index e3380501351..073fb5e966c 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowAggregateAsyncSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowAggregateAsyncSpec.cs @@ -54,9 +54,9 @@ private static Sink> AggregateSink [Fact] - public void A_AggregateAsync_must_work_when_using_Source_AggregateAsync() + public async Task A_AggregateAsync_must_work_when_using_Source_AggregateAsync() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = AggregateSource.RunWith(Sink.First(), Materializer); task.AwaitResult().Should().Be(Expected); @@ -64,9 +64,9 @@ public void A_AggregateAsync_must_work_when_using_Source_AggregateAsync() } [Fact] - public void A_AggregateAsync_must_work_when_using_Sink_AggregateAsync() + public async Task A_AggregateAsync_must_work_when_using_Sink_AggregateAsync() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = InputSource.RunWith(AggregateSink, Materializer); task.AwaitResult().Should().Be(Expected); @@ -74,10 +74,10 @@ public void A_AggregateAsync_must_work_when_using_Sink_AggregateAsync() } [Fact(Skip = "Racy on Azure DevOps")] - public void A_AggregateAsync_must_work_when_using_Flow_AggregateAsync() + public async Task A_AggregateAsync_must_work_when_using_Flow_AggregateAsync() { var flowTimeout = TimeSpan.FromMilliseconds(FlowDelayInMs*Input.Count()) + TimeSpan.FromSeconds(3); - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = InputSource.Via(AggregateFlow).RunWith(Sink.First(), Materializer); task.AwaitResult(flowTimeout).Should().Be(Expected); @@ -85,9 +85,9 @@ public void A_AggregateAsync_must_work_when_using_Flow_AggregateAsync() } [Fact] - public void A_AggregateAsync_must_work_when_using_Source_AggregateAsync_and_Flow_AggregateAsync_and_Sink_AggregateAsync() + public async Task A_AggregateAsync_must_work_when_using_Source_AggregateAsync_and_Flow_AggregateAsync_and_Sink_AggregateAsync() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = AggregateSource.Via(AggregateFlow).RunWith(AggregateSink, Materializer); task.AwaitResult().Should().Be(Expected); @@ -95,9 +95,9 @@ public void A_AggregateAsync_must_work_when_using_Source_AggregateAsync_and_Flow } [Fact] - public void A_AggregateAsync_must_propagate_an_error() + public async Task A_AggregateAsync_must_propagate_an_error() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var error = new TestException("buh"); var future = InputSource.Select(x => @@ -114,9 +114,9 @@ public void A_AggregateAsync_must_propagate_an_error() } [Fact] - public void A_AggregateAsync_must_complete_task_with_failure_when_Aggregating_functions_throws() + public async Task A_AggregateAsync_must_complete_task_with_failure_when_Aggregating_functions_throws() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var error = new TestException("buh"); var future = InputSource.RunAggregateAsync(0, (x, y) => @@ -153,9 +153,9 @@ public void A_AggregateAsync_must_not_blow_up_with_high_request_count() } [Fact] - public void A_AggregateAsync_must_signal_task_failure() + public async Task A_AggregateAsync_must_signal_task_failure() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateSubscriberProbe(); Source.From(Enumerable.Range(1, 5)).AggregateAsync(0, (_, n) => Task.Run(() => @@ -172,9 +172,9 @@ public void A_AggregateAsync_must_signal_task_failure() } [Fact] - public void A_AggregateAsync_must_signal_error_from_AggregateAsync() + public async Task A_AggregateAsync_must_signal_error_from_AggregateAsync() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c = this.CreateManualSubscriberProbe(); @@ -193,9 +193,9 @@ public void A_AggregateAsync_must_signal_error_from_AggregateAsync() } [Fact] - public void A_AggregateAsync_must_resume_after_task_failure() + public async Task A_AggregateAsync_must_resume_after_task_failure() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateSubscriberProbe<(int, int)>(); Source.From(Enumerable.Range(1, 5)).AggregateAsync((0, 1), (t, n) => @@ -222,9 +222,9 @@ public void A_AggregateAsync_must_resume_after_task_failure() } [Fact] - public void A_AggregateAsync_must_restart_after_task_failure() + public async Task A_AggregateAsync_must_restart_after_task_failure() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateSubscriberProbe<(int, int)>(); Source.From(Enumerable.Range(1, 5)).AggregateAsync((0, 1), (t, n) => @@ -251,9 +251,9 @@ public void A_AggregateAsync_must_restart_after_task_failure() } [Fact] - public void A_AggregateAsync_must_resume_after_multiple_failures() + public async Task A_AggregateAsync_must_resume_after_multiple_failures() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var tasks = new [] { @@ -281,9 +281,9 @@ private Task FailedTask(string message) } [Fact] - public void A_AggregateAsync_must_finish_after_task_failure() + public async Task A_AggregateAsync_must_finish_after_task_failure() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 3)).AggregateAsync(1, (_, n) => Task.Run(() => { @@ -398,9 +398,9 @@ public void A_AggregateAsync_must_restart_when_task_is_completed_with_null() } [Fact] - public void A_AggregateAsync_must_handle_cancel_properly() + public async Task A_AggregateAsync_must_handle_cancel_properly() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var pub = this.CreateManualPublisherProbe(); var sub = this.CreateSubscriberProbe(); @@ -419,9 +419,9 @@ public void A_AggregateAsync_must_handle_cancel_properly() } [Fact] - public void A_AggregateAsync_must_complete_task_and_return_zero_given_an_empty_stream() + public async Task A_AggregateAsync_must_complete_task_and_return_zero_given_an_empty_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.From(Enumerable.Empty()) .RunAggregateAsync(0, (acc, element) => Task.FromResult(acc + element), Materializer); @@ -430,9 +430,9 @@ public void A_AggregateAsync_must_complete_task_and_return_zero_given_an_empty_s } [Fact] - public void A_AggregateAsync_must_complete_task_and_return_zero_and_item_given_a_stream_of_one_item() + public async Task A_AggregateAsync_must_complete_task_and_return_zero_and_item_given_a_stream_of_one_item() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.Single(100) .RunAggregateAsync(5, (acc, element) => Task.FromResult(acc + element), Materializer); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowAggregateSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowAggregateSpec.cs index 045d17a2a54..2f443c9543a 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowAggregateSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowAggregateSpec.cs @@ -36,9 +36,9 @@ public FlowAggregateSpec(ITestOutputHelper helper) : base(helper) private static Sink> AggregateSink => Sink.Aggregate(0, (sum, i) => sum + i); [Fact] - public void A_Aggregate_must_work_when_using_Source_RunAggregate() + public async Task A_Aggregate_must_work_when_using_Source_RunAggregate() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = InputSource.RunAggregate(0, (sum, i) => sum + i, Materializer); task.AwaitResult().Should().Be(Expected); @@ -46,9 +46,9 @@ public void A_Aggregate_must_work_when_using_Source_RunAggregate() } [Fact] - public void A_Aggregate_must_work_when_using_Source_Aggregate() + public async Task A_Aggregate_must_work_when_using_Source_Aggregate() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = AggregateSource.RunWith(Sink.First(), Materializer); task.AwaitResult().Should().Be(Expected); @@ -56,9 +56,9 @@ public void A_Aggregate_must_work_when_using_Source_Aggregate() } [Fact] - public void A_Aggregate_must_work_when_using_Sink_Aggregate() + public async Task A_Aggregate_must_work_when_using_Sink_Aggregate() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = InputSource.RunWith(AggregateSink, Materializer); task.AwaitResult().Should().Be(Expected); @@ -66,9 +66,9 @@ public void A_Aggregate_must_work_when_using_Sink_Aggregate() } [Fact] - public void A_Aggregate_must_work_when_using_Flow_Aggregate() + public async Task A_Aggregate_must_work_when_using_Flow_Aggregate() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = InputSource.Via(AggregateFlow).RunWith(Sink.First(), Materializer); task.AwaitResult().Should().Be(Expected); @@ -76,9 +76,9 @@ public void A_Aggregate_must_work_when_using_Flow_Aggregate() } [Fact] - public void A_Aggregate_must_work_when_using_Source_Aggregate_and_Flow_Aggregate_and_Sink_Aggregate() + public async Task A_Aggregate_must_work_when_using_Source_Aggregate_and_Flow_Aggregate_and_Sink_Aggregate() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = AggregateSource.Via(AggregateFlow).RunWith(AggregateSink, Materializer); task.AwaitResult().Should().Be(Expected); @@ -86,9 +86,9 @@ public void A_Aggregate_must_work_when_using_Source_Aggregate_and_Flow_Aggregate } [Fact] - public void A_Aggregate_must_propagate_an_error() + public async Task A_Aggregate_must_propagate_an_error() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var error = new TestException("buh"); var future = InputSource.Select(x => @@ -106,10 +106,10 @@ public void A_Aggregate_must_propagate_an_error() } [Fact] - public void + public async Task A_Aggregate_must_complete_task_with_failure_when_the_aggregateing_function_throws_and_the_supervisor_strategy_decides_to_stop() - { - this.AssertAllStagesStopped(() => + { + await this.AssertAllStagesStoppedAsync(() => { var error = new TestException("buh"); var future = InputSource.RunAggregate(0, (x, y) => @@ -127,9 +127,9 @@ public void } [Fact] - public void A_Aggregate_must_resume_with_the_accumulated_state_when_the_aggregating_funtion_throws_and_the_supervisor_strategy_decides_to_resume() + public async Task A_Aggregate_must_resume_with_the_accumulated_state_when_the_aggregating_funtion_throws_and_the_supervisor_strategy_decides_to_resume() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var error = new Exception("boom"); var aggregate = Sink.Aggregate(0, (int x, int y) => @@ -147,9 +147,9 @@ public void A_Aggregate_must_resume_with_the_accumulated_state_when_the_aggregat } [Fact] - public void A_Aggregate_must_resume_and_reset_the_state_when_the_aggregating_funtion_throws_and_the_supervisor_strategy_decides_to_restart() + public async Task A_Aggregate_must_resume_and_reset_the_state_when_the_aggregating_funtion_throws_and_the_supervisor_strategy_decides_to_restart() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var error = new Exception("boom"); var aggregate = Sink.Aggregate(0, (int x, int y) => @@ -167,9 +167,9 @@ public void A_Aggregate_must_resume_and_reset_the_state_when_the_aggregating_fun } [Fact] - public void A_Aggregate_must_complete_task_and_return_zero_given_an_empty_stream() + public async Task A_Aggregate_must_complete_task_and_return_zero_given_an_empty_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.From(Enumerable.Empty()) .RunAggregate(0, (acc, element) => acc + element, Materializer); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowAskSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowAskSpec.cs index 5baf58db3da..5a184e5cc84 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowAskSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowAskSpec.cs @@ -146,7 +146,7 @@ public FlowAskSpec(ITestOutputHelper output) : base(SpecConfig, output) } [Fact] - public void Flow_with_ask_must_produce_asked_elements() => this.AssertAllStagesStopped(() => + public async Task Flow_with_ask_must_produce_asked_elements() => await this.AssertAllStagesStoppedAsync(() => { var replyOnInts = Sys.ActorOf(Props.Create(() => new Replier()).WithDispatcher("akka.test.stream-dispatcher"), @@ -168,7 +168,7 @@ public void Flow_with_ask_must_produce_asked_elements() => this.AssertAllStagesS }, _materializer); [Fact] - public void Flow_with_ask_must_produce_asked_elements_for_simple_ask() => this.AssertAllStagesStopped(() => + public async Task Flow_with_ask_must_produce_asked_elements_for_simple_ask() => await this.AssertAllStagesStoppedAsync(() => { var replyOnInts = Sys.ActorOf(Props.Create(() => new Replier()).WithDispatcher("akka.test.stream-dispatcher"), "replyOnInts"); var c = this.CreateManualSubscriberProbe(); @@ -188,7 +188,7 @@ public void Flow_with_ask_must_produce_asked_elements_for_simple_ask() => this.A }, _materializer); [Fact] - public void Flow_with_ask_must_produce_asked_elements_when_response_is_Status_Success() => this.AssertAllStagesStopped(() => + public async Task Flow_with_ask_must_produce_asked_elements_when_response_is_Status_Success() => await this.AssertAllStagesStoppedAsync(() => { var statusReplier = Sys.ActorOf(Props.Create(() => new StatusReplier()).WithDispatcher("akka.test.stream-dispatcher"), "statusReplier"); var c = this.CreateManualSubscriberProbe(); @@ -226,7 +226,7 @@ public void Flow_with_ask_must_produce_future_elements_in_order() } [Fact] - public void Flow_with_ask_must_signal_ask_timeout_failure() => this.AssertAllStagesStopped(() => + public async Task Flow_with_ask_must_signal_ask_timeout_failure() => await this.AssertAllStagesStoppedAsync(() => { var dontReply = Sys.ActorOf(BlackHoleActor.Props.WithDispatcher("akka.test.stream-dispatcher"), "dontReply"); var c = this.CreateManualSubscriberProbe(); @@ -243,7 +243,7 @@ public void Flow_with_ask_must_signal_ask_timeout_failure() => this.AssertAllSta }, _materializer); [Fact(Skip = "Racy on Azure DevOps")] - public void Flow_with_ask_must_signal_ask_failure() => this.AssertAllStagesStopped(() => + public async Task Flow_with_ask_must_signal_ask_failure() => await this.AssertAllStagesStoppedAsync(() => { var failsOn = ReplierFailOn(1); var c = this.CreateManualSubscriberProbe(); @@ -258,7 +258,7 @@ public void Flow_with_ask_must_signal_ask_failure() => this.AssertAllStagesStopp }, _materializer); [Fact] - public void Flow_with_ask_signal_failure_when_target_actor_is_terminated() => this.AssertAllStagesStopped(() => + public async Task Flow_with_ask_signal_failure_when_target_actor_is_terminated() => await this.AssertAllStagesStoppedAsync(() => { var r = Sys.ActorOf(Props.Create(() => new Replier()).WithDispatcher("akka.test.stream-dispatcher"), "replyRandomDelays"); var done = Source.Maybe() @@ -276,7 +276,7 @@ public void Flow_with_ask_signal_failure_when_target_actor_is_terminated() => th }, _materializer); [Fact] - public void Flow_with_ask_a_failure_mid_stream_must_skip_element_with_resume_strategy() => this.AssertAllStagesStopped(() => + public async Task Flow_with_ask_a_failure_mid_stream_must_skip_element_with_resume_strategy() => await this.AssertAllStagesStoppedAsync(() => { var p = CreateTestProbe(); var input = new[] { "a", "b", "c", "d", "e", "f" }; @@ -310,7 +310,7 @@ public void Flow_with_ask_a_failure_mid_stream_must_skip_element_with_resume_str }, _materializer); [Fact] - public void Flow_with_ask_must_resume_after_ask_failure() => this.AssertAllStagesStopped(() => + public async Task Flow_with_ask_must_resume_after_ask_failure() => await this.AssertAllStagesStoppedAsync(() => { var c = this.CreateManualSubscriberProbe(); var aref = ReplierFailOn(3); @@ -332,7 +332,7 @@ public void Flow_with_ask_must_resume_after_ask_failure() => this.AssertAllStage }, _materializer); [Fact] - public void Flow_with_ask_must_resume_after_multiple_failures() => this.AssertAllStagesStopped(() => + public async Task Flow_with_ask_must_resume_after_multiple_failures() => await this.AssertAllStagesStoppedAsync(() => { var aref = ReplierFailAllExceptOn(6); var t = Source.From(Enumerable.Range(1, 6)) @@ -345,7 +345,7 @@ public void Flow_with_ask_must_resume_after_multiple_failures() => this.AssertAl }, _materializer); [Fact] - public void Flow_with_ask_should_handle_cancel_properly() => this.AssertAllStagesStopped(() => + public async Task Flow_with_ask_should_handle_cancel_properly() => await this.AssertAllStagesStoppedAsync(() => { var dontReply = Sys.ActorOf(BlackHoleActor.Props.WithDispatcher("akka.test.stream-dispatcher"), "dontReply"); var pub = this.CreateManualPublisherProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowBufferSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowBufferSpec.cs index de31039f4ec..fc2d7feb8b5 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowBufferSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowBufferSpec.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -54,9 +55,9 @@ public void Buffer_must_pass_elements_through_normally_in_backpressured_mode_wit } [Fact] - public void Buffer_must_pass_elements_through_a_chain_of_backpressured_buffers_of_different_size() + public async Task Buffer_must_pass_elements_through_a_chain_of_backpressured_buffers_of_different_size() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var future = Source.From(Enumerable.Range(1, 1000)) .Buffer(1, OverflowStrategy.Backpressure) @@ -243,9 +244,9 @@ public void Buffer_must_drop_new_elements_if_buffer_is_full_and_configured_so() } [Fact] - public void Buffer_must_fail_upstream_if_buffer_is_full_and_configured_so() + public async Task Buffer_must_fail_upstream_if_buffer_is_full_and_configured_so() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisher = this.CreatePublisherProbe(); var subscriber = this.CreateManualSubscriberProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowConcatAllSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowConcatAllSpec.cs index 7432478d531..579dac38f9a 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowConcatAllSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowConcatAllSpec.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -33,9 +34,9 @@ public FlowConcatAllSpec(ITestOutputHelper helper) : base(helper) private static readonly TestException TestException = new TestException("test"); [Fact] - public void ConcatAll_must_work_in_the_happy_case() + public async Task ConcatAll_must_work_in_the_happy_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s1 = Source.From(new[] {1, 2}); var s2 = Source.From(new int[] {}); @@ -76,9 +77,9 @@ public void ConcatAll_must_work_together_with_SplitWhen() subscriber.ExpectComplete();} [Fact] - public void ConcatAll_must_on_OnError_on_master_stream_cancel_the_current_open_substream_and_signal_error() + public async Task ConcatAll_must_on_OnError_on_master_stream_cancel_the_current_open_substream_and_signal_error() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisher = this.CreateManualPublisherProbe>(); var subscriber = this.CreateManualSubscriberProbe(); @@ -104,9 +105,9 @@ public void ConcatAll_must_on_OnError_on_master_stream_cancel_the_current_open_s } [Fact] - public void ConcatAll_must_on_OnError_on_master_stream_cancel_the_currently_opening_substream_and_signal_error() + public async Task ConcatAll_must_on_OnError_on_master_stream_cancel_the_currently_opening_substream_and_signal_error() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisher = this.CreateManualPublisherProbe>(); var subscriber = this.CreateManualSubscriberProbe(); @@ -135,9 +136,9 @@ public void ConcatAll_must_on_OnError_on_master_stream_cancel_the_currently_open } [Fact] - public void ConcatAll_must_on_OnError_on_opening_substream_cancel_the_master_stream_and_signal_error() + public async Task ConcatAll_must_on_OnError_on_opening_substream_cancel_the_master_stream_and_signal_error() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisher = this.CreateManualPublisherProbe>(); var subscriber = this.CreateManualSubscriberProbe(); @@ -160,9 +161,9 @@ public void ConcatAll_must_on_OnError_on_opening_substream_cancel_the_master_str } [Fact] - public void ConcatAll_must_on_OnError_on_open_substream_cancel_the_master_stream_and_signal_error() + public async Task ConcatAll_must_on_OnError_on_open_substream_cancel_the_master_stream_and_signal_error() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisher = this.CreateManualPublisherProbe>(); var subscriber = this.CreateManualSubscriberProbe(); @@ -188,9 +189,9 @@ public void ConcatAll_must_on_OnError_on_open_substream_cancel_the_master_stream } [Fact] - public void ConcatAll_must_on_cancellation_cancel_the_current_open_substream_and_the_master_stream() + public async Task ConcatAll_must_on_cancellation_cancel_the_current_open_substream_and_the_master_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisher = this.CreateManualPublisherProbe>(); var subscriber = this.CreateManualSubscriberProbe(); @@ -217,9 +218,9 @@ public void ConcatAll_must_on_cancellation_cancel_the_current_open_substream_and } [Fact] - public void ConcatAll_must_on_cancellation_cancel_the_currently_opening_substream_and_the_master_stream() + public async Task ConcatAll_must_on_cancellation_cancel_the_currently_opening_substream_and_the_master_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisher = this.CreateManualPublisherProbe>(); var subscriber = this.CreateManualSubscriberProbe(); @@ -248,9 +249,9 @@ public void ConcatAll_must_on_cancellation_cancel_the_currently_opening_substrea } [Fact] - public void ConcatAll_must_pass_along_early_cancellation() + public async Task ConcatAll_must_pass_along_early_cancellation() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var up = this.CreateManualPublisherProbe>(); var down = this.CreateManualSubscriberProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowConcatSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowConcatSpec.cs index 1a9565d7ec0..03b868fda3f 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowConcatSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowConcatSpec.cs @@ -75,9 +75,9 @@ public void A_Concat_for_Flow_must_be_able_to_prepend_a_Source_to_a_Flow() } [Fact] - public void A_Concat_for_Flow_must_work_with_one_immediately_completed_and_one_nonempty_publisher() + public async Task A_Concat_for_Flow_must_work_with_one_immediately_completed_and_one_nonempty_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber1 = Setup(CompletedPublisher(), NonEmptyPublisher(Enumerable.Range(1, 4))); var subscription1 = subscriber1.ExpectSubscription(); @@ -94,9 +94,9 @@ public void A_Concat_for_Flow_must_work_with_one_immediately_completed_and_one_n } [Fact] - public void A_Concat_for_Flow_must_work_with_one_immediately_failed_and_one_nonempty_publisher() + public async Task A_Concat_for_Flow_must_work_with_one_immediately_failed_and_one_nonempty_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber = Setup(FailedPublisher(), NonEmptyPublisher(Enumerable.Range(1, 4))); subscriber.ExpectSubscriptionAndError().Should().BeOfType(); @@ -104,9 +104,9 @@ public void A_Concat_for_Flow_must_work_with_one_immediately_failed_and_one_none } [Fact] - public void A_Concat_for_Flow_must_work_with_one_nonempty_and_one_immediately_failed_publisher() + public async Task A_Concat_for_Flow_must_work_with_one_nonempty_and_one_immediately_failed_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber = Setup(NonEmptyPublisher(Enumerable.Range(1, 4)), FailedPublisher()); subscriber.ExpectSubscription().Request(5); @@ -119,9 +119,9 @@ public void A_Concat_for_Flow_must_work_with_one_nonempty_and_one_immediately_fa } [Fact] - public void A_Concat_for_Flow_must_work_with_one_delayed_failed_and_one_nonempty_publisher() + public async Task A_Concat_for_Flow_must_work_with_one_delayed_failed_and_one_nonempty_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber = Setup(SoonToFailPublisher(), NonEmptyPublisher(Enumerable.Range(1, 4))); subscriber.ExpectSubscriptionAndError().Should().BeOfType(); @@ -129,9 +129,9 @@ public void A_Concat_for_Flow_must_work_with_one_delayed_failed_and_one_nonempty } [Fact] - public void A_Concat_for_Flow_must_work_with_one_nonempty_and_one_delayed_failed_publisher() + public async Task A_Concat_for_Flow_must_work_with_one_nonempty_and_one_delayed_failed_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber = Setup(NonEmptyPublisher(Enumerable.Range(1, 4)), SoonToFailPublisher()); subscriber.ExpectSubscription().Request(5); @@ -144,9 +144,9 @@ public void A_Concat_for_Flow_must_work_with_one_nonempty_and_one_delayed_failed } [Fact] - public void A_Concat_for_Flow_must_correctly_handle_async_errors_in_secondary_upstream() + public async Task A_Concat_for_Flow_must_correctly_handle_async_errors_in_secondary_upstream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var promise = new TaskCompletionSource(); var subscriber = this.CreateManualSubscriberProbe(); @@ -163,9 +163,9 @@ public void A_Concat_for_Flow_must_correctly_handle_async_errors_in_secondary_up } [Fact] - public void A_Concat_for_Flow_must_work_with_Source_DSL() + public async Task A_Concat_for_Flow_must_work_with_Source_DSL() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var testSource = Source.From(Enumerable.Range(1, 5)) @@ -185,9 +185,9 @@ public void A_Concat_for_Flow_must_work_with_Source_DSL() } [Fact] - public void A_Concat_for_Flow_must_work_with_Flow_DSL() + public async Task A_Concat_for_Flow_must_work_with_Flow_DSL() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var testFlow = Flow.Create() .ConcatMaterialized(Source.From(Enumerable.Range(6, 5)), Keep.Both) @@ -209,9 +209,9 @@ public void A_Concat_for_Flow_must_work_with_Flow_DSL() } [Fact(Skip = "ConcatMaterialized type conflict")] - public void A_Concat_for_Flow_must_work_with_Flow_DSL2() + public async Task A_Concat_for_Flow_must_work_with_Flow_DSL2() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var testFlow = Flow.Create() .ConcatMaterialized(Source.From(Enumerable.Range(6, 5)), Keep.Both) @@ -238,9 +238,9 @@ public void A_Concat_for_Flow_must_work_with_Flow_DSL2() } [Fact] - public void A_Concat_for_Flow_must_subscribe_at_one_to_initial_source_and_to_one_that_it_is_concat_to() + public async Task A_Concat_for_Flow_must_subscribe_at_one_to_initial_source_and_to_one_that_it_is_concat_to() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisher1 = this.CreatePublisherProbe(); var publisher2 = this.CreatePublisherProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowDelaySpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowDelaySpec.cs index f96cb3cbc1c..028de2b7a42 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowDelaySpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowDelaySpec.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Akka.Actor; using Akka.Streams.Dsl; using Akka.Streams.TestKit; @@ -74,9 +75,9 @@ public void A_Delay_must_deliver_element_after_time_passed_from_actual_receiving } [Fact] - public void A_Delay_must_deliver_elements_with_delay_for_slow_stream() + public async Task A_Delay_must_deliver_elements_with_delay_for_slow_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c = this.CreateManualSubscriberProbe(); var p = this.CreateManualPublisherProbe(); @@ -100,9 +101,9 @@ public void A_Delay_must_deliver_elements_with_delay_for_slow_stream() } [Fact] - public void A_Delay_must_drop_tail_for_internal_buffer_if_it_is_full_in_DropTail_mode() + public async Task A_Delay_must_drop_tail_for_internal_buffer_if_it_is_full_in_DropTail_mode() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.From(Enumerable.Range(1, 20)) .Delay(TimeSpan.FromSeconds(1), DelayOverflowStrategy.DropTail) @@ -118,9 +119,9 @@ public void A_Delay_must_drop_tail_for_internal_buffer_if_it_is_full_in_DropTail } [Fact] - public void A_Delay_must_drop_head_for_internal_buffer_if_it_is_full_in_DropHead_mode() + public async Task A_Delay_must_drop_head_for_internal_buffer_if_it_is_full_in_DropHead_mode() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.From(Enumerable.Range(1, 20)) .Delay(TimeSpan.FromSeconds(1), DelayOverflowStrategy.DropHead) @@ -134,9 +135,9 @@ public void A_Delay_must_drop_head_for_internal_buffer_if_it_is_full_in_DropHead } [Fact] - public void A_Delay_must_clear_all_for_internal_buffer_if_it_is_full_in_DropBuffer_mode() + public async Task A_Delay_must_clear_all_for_internal_buffer_if_it_is_full_in_DropBuffer_mode() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.From(Enumerable.Range(1, 20)) .Delay(TimeSpan.FromSeconds(1), DelayOverflowStrategy.DropBuffer) @@ -150,9 +151,9 @@ public void A_Delay_must_clear_all_for_internal_buffer_if_it_is_full_in_DropBuff } [Fact] - public void A_Delay_must_pass_elements_with_delay_through_normally_in_backpressured_mode() + public async Task A_Delay_must_pass_elements_with_delay_through_normally_in_backpressured_mode() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 3)) .Delay(TimeSpan.FromMilliseconds(300), DelayOverflowStrategy.Backpressure) @@ -169,9 +170,9 @@ public void A_Delay_must_pass_elements_with_delay_through_normally_in_backpressu } [Fact] - public void A_Delay_must_fail_on_overflow_in_Fail_mode() + public async Task A_Delay_must_fail_on_overflow_in_Fail_mode() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var actualError = Source.From(Enumerable.Range(1, 20)) .Delay(TimeSpan.FromMilliseconds(300), DelayOverflowStrategy.Fail) @@ -186,9 +187,9 @@ public void A_Delay_must_fail_on_overflow_in_Fail_mode() } [Fact] - public void A_Delay_must_emit_early_when_buffer_is_full_and_in_EmitEarly_mode() + public async Task A_Delay_must_emit_early_when_buffer_is_full_and_in_EmitEarly_mode() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c = this.CreateManualSubscriberProbe(); var p = this.CreateManualPublisherProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowDetacherSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowDetacherSpec.cs index 992b7479d4a..ac1cee9c99d 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowDetacherSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowDetacherSpec.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -27,9 +28,9 @@ public FlowDetacherSpec(ITestOutputHelper helper) : base(helper) } [Fact] - public void A_Detacher_must_pass_through_all_elements() + public async Task A_Detacher_must_pass_through_all_elements() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 100)) .Detach() @@ -39,9 +40,9 @@ public void A_Detacher_must_pass_through_all_elements() } [Fact] - public void A_Detacher_must_pass_through_failure() + public async Task A_Detacher_must_pass_through_failure() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var ex = new TestException("buh"); var result = Source.From(Enumerable.Range(1, 100)).Select(x => @@ -56,9 +57,9 @@ public void A_Detacher_must_pass_through_failure() } [Fact] - public void A_Detacher_must_emit_the_last_element_when_completed_Without_demand() + public async Task A_Detacher_must_emit_the_last_element_when_completed_Without_demand() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = Source.Single(42).Detach().RunWith(this.SinkProbe(), Materializer).EnsureSubscription(); probe.ExpectNoMsg(TimeSpan.FromMilliseconds(500)); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowFlattenMergeSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowFlattenMergeSpec.cs index 2109584747f..90c3f042661 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowFlattenMergeSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowFlattenMergeSpec.cs @@ -267,11 +267,11 @@ public AttibutesSourceStage() } [Fact] - public void A_FlattenMerge_must_propagate_attributes_to_inner_stream() + public async Task A_FlattenMerge_must_propagate_attributes_to_inner_stream() { var attributesSource = Source.FromGraph(new AttibutesSourceStage()); - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.Single(attributesSource.AddAttributes(Attributes.CreateName("inner"))) .MergeMany(1, x => x) @@ -291,9 +291,9 @@ public void A_FlattenMerge_must_propagate_attributes_to_inner_stream() } [Fact] - public void A_FlattenMerge_must_bubble_up_substream_materialization_exception() + public async Task A_FlattenMerge_must_bubble_up_substream_materialization_exception() { - this.AssertAllStagesStopped(() => { + await this.AssertAllStagesStoppedAsync(() => { var matFail = new TestException("fail!"); var task = Source.Single("whatever") diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowForeachSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowForeachSpec.cs index 10b5d4436a8..4c4d10a7562 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowForeachSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowForeachSpec.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Threading.Tasks; using Akka.Actor; using Akka.Streams.Dsl; using Akka.Streams.TestKit; @@ -28,9 +29,9 @@ public FlowForeachSpec(ITestOutputHelper helper) : base(helper) } [Fact] - public void A_Foreach_must_call_the_procedure_for_each_element() + public async Task A_Foreach_must_call_the_procedure_for_each_element() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 3)).RunForeach(i => TestActor.Tell(i), Materializer).ContinueWith( task => @@ -47,9 +48,9 @@ public void A_Foreach_must_call_the_procedure_for_each_element() } [Fact] - public void A_Foreach_must_complete_the_future_for_an_empty_stream() + public async Task A_Foreach_must_complete_the_future_for_an_empty_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.Empty().RunForeach(i => TestActor.Tell(i), Materializer).ContinueWith( task => @@ -62,9 +63,9 @@ public void A_Foreach_must_complete_the_future_for_an_empty_stream() } [Fact] - public void A_Foreach_must_yield_the_first_error() + public async Task A_Foreach_must_yield_the_first_error() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = this.CreateManualPublisherProbe(); Source.FromPublisher(p).RunForeach(i => TestActor.Tell(i), Materializer).ContinueWith(task => @@ -80,9 +81,9 @@ public void A_Foreach_must_yield_the_first_error() } [Fact] - public void A_Foreach_must_complete_future_with_failure_when_function_throws() + public async Task A_Foreach_must_complete_future_with_failure_when_function_throws() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var error = new TestException("test"); var future = Source.Single(1).RunForeach(_ => diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowFromTaskSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowFromTaskSpec.cs index a7996a6e8bb..688b65498b3 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowFromTaskSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowFromTaskSpec.cs @@ -29,9 +29,9 @@ public FlowFromTaskSpec(ITestOutputHelper helper) : base(helper) } [Fact] - public void A_Flow_based_on_a_Task_must_produce_one_element_from_already_successful_Future() + public async Task A_Flow_based_on_a_Task_must_produce_one_element_from_already_successful_Future() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c = this.CreateManualSubscriberProbe(); var p = Source.FromTask(Task.FromResult(1)).RunWith(Sink.AsPublisher(true), Materializer); @@ -45,9 +45,9 @@ public void A_Flow_based_on_a_Task_must_produce_one_element_from_already_success } [Fact] - public void A_Flow_based_on_a_Task_must_produce_error_from_already_failed_Task() + public async Task A_Flow_based_on_a_Task_must_produce_error_from_already_failed_Task() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var ex = new TestException("test"); var c = this.CreateManualSubscriberProbe(); @@ -60,9 +60,9 @@ public void A_Flow_based_on_a_Task_must_produce_error_from_already_failed_Task() } [Fact] - public void A_Flow_based_on_a_Task_must_produce_one_element_when_Task_is_completed() + public async Task A_Flow_based_on_a_Task_must_produce_one_element_when_Task_is_completed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var promise = new TaskCompletionSource(); var c = this.CreateManualSubscriberProbe(); @@ -94,9 +94,9 @@ public void A_Flow_based_on_a_Task_must_produce_one_element_when_Task_is_complet } [Fact] - public void A_Flow_based_on_a_Task_must_produce_elements_with_multiple_subscribers() + public async Task A_Flow_based_on_a_Task_must_produce_elements_with_multiple_subscribers() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var promise = new TaskCompletionSource(); var p = Source.FromTask(promise.Task).RunWith(Sink.AsPublisher(true), Materializer); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowGroupBySpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowGroupBySpec.cs index 6291f7e5b15..0068e93afd8 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowGroupBySpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowGroupBySpec.cs @@ -96,9 +96,9 @@ private ByteString RandomByteString(int size) } [Fact] - public void GroupBy_must_work_in_the_happy_case() + public async Task GroupBy_must_work_in_the_happy_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { WithSubstreamsSupport(2, run: (masterSubscriber, masterSubscription, getSubFlow) => { @@ -167,9 +167,9 @@ public void GroupBy_must_fail_when_key_function_returns_null() } [Fact] - public void GroupBy_must_support_cancelling_substreams() + public async Task GroupBy_must_support_cancelling_substreams() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { WithSubstreamsSupport(2, run: (masterSubscriber, masterSubscription, getSubFlow) => { @@ -192,9 +192,9 @@ public void GroupBy_must_support_cancelling_substreams() } [Fact] - public void GroupBy_must_accept_cancellation_of_master_stream_when_not_consume_anything() + public async Task GroupBy_must_accept_cancellation_of_master_stream_when_not_consume_anything() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisherProbe = this.CreateManualPublisherProbe(); var publisher = @@ -213,9 +213,9 @@ public void GroupBy_must_accept_cancellation_of_master_stream_when_not_consume_a } [Fact] - public void GroupBy_must_work_with_empty_input_stream() + public async Task GroupBy_must_work_with_empty_input_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisher = Source.From(new List()) @@ -230,9 +230,9 @@ public void GroupBy_must_work_with_empty_input_stream() } [Fact] - public void GroupBy_must_abort_onError_from_upstream() + public async Task GroupBy_must_abort_onError_from_upstream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisherProbe = this.CreateManualPublisherProbe(); var publisher = @@ -254,9 +254,9 @@ public void GroupBy_must_abort_onError_from_upstream() } [Fact] - public void GroupBy_must_abort_onError_from_upstream_when_substreams_are_running() + public async Task GroupBy_must_abort_onError_from_upstream_when_substreams_are_running() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisherProbe = this.CreateManualPublisherProbe(); var publisher = @@ -286,9 +286,9 @@ public void GroupBy_must_abort_onError_from_upstream_when_substreams_are_running } [Fact] - public void GroupBy_must_fail_stream_when_GroupBy_function_throws() + public async Task GroupBy_must_fail_stream_when_GroupBy_function_throws() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisherProbe = this.CreateManualPublisherProbe(); var ex = new TestException("test"); @@ -325,9 +325,9 @@ public void GroupBy_must_fail_stream_when_GroupBy_function_throws() } [Fact] - public void GroupBy_must_resume_stream_when_GroupBy_function_throws() + public async Task GroupBy_must_resume_stream_when_GroupBy_function_throws() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisherProbe = this.CreateManualPublisherProbe(); var ex = new TestException("test"); @@ -379,9 +379,9 @@ public void GroupBy_must_resume_stream_when_GroupBy_function_throws() } [Fact] - public void GroupBy_must_pass_along_early_cancellation() + public async Task GroupBy_must_pass_along_early_cancellation() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var up = this.CreateManualPublisherProbe(); var down = this.CreateManualSubscriberProbe<(int, Source)>(); @@ -401,9 +401,9 @@ public void GroupBy_must_pass_along_early_cancellation() } [Fact] - public void GroupBy_must_fail_when_exceeding_maxSubstreams() + public async Task GroupBy_must_fail_when_exceeding_maxSubstreams() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var f = Flow.Create().GroupBy(1, x => x % 2).PrefixAndTail(0).MergeSubstreams(); var t = ((Flow, Source), NotUsed>)f) @@ -428,9 +428,9 @@ public void GroupBy_must_fail_when_exceeding_maxSubstreams() } [Fact] - public void GroupBy_must_emit_subscribe_before_completed() + public async Task GroupBy_must_emit_subscribe_before_completed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var source = (Source, NotUsed>)Source.Single(0).GroupBy(1, _ => "all") .PrefixAndTail(0) @@ -449,9 +449,9 @@ public void GroupBy_must_emit_subscribe_before_completed() } [Fact] - public void GroupBy_must_work_under_fuzzing_stress_test() + public async Task GroupBy_must_work_under_fuzzing_stress_test() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisherProbe = this.CreateManualPublisherProbe(); var subscriber = this.CreateManualSubscriberProbe>(); @@ -483,9 +483,9 @@ public void GroupBy_must_work_under_fuzzing_stress_test() } [Fact] - public void GroupBy_must_Work_if_pull_is_exercised_from_both_substream_and_main() + public async Task GroupBy_must_Work_if_pull_is_exercised_from_both_substream_and_main() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstream = this.CreatePublisherProbe(); var downstreamMaster = this.CreateSubscriberProbe>(); @@ -518,9 +518,9 @@ public void GroupBy_must_Work_if_pull_is_exercised_from_both_substream_and_main( } [Fact] - public void GroupBy_must_work_with_random_demand() + public async Task GroupBy_must_work_with_random_demand() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var settings = ActorMaterializerSettings.Create(Sys).WithInputBuffer(1, 1); var materializer = Sys.Materializer(settings); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowGroupedWithinSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowGroupedWithinSpec.cs index 44a869d58f0..2708dd064c5 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowGroupedWithinSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowGroupedWithinSpec.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -34,9 +35,9 @@ public FlowGroupedWithinSpec(ITestOutputHelper helper) : base(helper) } [Fact] - public void A_GroupedWithin_must_group_elements_within_the_duration() + public async Task A_GroupedWithin_must_group_elements_within_the_duration() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var input = new Iterator(Enumerable.Range(1, 10000)); var p = this.CreateManualPublisherProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowIdleInjectSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowIdleInjectSpec.cs index 6f1c87c9adf..1bf281052e9 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowIdleInjectSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowIdleInjectSpec.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -31,9 +32,9 @@ public FlowIdleInjectSpec(ITestOutputHelper helper) : base(helper) } [Fact] - public void KeepAlive_must_not_emit_additional_elements_if_upstream_is_fastEnough() + public async Task KeepAlive_must_not_emit_additional_elements_if_upstream_is_fastEnough() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var result = Source.From(Enumerable.Range(1, 10)) .KeepAlive(TimeSpan.FromSeconds(1), () => 0) @@ -46,9 +47,9 @@ public void KeepAlive_must_not_emit_additional_elements_if_upstream_is_fastEnoug } [Fact] - public void KeepAlive_must_emit_elements_periodically_after_silent_periods() + public async Task KeepAlive_must_emit_elements_periodically_after_silent_periods() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var sourceWithIdleGap = Source.Combine(Source.From(Enumerable.Range(1, 5)), Source.From(Enumerable.Range(6, 5)).InitialDelay(TimeSpan.FromSeconds(2)), diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowInitialDelaySpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowInitialDelaySpec.cs index ade47395a63..fab3005ca5a 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowInitialDelaySpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowInitialDelaySpec.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -31,9 +32,9 @@ public FlowInitialDelaySpec(ITestOutputHelper helper) : base(helper) } [Fact] - public void Flow_InitialDelay_must_work_with_zero_delay() + public async Task Flow_InitialDelay_must_work_with_zero_delay() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.From(Enumerable.Range(1, 10)) .InitialDelay(TimeSpan.Zero) @@ -45,9 +46,9 @@ public void Flow_InitialDelay_must_work_with_zero_delay() } [Fact] - public void Flow_InitialDelay_must_delay_elements_by_the_specified_time_but_not_more() + public async Task Flow_InitialDelay_must_delay_elements_by_the_specified_time_but_not_more() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.From(Enumerable.Range(1, 10)) .InitialDelay(TimeSpan.FromSeconds(2)) @@ -58,9 +59,9 @@ public void Flow_InitialDelay_must_delay_elements_by_the_specified_time_but_not_ } [Fact] - public void Flow_InitialDelay_must_properly_ignore_timer_while_backpressured() + public async Task Flow_InitialDelay_must_properly_ignore_timer_while_backpressured() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateSubscriberProbe(); Source.From(Enumerable.Range(1, 10)) diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowInterleaveSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowInterleaveSpec.cs index 049acefa83c..8e594628bf2 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowInterleaveSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowInterleaveSpec.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -32,9 +33,9 @@ protected override TestSubscriber.Probe Setup(IPublisher p1, IPublishe } [Fact] - public void An_Interleave_for_Flow_must_work_in_the_happy_case() + public async Task An_Interleave_for_Flow_must_work_in_the_happy_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateManualSubscriberProbe(); @@ -58,9 +59,9 @@ public void An_Interleave_for_Flow_must_work_in_the_happy_case() } [Fact] - public void An_Interleave_for_Flow_must_work_when_segmentSize_is_not_equal_elements_in_stream() + public async Task An_Interleave_for_Flow_must_work_when_segmentSize_is_not_equal_elements_in_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateManualSubscriberProbe(); @@ -75,9 +76,9 @@ public void An_Interleave_for_Flow_must_work_when_segmentSize_is_not_equal_eleme } [Fact] - public void An_Interleave_for_Flow_must_work_with_segmentSize_1() + public async Task An_Interleave_for_Flow_must_work_with_segmentSize_1() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateManualSubscriberProbe(); @@ -92,9 +93,9 @@ public void An_Interleave_for_Flow_must_work_with_segmentSize_1() } [Fact] - public void An_Interleave_for_Flow_must_not_work_with_segmentSize_0() + public async Task An_Interleave_for_Flow_must_not_work_with_segmentSize_0() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var source = Source.From(Enumerable.Range(0, 3)); source.Invoking(s => s.Interleave(Source.From(Enumerable.Range(3, 3)), 0)) @@ -103,9 +104,9 @@ public void An_Interleave_for_Flow_must_not_work_with_segmentSize_0() } [Fact] - public void An_Interleave_for_Flow_must_work_when_segmentSize_is_greater_than_stream_elements() + public async Task An_Interleave_for_Flow_must_work_when_segmentSize_is_greater_than_stream_elements() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateManualSubscriberProbe(); Source.From(Enumerable.Range(0, 3)) @@ -130,9 +131,9 @@ public void An_Interleave_for_Flow_must_work_when_segmentSize_is_greater_than_st } [Fact] - public void An_Interleave_for_Flow_must_work_with_one_immediately_completed_and_one_nonempty_publisher() + public async Task An_Interleave_for_Flow_must_work_with_one_immediately_completed_and_one_nonempty_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber1 = Setup(CompletedPublisher(), NonEmptyPublisher(Enumerable.Range(1, 4))); var subscription1 = subscriber1.ExpectSubscription(); @@ -150,9 +151,9 @@ public void An_Interleave_for_Flow_must_work_with_one_immediately_completed_and_ } [Fact] - public void An_Interleave_for_Flow_must_work_with_one_delayed_completed_and_one_nonempty_publisher() + public async Task An_Interleave_for_Flow_must_work_with_one_delayed_completed_and_one_nonempty_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber1 = Setup(SoonToCompletePublisher(), NonEmptyPublisher(Enumerable.Range(1, 4))); var subscription1 = subscriber1.ExpectSubscription(); @@ -209,9 +210,9 @@ public void An_Interleave_for_Flow_must_work_with_one_delayed_failed_and_one_non } [Fact] - public void An_Interleave_for_Flow_must_pass_along_early_cancellation() + public async Task An_Interleave_for_Flow_must_pass_along_early_cancellation() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var up1 = this.CreateManualPublisherProbe(); var up2 = this.CreateManualPublisherProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowIteratorSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowIteratorSpec.cs index 252c64a455d..b0bad88fbb8 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowIteratorSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowIteratorSpec.cs @@ -9,6 +9,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Akka.Pattern; using Akka.Streams.Dsl; using Akka.Streams.TestKit; @@ -146,9 +147,9 @@ protected AbstractFlowIteratorSpec(ITestOutputHelper helper) : base(helper) protected abstract Source CreateSource(int elements); [Fact] - public void A_Flow_based_on_an_iterable_must_produce_elements() + public async Task A_Flow_based_on_an_iterable_must_produce_elements() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = CreateSource(3).RunWith(Sink.AsPublisher(false), Materializer); var c = this.CreateManualSubscriberProbe(); @@ -167,9 +168,9 @@ public void A_Flow_based_on_an_iterable_must_produce_elements() } [Fact] - public void A_Flow_based_on_an_iterable_must_complete_empty() + public async Task A_Flow_based_on_an_iterable_must_complete_empty() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = CreateSource(0).RunWith(Sink.AsPublisher(false), Materializer); var c = this.CreateManualSubscriberProbe(); @@ -181,9 +182,9 @@ public void A_Flow_based_on_an_iterable_must_complete_empty() } [Fact] - public void A_Flow_based_on_an_iterable_must_produce_elements_with_multiple_subscribers() + public async Task A_Flow_based_on_an_iterable_must_produce_elements_with_multiple_subscribers() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = CreateSource(3).RunWith(Sink.AsPublisher(true), Materializer); var c1 = this.CreateManualSubscriberProbe(); @@ -211,9 +212,9 @@ public void A_Flow_based_on_an_iterable_must_produce_elements_with_multiple_subs } [Fact] - public void A_Flow_based_on_an_iterable_must_produce_elements_to_later_subscriber() + public async Task A_Flow_based_on_an_iterable_must_produce_elements_to_later_subscriber() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = CreateSource(3).RunWith(Sink.AsPublisher(true), Materializer); var c1 = this.CreateManualSubscriberProbe(); @@ -241,9 +242,9 @@ public void A_Flow_based_on_an_iterable_must_produce_elements_to_later_subscribe } [Fact] - public void A_Flow_based_on_an_iterable_must_produce_elements_with_one_transformation_step() + public async Task A_Flow_based_on_an_iterable_must_produce_elements_with_one_transformation_step() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = CreateSource(3) .Select(x => x*2) @@ -262,9 +263,9 @@ public void A_Flow_based_on_an_iterable_must_produce_elements_with_one_transform } [Fact] - public void A_Flow_based_on_an_iterable_must_produce_elements_with_two_transformation_steps() + public async Task A_Flow_based_on_an_iterable_must_produce_elements_with_two_transformation_steps() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = CreateSource(4) .Where(x => x%2 == 0) @@ -283,9 +284,9 @@ public void A_Flow_based_on_an_iterable_must_produce_elements_with_two_transform } [Fact] - public void A_Flow_based_on_an_iterable_must_not_produce_after_cancel() + public async Task A_Flow_based_on_an_iterable_must_not_produce_after_cancel() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = CreateSource(3).RunWith(Sink.AsPublisher(false), Materializer); var c = this.CreateManualSubscriberProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowJoinSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowJoinSpec.cs index 2583f3bba4b..435462ec239 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowJoinSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowJoinSpec.cs @@ -31,9 +31,9 @@ public FlowJoinSpec(ITestOutputHelper helper) : base(helper) } [Fact] - public void A_Flow_using_Join_must_allow_for_cycles() + public async Task A_Flow_using_Join_must_allow_for_cycles() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { const int end = 47; var t = Enumerable.Range(0, end + 1).GroupBy(i => i%2 == 0).ToList(); @@ -72,9 +72,9 @@ public void A_Flow_using_Join_must_allow_for_cycles() } [Fact] - public void A_Flow_using_Join_must_allow_for_merge_cycle() + public async Task A_Flow_using_Join_must_allow_for_merge_cycle() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var source = Source.Single("lonely traveler").MapMaterializedValue(_ => Task.FromResult("")); @@ -97,9 +97,9 @@ public void A_Flow_using_Join_must_allow_for_merge_cycle() } [Fact] - public void A_Flow_using_Join_must_allow_for_merge_preferred_cycle() + public async Task A_Flow_using_Join_must_allow_for_merge_preferred_cycle() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var source = Source.Single("lonely traveler").MapMaterializedValue(_ => Task.FromResult("")); @@ -122,9 +122,9 @@ public void A_Flow_using_Join_must_allow_for_merge_preferred_cycle() } [Fact] - public void A_Flow_using_Join_must_allow_for_zip_cycle() + public async Task A_Flow_using_Join_must_allow_for_zip_cycle() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var source = Source.From(new[] {"traveler1", "traveler2"}) .MapMaterializedValue>(_ => null); @@ -158,9 +158,9 @@ public void A_Flow_using_Join_must_allow_for_zip_cycle() } [Fact] - public void A_Flow_using_Join_must_allow_for_concat_cycle() + public async Task A_Flow_using_Join_must_allow_for_concat_cycle() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var flow = Flow.FromGraph(GraphDsl.Create(TestSource.SourceProbe(this), Sink.First(), Keep.Both, (b, source, sink) => { @@ -184,9 +184,9 @@ public void A_Flow_using_Join_must_allow_for_concat_cycle() } [Fact] - public void A_Flow_using_Join_must_allow_for_interleave_cycle() + public async Task A_Flow_using_Join_must_allow_for_interleave_cycle() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var source = Source.Single("lonely traveler").MapMaterializedValue(_ => Task.FromResult("")); var flow = Flow.FromGraph(GraphDsl.Create(Sink.First(), (b, sink) => diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowKillSwitchSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowKillSwitchSpec.cs index 214e30a27d8..58e23983f3e 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowKillSwitchSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowKillSwitchSpec.cs @@ -9,6 +9,7 @@ using System; using System.Linq; using System.Threading; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -132,9 +133,9 @@ public void A_UniqueKillSwitch_must_ignore_completion_after_already_completed() #region shared kill switch [Fact] - public void A_SharedKillSwitch_must_stop_a_stream_if_requested() + public async Task A_SharedKillSwitch_must_stop_a_stream_if_requested() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var killSwitch = KillSwitches.Shared("switch"); @@ -156,9 +157,9 @@ public void A_SharedKillSwitch_must_stop_a_stream_if_requested() } [Fact] - public void A_SharedKillSwitch_must_fail_a_stream_if_requested() + public async Task A_SharedKillSwitch_must_fail_a_stream_if_requested() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var killSwitch = KillSwitches.Shared("switch"); @@ -181,9 +182,9 @@ public void A_SharedKillSwitch_must_fail_a_stream_if_requested() } [Fact] - public void A_SharedKillSwitch_must_pass_through_all_elements_unmodified() + public async Task A_SharedKillSwitch_must_pass_through_all_elements_unmodified() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var killSwitch = KillSwitches.Shared("switch"); var task = Source.From(Enumerable.Range(1, 100)) @@ -195,9 +196,9 @@ public void A_SharedKillSwitch_must_pass_through_all_elements_unmodified() } [Fact] - public void A_SharedKillSwitch_must_provide_a_flow_that_if_materialized_multiple_times_with_multiple_types_stops_all_streams_if_requested() + public async Task A_SharedKillSwitch_must_provide_a_flow_that_if_materialized_multiple_times_with_multiple_types_stops_all_streams_if_requested() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var killSwitch = KillSwitches.Shared("switch"); @@ -233,9 +234,9 @@ public void A_SharedKillSwitch_must_provide_a_flow_that_if_materialized_multiple } [Fact] - public void A_SharedKillSwitch_must_provide_a_flow_that_if_materialized_multiple_times_with_multiple_types_fails_all_streams_if_requested() + public async Task A_SharedKillSwitch_must_provide_a_flow_that_if_materialized_multiple_times_with_multiple_types_fails_all_streams_if_requested() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var killSwitch = KillSwitches.Shared("switch"); @@ -272,9 +273,9 @@ public void A_SharedKillSwitch_must_provide_a_flow_that_if_materialized_multiple } [Fact] - public void A_SharedKillSwitch_must_ignore_subsequent_aborts_and_shutdowns_after_shutdown() + public async Task A_SharedKillSwitch_must_ignore_subsequent_aborts_and_shutdowns_after_shutdown() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var killSwitch = KillSwitches.Shared("switch"); @@ -304,9 +305,9 @@ public void A_SharedKillSwitch_must_ignore_subsequent_aborts_and_shutdowns_after } [Fact] - public void A_SharedKillSwitch_must_ignore_subsequent_aborts_and_shutdowns_after_abort() + public async Task A_SharedKillSwitch_must_ignore_subsequent_aborts_and_shutdowns_after_abort() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var killSwitch = KillSwitches.Shared("switch"); @@ -337,9 +338,9 @@ public void A_SharedKillSwitch_must_ignore_subsequent_aborts_and_shutdowns_after } [Fact] - public void A_SharedKillSwitch_must_complete_immediately_flows_materialized_after_switch_shutdown() + public async Task A_SharedKillSwitch_must_complete_immediately_flows_materialized_after_switch_shutdown() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var killSwitch = KillSwitches.Shared("switch"); killSwitch.Shutdown(); @@ -357,9 +358,9 @@ public void A_SharedKillSwitch_must_complete_immediately_flows_materialized_afte } [Fact] - public void A_SharedKillSwitch_must_fail_immediately_flows_materialized_after_switch_failure() + public async Task A_SharedKillSwitch_must_fail_immediately_flows_materialized_after_switch_failure() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var killSwitch = KillSwitches.Shared("switch"); var testException = new TestException("Abort"); @@ -378,9 +379,9 @@ public void A_SharedKillSwitch_must_fail_immediately_flows_materialized_after_sw } [Fact] - public void A_SharedKillSwitch_should_not_cause_problems_if_switch_is_shutdown_after_flow_completed_normally() + public async Task A_SharedKillSwitch_should_not_cause_problems_if_switch_is_shutdown_after_flow_completed_normally() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var killSwitch = KillSwitches.Shared("switch"); var task = Source.From(Enumerable.Range(1, 10)) @@ -393,9 +394,9 @@ public void A_SharedKillSwitch_should_not_cause_problems_if_switch_is_shutdown_a } [Fact] - public void A_SharedKillSwitch_must_provide_flows_that_materialize_to_its_owner_KillSwitch() + public async Task A_SharedKillSwitch_must_provide_flows_that_materialize_to_its_owner_KillSwitch() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var killSwitch = KillSwitches.Shared("switch"); var t = Source.Maybe() @@ -413,9 +414,9 @@ public void A_SharedKillSwitch_must_provide_flows_that_materialize_to_its_owner_ } [Fact] - public void A_SharedKillSwitch_must_not_affect_streams_corresponding_to_another_KillSwitch() + public async Task A_SharedKillSwitch_must_not_affect_streams_corresponding_to_another_KillSwitch() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var killSwitch1 = KillSwitches.Shared("switch"); var killSwitch2 = KillSwitches.Shared("switch"); @@ -458,9 +459,9 @@ public void A_SharedKillSwitch_must_not_affect_streams_corresponding_to_another_ } [Fact] - public void A_SharedKillSwitch_must_allow_using_multiple_KillSwitch_in_one_graph() + public async Task A_SharedKillSwitch_must_allow_using_multiple_KillSwitch_in_one_graph() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var killSwitch1 = KillSwitches.Shared("switch"); var killSwitch2 = KillSwitches.Shared("switch"); @@ -489,9 +490,9 @@ public void A_SharedKillSwitch_must_allow_using_multiple_KillSwitch_in_one_graph } [Fact] - public void A_SharedKillSwitch_must_use_its_name_on_the_flows_it_hands_out() + public async Task A_SharedKillSwitch_must_use_its_name_on_the_flows_it_hands_out() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var killSwitch = KillSwitches.Shared("MySwitchName"); killSwitch.ToString().Should().Be("KillSwitch(MySwitchName)"); @@ -504,9 +505,9 @@ public void A_SharedKillSwitch_must_use_its_name_on_the_flows_it_hands_out() #region cancellable kill switch [Fact] - public void A_CancellationToken_flow_must_stop_a_stream_if_requested() + public async Task A_CancellationToken_flow_must_stop_a_stream_if_requested() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var cancel = new CancellationTokenSource(); @@ -528,9 +529,9 @@ public void A_CancellationToken_flow_must_stop_a_stream_if_requested() } [Fact] - public void A_CancellationToken_flow_must_fail_a_stream_if_requested() + public async Task A_CancellationToken_flow_must_fail_a_stream_if_requested() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var cancel = new CancellationTokenSource(); @@ -552,9 +553,9 @@ public void A_CancellationToken_flow_must_fail_a_stream_if_requested() } [Fact] - public void A_CancellationToken_flow_must_pass_through_all_elements_unmodified() + public async Task A_CancellationToken_flow_must_pass_through_all_elements_unmodified() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var cancel = new CancellationTokenSource(); var task = Source.From(Enumerable.Range(1, 100)) @@ -566,9 +567,9 @@ public void A_CancellationToken_flow_must_pass_through_all_elements_unmodified() } [Fact] - public void A_CancellationToken_flow_must_provide_a_flow_that_if_materialized_multiple_times_with_multiple_types_stops_all_streams_if_requested() + public async Task A_CancellationToken_flow_must_provide_a_flow_that_if_materialized_multiple_times_with_multiple_types_stops_all_streams_if_requested() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var cancel = new CancellationTokenSource(); @@ -604,9 +605,9 @@ public void A_CancellationToken_flow_must_provide_a_flow_that_if_materialized_mu } [Fact] - public void A_CancellationToken_flow_must_provide_a_flow_that_if_materialized_multiple_times_with_multiple_types_fails_all_streams_if_requested() + public async Task A_CancellationToken_flow_must_provide_a_flow_that_if_materialized_multiple_times_with_multiple_types_fails_all_streams_if_requested() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var cancel = new CancellationTokenSource(); @@ -642,9 +643,9 @@ public void A_CancellationToken_flow_must_provide_a_flow_that_if_materialized_mu } [Fact] - public void A_CancellationToken_flow_must_ignore_subsequent_aborts_and_shutdowns_after_shutdown() + public async Task A_CancellationToken_flow_must_ignore_subsequent_aborts_and_shutdowns_after_shutdown() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var cancel = new CancellationTokenSource(); @@ -674,9 +675,9 @@ public void A_CancellationToken_flow_must_ignore_subsequent_aborts_and_shutdowns } [Fact] - public void A_CancellationToken_flow_must_complete_immediately_flows_materialized_after_switch_shutdown() + public async Task A_CancellationToken_flow_must_complete_immediately_flows_materialized_after_switch_shutdown() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var cancel = new CancellationTokenSource(); cancel.Cancel(); @@ -694,9 +695,9 @@ public void A_CancellationToken_flow_must_complete_immediately_flows_materialize } [Fact] - public void A_CancellationToken_flow_must_fail_immediately_flows_materialized_after_switch_failure() + public async Task A_CancellationToken_flow_must_fail_immediately_flows_materialized_after_switch_failure() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var cancel = new CancellationTokenSource(); cancel.Cancel(); @@ -714,9 +715,9 @@ public void A_CancellationToken_flow_must_fail_immediately_flows_materialized_af } [Fact] - public void A_CancellationToken_flow_should_not_cause_problems_if_switch_is_shutdown_after_flow_completed_normally() + public async Task A_CancellationToken_flow_should_not_cause_problems_if_switch_is_shutdown_after_flow_completed_normally() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var cancel = new CancellationTokenSource(); var task = Source.From(Enumerable.Range(1, 10)) diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowMergeSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowMergeSpec.cs index 333e1042254..1d1ed76004a 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowMergeSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowMergeSpec.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -31,9 +32,9 @@ protected override TestSubscriber.Probe Setup(IPublisher p1, IPublishe } [Fact] - public void A_Merge_for_Flow_must_work_in_the_happy_case() + public async Task A_Merge_for_Flow_must_work_in_the_happy_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { // Different input size (4 and 6) var source1 = Source.From(Enumerable.Range(0, 4)); @@ -64,9 +65,9 @@ public void A_Merge_for_Flow_must_work_in_the_happy_case() } [Fact] - public void A_Merge_for_Flow_must_work_with_one_immediately_completed_and_one_nonempty_publisher() + public async Task A_Merge_for_Flow_must_work_with_one_immediately_completed_and_one_nonempty_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber1 = Setup(CompletedPublisher(), NonEmptyPublisher(Enumerable.Range(1,4))); var subscription1 = subscriber1.EnsureSubscription(); @@ -83,9 +84,9 @@ public void A_Merge_for_Flow_must_work_with_one_immediately_completed_and_one_no } [Fact] - public void A_Merge_for_Flow_must_work_with_one_delayed_completed_and_one_nonempty_publisher() + public async Task A_Merge_for_Flow_must_work_with_one_delayed_completed_and_one_nonempty_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber1 = Setup(SoonToCompletePublisher(), NonEmptyPublisher(Enumerable.Range(1, 4))); var subscription1 = subscriber1.EnsureSubscription(); @@ -112,9 +113,9 @@ public void A_Merge_for_Flow_must_work_with_one_delayed_failed_an_one_nonempty_p } [Fact] - public void A_Merge_for_Flow_must_pass_along_early_cancellation() + public async Task A_Merge_for_Flow_must_pass_along_early_cancellation() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var up1 = this.CreateManualPublisherProbe(); var up2 = this.CreateManualPublisherProbe(); @@ -139,9 +140,9 @@ public void A_Merge_for_Flow_must_pass_along_early_cancellation() } [Fact] - public void A_Merge_for_Flow_must_not_try_to_grab_from_closed_input_previously_enqueued() + public async Task A_Merge_for_Flow_must_not_try_to_grab_from_closed_input_previously_enqueued() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var up1 = this.CreatePublisherProbe(); var up2 = this.CreatePublisherProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowMonitorSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowMonitorSpec.cs index 43f74d0c10f..6e7c0204e1a 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowMonitorSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowMonitorSpec.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -26,7 +27,7 @@ public FlowMonitorSpec(ITestOutputHelper helper) : base(helper) } [Fact] - public void A_FlowMonitor_must_return_Finished_when_stream_is_completed() + public async Task A_FlowMonitor_must_return_Finished_when_stream_is_completed() { var t = this.SourceProbe() .Monitor(Keep.Both) @@ -36,7 +37,7 @@ public void A_FlowMonitor_must_return_Finished_when_stream_is_completed() var monitor = t.Item1.Item2; var sink = t.Item2; source.SendComplete(); - AwaitAssert(() => + await AwaitAssertAsync(() => { if(monitor.State != FlowMonitor.Finished.Instance) throw new Exception(); @@ -46,7 +47,7 @@ public void A_FlowMonitor_must_return_Finished_when_stream_is_completed() } [Fact] - public void A_FlowMonitor_must_return_Finished_when_stream_is_cancelled_from_downstream() + public async Task A_FlowMonitor_must_return_Finished_when_stream_is_cancelled_from_downstream() { var t = this.SourceProbe() .Monitor(Keep.Right) @@ -56,7 +57,7 @@ public void A_FlowMonitor_must_return_Finished_when_stream_is_cancelled_from_dow var sink = t.Item2; sink.Cancel(); - AwaitAssert(() => + await AwaitAssertAsync(() => { if (monitor.State != FlowMonitor.Finished.Instance) throw new Exception(); @@ -64,7 +65,7 @@ public void A_FlowMonitor_must_return_Finished_when_stream_is_cancelled_from_dow } [Fact] - public void A_FlowMonitor_must_return_Failed_when_stream_fails_and_propagate_the_error() + public async Task A_FlowMonitor_must_return_Failed_when_stream_fails_and_propagate_the_error() { var t = this.SourceProbe() .Monitor(Keep.Both) @@ -75,7 +76,7 @@ public void A_FlowMonitor_must_return_Failed_when_stream_fails_and_propagate_the var sink = t.Item2; var ex = new TestException("Source failed"); source.SendError(ex); - AwaitAssert(() => + await AwaitAssertAsync(() => { var state = monitor.State as FlowMonitor.Failed; if(state != null && ReferenceEquals(state.Cause, ex)) @@ -87,7 +88,7 @@ public void A_FlowMonitor_must_return_Failed_when_stream_fails_and_propagate_the } [Fact] - public void A_FlowMonitor_must_return_Initialized_for_an_empty_stream() + public async Task A_FlowMonitor_must_return_Initialized_for_an_empty_stream() { var t = this.SourceProbe() .Monitor(Keep.Both) @@ -97,7 +98,7 @@ public void A_FlowMonitor_must_return_Initialized_for_an_empty_stream() var monitor = t.Item1.Item2; var sink = t.Item2; - AwaitAssert(() => + await AwaitAssertAsync(() => { if (monitor.State != FlowMonitor.Initialized.Instance) throw new Exception(); @@ -107,7 +108,7 @@ public void A_FlowMonitor_must_return_Initialized_for_an_empty_stream() } [Fact] - public void A_FlowMonitor_must_return_Received_after_receiving_a_message() + public async Task A_FlowMonitor_must_return_Received_after_receiving_a_message() { var t = this.SourceProbe() .Monitor(Keep.Both) @@ -119,7 +120,7 @@ public void A_FlowMonitor_must_return_Received_after_receiving_a_message() var message = 42; source.SendNext(message); sink.RequestNext(message); - AwaitAssert(() => + await AwaitAssertAsync(() => { var state = monitor.State as FlowMonitor.Received; if (state != null && state.Message == 42) @@ -132,7 +133,7 @@ public void A_FlowMonitor_must_return_Received_after_receiving_a_message() // Check a stream that processes StreamState messages specifically, to make sure the optimization in FlowMonitorImpl // (to avoid allocating an object for each message) doesn't introduce a bug [Fact] - public void A_FlowMonitor_must_return_Received_after_receiving_a_StreamState_message() + public async Task A_FlowMonitor_must_return_Received_after_receiving_a_StreamState_message() { var t = this.SourceProbe>() .Monitor(Keep.Both) @@ -144,7 +145,7 @@ public void A_FlowMonitor_must_return_Received_after_receiving_a_StreamState_mes var message = new FlowMonitor.Received("message"); source.SendNext(message); sink.RequestNext(message); - AwaitAssert(() => + await AwaitAssertAsync(() => { var state = monitor.State as FlowMonitor.Received>; if (state != null && state.Message == message) @@ -155,7 +156,7 @@ public void A_FlowMonitor_must_return_Received_after_receiving_a_StreamState_mes } [Fact] - public void A_FlowMonitor_must_return_failed_when_stream_is_abruptly_terminated() + public async Task A_FlowMonitor_must_return_failed_when_stream_is_abruptly_terminated() { var materializer = ActorMaterializer.Create(Sys); @@ -163,7 +164,7 @@ public void A_FlowMonitor_must_return_failed_when_stream_is_abruptly_terminated( var monitor = t.Item2; materializer.Shutdown(); - AwaitAssert(() => monitor.State.Should().BeOfType(), RemainingOrDefault); + await AwaitAssertAsync(() => monitor.State.Should().BeOfType(), RemainingOrDefault); } } } diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowOnCompleteSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowOnCompleteSpec.cs index 4bf4a653afb..044a5bf5e5b 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowOnCompleteSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowOnCompleteSpec.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System; +using System.Threading.Tasks; using Akka.Actor; using Akka.Streams.Dsl; using Akka.Streams.TestKit; @@ -26,9 +27,9 @@ public FlowOnCompleteSpec(ITestOutputHelper helper) : base(helper) } [Fact] - public void A_Flow_with_OnComplete_must_invoke_callback_on_normal_completion() + public async Task A_Flow_with_OnComplete_must_invoke_callback_on_normal_completion() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var onCompleteProbe = CreateTestProbe(); var p = this.CreateManualPublisherProbe(); @@ -45,9 +46,9 @@ public void A_Flow_with_OnComplete_must_invoke_callback_on_normal_completion() } [Fact] - public void A_Flow_with_OnComplete_must_yield_the_first_error() + public async Task A_Flow_with_OnComplete_must_yield_the_first_error() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var onCompleteProbe = CreateTestProbe(); var p = this.CreateManualPublisherProbe(); @@ -64,9 +65,9 @@ public void A_Flow_with_OnComplete_must_yield_the_first_error() } [Fact] - public void A_Flow_with_OnComplete_must_invoke_callback_for_an_empty_stream() + public async Task A_Flow_with_OnComplete_must_invoke_callback_for_an_empty_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var onCompleteProbe = CreateTestProbe(); var p = this.CreateManualPublisherProbe(); @@ -82,9 +83,9 @@ public void A_Flow_with_OnComplete_must_invoke_callback_for_an_empty_stream() } [Fact] - public void A_Flow_with_OnComplete_must_invoke_callback_after_transform_and_foreach_steps() + public async Task A_Flow_with_OnComplete_must_invoke_callback_after_transform_and_foreach_steps() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var onCompleteProbe = CreateTestProbe(); var p = this.CreateManualPublisherProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowPrefixAndTailSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowPrefixAndTailSpec.cs index a1ae9eba380..dbfbeab3955 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowPrefixAndTailSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowPrefixAndTailSpec.cs @@ -40,9 +40,9 @@ private static [Fact] - public void PrefixAndTail_must_work_on_empty_input() + public async Task PrefixAndTail_must_work_on_empty_input() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var futureSink = NewHeadSink; var fut = Source.Empty().PrefixAndTail(10).RunWith(futureSink, Materializer); @@ -55,9 +55,9 @@ public void PrefixAndTail_must_work_on_empty_input() } [Fact] - public void PrefixAndTail_must_work_on_short_inputs() + public async Task PrefixAndTail_must_work_on_short_inputs() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var futureSink = NewHeadSink; var fut = Source.From(new [] {1,2,3}).PrefixAndTail(10).RunWith(futureSink, Materializer); @@ -71,9 +71,9 @@ public void PrefixAndTail_must_work_on_short_inputs() } [Fact] - public void PrefixAndTail_must_work_on_longer_inputs() + public async Task PrefixAndTail_must_work_on_longer_inputs() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var futureSink = NewHeadSink; var fut = Source.From(Enumerable.Range(1, 10)).PrefixAndTail(5).RunWith(futureSink, Materializer); @@ -90,9 +90,9 @@ public void PrefixAndTail_must_work_on_longer_inputs() } [Fact] - public void PrefixAndTail_must_handle_zero_take_count() + public async Task PrefixAndTail_must_handle_zero_take_count() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var futureSink = NewHeadSink; var fut = Source.From(Enumerable.Range(1, 10)).PrefixAndTail(0).RunWith(futureSink, Materializer); @@ -108,9 +108,9 @@ public void PrefixAndTail_must_handle_zero_take_count() } [Fact] - public void PrefixAndTail_must_handle_negative_take_count() + public async Task PrefixAndTail_must_handle_negative_take_count() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var futureSink = NewHeadSink; var fut = Source.From(Enumerable.Range(1, 10)).PrefixAndTail(-1).RunWith(futureSink, Materializer); @@ -126,9 +126,9 @@ public void PrefixAndTail_must_handle_negative_take_count() } [Fact] - public void PrefixAndTail_must_work_if_size_of_tak_is_equal_to_stream_size() + public async Task PrefixAndTail_must_work_if_size_of_tak_is_equal_to_stream_size() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var futureSink = NewHeadSink; var fut = Source.From(Enumerable.Range(1,10)).PrefixAndTail(10).RunWith(futureSink, Materializer); @@ -142,9 +142,9 @@ public void PrefixAndTail_must_work_if_size_of_tak_is_equal_to_stream_size() } [Fact] - public void PrefixAndTail_must_throw_if_tail_is_attempted_to_be_materialized_twice() + public async Task PrefixAndTail_must_throw_if_tail_is_attempted_to_be_materialized_twice() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var futureSink = NewHeadSink; var fut = Source.From(Enumerable.Range(1, 2)).PrefixAndTail(1).RunWith(futureSink, Materializer); @@ -166,9 +166,9 @@ public void PrefixAndTail_must_throw_if_tail_is_attempted_to_be_materialized_twi } [Fact] - public void PrefixAndTail_must_signal_error_if_substream_has_been_not_subscribed_in_time() + public async Task PrefixAndTail_must_signal_error_if_substream_has_been_not_subscribed_in_time() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var ms = 300; @@ -195,9 +195,9 @@ public void PrefixAndTail_must_signal_error_if_substream_has_been_not_subscribed } [Fact] - public void PrefixAndTail_must_not_fail_the_stream_if_substream_has_not_been_subscribed_in_time_and_configured_subscription_timeout_is_noop() + public async Task PrefixAndTail_must_not_fail_the_stream_if_substream_has_not_been_subscribed_in_time_and_configured_subscription_timeout_is_noop() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var settings = ActorMaterializerSettings.Create(Sys) .WithSubscriptionTimeoutSettings( @@ -220,9 +220,9 @@ public void PrefixAndTail_must_not_fail_the_stream_if_substream_has_not_been_sub } [Fact] - public void PrefixAndTail_must_shut_down_main_stage_if_substream_is_empty_even_when_not_subscribed() + public async Task PrefixAndTail_must_shut_down_main_stage_if_substream_is_empty_even_when_not_subscribed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var futureSink = NewHeadSink; var fut = Source.Single(1).PrefixAndTail(1).RunWith(futureSink, Materializer); @@ -232,9 +232,9 @@ public void PrefixAndTail_must_shut_down_main_stage_if_substream_is_empty_even_w } [Fact] - public void PrefixAndTail_must_handle_OnError_when_no_substream_is_open() + public async Task PrefixAndTail_must_handle_OnError_when_no_substream_is_open() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisher = this.CreateManualPublisherProbe(); var subscriber = this.CreateManualSubscriberProbe<(IImmutableList, Source)>(); @@ -258,9 +258,9 @@ public void PrefixAndTail_must_handle_OnError_when_no_substream_is_open() } [Fact] - public void PrefixAndTail_must_handle_OnError_when_substream_is_open() + public async Task PrefixAndTail_must_handle_OnError_when_substream_is_open() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisher = this.CreateManualPublisherProbe(); var subscriber = this.CreateManualSubscriberProbe<(IImmutableList, Source)>(); @@ -292,9 +292,9 @@ public void PrefixAndTail_must_handle_OnError_when_substream_is_open() } [Fact] - public void PrefixAndTail_must_handle_master_stream_cancellation() + public async Task PrefixAndTail_must_handle_master_stream_cancellation() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisher = this.CreateManualPublisherProbe(); var subscriber = this.CreateManualSubscriberProbe<(IImmutableList, Source)>(); @@ -318,9 +318,9 @@ public void PrefixAndTail_must_handle_master_stream_cancellation() } [Fact] - public void PrefixAndTail_must_handle_substream_cancellation() + public async Task PrefixAndTail_must_handle_substream_cancellation() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisher = this.CreateManualPublisherProbe(); var subscriber = this.CreateManualSubscriberProbe<(IImmutableList, Source)>(); @@ -352,9 +352,9 @@ public void PrefixAndTail_must_handle_substream_cancellation() } [Fact] - public void PrefixAndTail_must_pass_along_early_cancellation() + public async Task PrefixAndTail_must_pass_along_early_cancellation() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var up = this.CreateManualPublisherProbe(); var down = this.CreateManualSubscriberProbe<(IImmutableList, Source)>(); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowRecoverSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowRecoverSpec.cs index 3351b461f9c..cbe96c42ae3 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowRecoverSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowRecoverSpec.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -31,9 +32,9 @@ public FlowRecoverSpec(ITestOutputHelper helper) : base(helper) private static readonly TestException Ex = new TestException("test"); [Fact] - public void A_Recover_must_recover_when_there_is_a_handler() + public async Task A_Recover_must_recover_when_there_is_a_handler() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 4)).Select(x => { @@ -53,9 +54,9 @@ public void A_Recover_must_recover_when_there_is_a_handler() } [Fact] - public void A_Recover_must_failed_stream_if_handler_is_not_for_such_exception_type() + public async Task A_Recover_must_failed_stream_if_handler_is_not_for_such_exception_type() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 3)).Select(x => { @@ -72,9 +73,9 @@ public void A_Recover_must_failed_stream_if_handler_is_not_for_such_exception_ty } [Fact] - public void A_Recover_must_not_influence_stream_when_there_is_no_exception() + public async Task A_Recover_must_not_influence_stream_when_there_is_no_exception() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 3)) .Select(x => x) @@ -87,9 +88,9 @@ public void A_Recover_must_not_influence_stream_when_there_is_no_exception() } [Fact] - public void A_Recover_must_finish_stream_if_it_is_empty() + public async Task A_Recover_must_finish_stream_if_it_is_empty() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.Empty() .Select(x => x) diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowRecoverWithSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowRecoverWithSpec.cs index 464d9fcafd7..a1eacba5043 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowRecoverWithSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowRecoverWithSpec.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.Stage; using Akka.Streams.TestKit; @@ -31,9 +32,9 @@ public FlowRecoverWithSpec(ITestOutputHelper helper) : base(helper) private static readonly TestException Ex = new TestException("test"); [Fact] - public void A_RecoverWith_must_recover_when_there_is_a_handler() + public async Task A_RecoverWith_must_recover_when_there_is_a_handler() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = Source.From(Enumerable.Range(1, 4)).Select(x => { @@ -59,9 +60,9 @@ public void A_RecoverWith_must_recover_when_there_is_a_handler() } [Fact] - public void A_RecoverWith_must_cancel_substream_if_parent_is_terminated_when_there_is_a_handler() + public async Task A_RecoverWith_must_cancel_substream_if_parent_is_terminated_when_there_is_a_handler() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = Source.From(Enumerable.Range(1, 4)).Select(x => { @@ -83,9 +84,9 @@ public void A_RecoverWith_must_cancel_substream_if_parent_is_terminated_when_the } [Fact] - public void A_RecoverWith_must_failed_stream_if_handler_is_not_for_such_exception_type() + public async Task A_RecoverWith_must_failed_stream_if_handler_is_not_for_such_exception_type() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = Source.From(Enumerable.Range(1, 3)).Select(x => { @@ -105,9 +106,9 @@ public void A_RecoverWith_must_failed_stream_if_handler_is_not_for_such_exceptio } [Fact] - public void A_RecoverWith_must_be_able_to_recover_with_the_same_unmaterialized_source_if_configured() + public async Task A_RecoverWith_must_be_able_to_recover_with_the_same_unmaterialized_source_if_configured() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var src = Source.From(Enumerable.Range(1, 3)).Select(x => { @@ -134,9 +135,9 @@ public void A_RecoverWith_must_be_able_to_recover_with_the_same_unmaterialized_s } [Fact] - public void A_RecoverWith_must_not_influence_stream_when_there_is_no_exception() + public async Task A_RecoverWith_must_not_influence_stream_when_there_is_no_exception() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 3)) .Select(x => x) @@ -149,9 +150,9 @@ public void A_RecoverWith_must_not_influence_stream_when_there_is_no_exception() } [Fact] - public void A_RecoverWith_must_finish_stream_if_it_is_empty() + public async Task A_RecoverWith_must_finish_stream_if_it_is_empty() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.Empty() .Select(x => x) @@ -163,9 +164,9 @@ public void A_RecoverWith_must_finish_stream_if_it_is_empty() } [Fact] - public void A_RecoverWith_must_switch_the_second_time_if_alternative_source_throws_exception() + public async Task A_RecoverWith_must_switch_the_second_time_if_alternative_source_throws_exception() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = Source.From(Enumerable.Range(1, 3)).Select(x => { @@ -202,9 +203,9 @@ public void A_RecoverWith_must_switch_the_second_time_if_alternative_source_thro } [Fact] - public void A_RecoverWith_must_terminate_with_exception_if_partial_function_fails_to_match_after_an_alternative_source_failure() + public async Task A_RecoverWith_must_terminate_with_exception_if_partial_function_fails_to_match_after_an_alternative_source_failure() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = Source.From(Enumerable.Range(1, 3)) .Select(x => @@ -241,9 +242,9 @@ public void A_RecoverWith_must_terminate_with_exception_if_partial_function_fail } [Fact] - public void A_RecoverWith_must_terminate_with_exception_after_set_number_of_retries() + public async Task A_RecoverWith_must_terminate_with_exception_after_set_number_of_retries() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = Source.From(Enumerable.Range(1, 3)) .Select(x => @@ -270,9 +271,9 @@ public void A_RecoverWith_must_terminate_with_exception_after_set_number_of_retr } [Fact] - public void A_RecoverWith_must_throw_ArgumentException_if_number_of_retries_is_less_than_minus_one() + public async Task A_RecoverWith_must_throw_ArgumentException_if_number_of_retries_is_less_than_minus_one() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Flow.Create() .Invoking(f => f.RecoverWithRetries(exception => Source.Empty(), -2)) @@ -281,9 +282,9 @@ public void A_RecoverWith_must_throw_ArgumentException_if_number_of_retries_is_l } [Fact] - public void A_RecoverWith_must_fail_correctly_when_materialization_of_recover_source_fails() + public async Task A_RecoverWith_must_fail_correctly_when_materialization_of_recover_source_fails() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var matFail = new TestException("fail!"); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowScanSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowScanSpec.cs index 0599862e22d..748b0c6f304 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowScanSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowScanSpec.cs @@ -45,7 +45,7 @@ private IEnumerable Scan(Source source, TimeSpan? duration = } [Fact] - public void A_Scan_must_Scan() + public async Task A_Scan_must_Scan() { Func scan = source => { @@ -58,7 +58,7 @@ public void A_Scan_must_Scan() return result; }; - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var random = new Random(); var v = Enumerable.Range(1, random.Next(100, 1000)).Select(_ => random.Next()).ToArray(); @@ -67,9 +67,9 @@ public void A_Scan_must_Scan() } [Fact] - public void A_Scan_must_Scan_empty_failed() + public async Task A_Scan_must_Scan_empty_failed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var error = new TestException("fail!"); Action fail = () => Scan(Source.Failed(error)); @@ -78,8 +78,8 @@ public void A_Scan_must_Scan_empty_failed() } [Fact] - public void A_Scan_must_Scan_empty() => - this.AssertAllStagesStopped(() => Scan(Source.Empty()).ShouldAllBeEquivalentTo(new[] {0}), Materializer); + public async Task A_Scan_must_Scan_empty() => + await this.AssertAllStagesStoppedAsync(() => Scan(Source.Empty()).ShouldAllBeEquivalentTo(new[] {0}), Materializer); [Fact] public void A_Scan_must_emit_values_promptly() diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowSelectAsyncSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowSelectAsyncSpec.cs index be2a1399628..9a7002a2601 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowSelectAsyncSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowSelectAsyncSpec.cs @@ -40,9 +40,9 @@ public FlowSelectAsyncSpec(ITestOutputHelper helper) : base(helper) } [Fact] - public void A_Flow_with_SelectAsync_must_produce_task_elements() + public async Task A_Flow_with_SelectAsync_must_produce_task_elements() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c = this.CreateManualSubscriberProbe(); Source.From(Enumerable.Range(1, 3)) @@ -113,9 +113,9 @@ public void A_Flow_with_SelectAsync_must_not_run_more_futures_than_requested_par } [Fact(Skip = "Racy on Azure DevOps")] - public void A_Flow_with_SelectAsync_must_signal_task_failure() + public async Task A_Flow_with_SelectAsync_must_signal_task_failure() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var latch = new TestLatch(1); var c = this.CreateManualSubscriberProbe(); @@ -137,9 +137,9 @@ public void A_Flow_with_SelectAsync_must_signal_task_failure() } [Fact] - public void A_Flow_with_SelectAsync_must_signal_task_failure_asap() + public async Task A_Flow_with_SelectAsync_must_signal_task_failure_asap() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var latch = CreateTestLatch(); var done = Source.From(Enumerable.Range(1, 5)) @@ -168,9 +168,9 @@ public void A_Flow_with_SelectAsync_must_signal_task_failure_asap() } [Fact] - public void A_Flow_with_SelectAsync_must_signal_error_from_SelectAsync() + public async Task A_Flow_with_SelectAsync_must_signal_error_from_SelectAsync() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var latch = new TestLatch(1); var c = this.CreateManualSubscriberProbe(); @@ -195,11 +195,11 @@ public void A_Flow_with_SelectAsync_must_signal_error_from_SelectAsync() } [Fact] - public void A_Flow_with_SelectAsync_must_resume_after_task_failure() + public async Task A_Flow_with_SelectAsync_must_resume_after_task_failure() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(async () => { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c = this.CreateManualSubscriberProbe(); Source.From(Enumerable.Range(1, 5)) @@ -220,9 +220,9 @@ public void A_Flow_with_SelectAsync_must_resume_after_task_failure() } [Fact] - public void A_Flow_with_SelectAsync_must_resume_after_multiple_failures() + public async Task A_Flow_with_SelectAsync_must_resume_after_multiple_failures() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var futures = new[] { @@ -245,9 +245,9 @@ public void A_Flow_with_SelectAsync_must_resume_after_multiple_failures() } [Fact] - public void A_Flow_with_SelectAsync_must_finish_after_task_failure() + public async Task A_Flow_with_SelectAsync_must_finish_after_task_failure() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = Source.From(Enumerable.Range(1, 3)) .SelectAsync(1, n => Task.Run(() => @@ -313,9 +313,9 @@ public void A_Flow_with_SelectAsync_must_resume_when_task_is_completed_with_null } [Fact] - public void A_Flow_with_SelectAsync_must_handle_cancel_properly() + public async Task A_Flow_with_SelectAsync_must_handle_cancel_properly() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var pub = this.CreateManualPublisherProbe(); var sub = this.CreateManualSubscriberProbe(); @@ -334,9 +334,9 @@ public void A_Flow_with_SelectAsync_must_handle_cancel_properly() } [Fact(Skip = "Racy on AzureDevOps")] - public void A_Flow_with_SelectAsync_must_not_run_more_futures_than_configured() + public async Task A_Flow_with_SelectAsync_must_not_run_more_futures_than_configured() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { const int parallelism = 8; var counter = new AtomicCounter(); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowSelectAsyncUnorderedSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowSelectAsyncUnorderedSpec.cs index 28294e81bf2..03cefa606f0 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowSelectAsyncUnorderedSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowSelectAsyncUnorderedSpec.cs @@ -39,9 +39,9 @@ public FlowSelectAsyncUnorderedSpec(ITestOutputHelper helper) : base(helper) } [Fact] - public void A_Flow_with_SelectAsyncUnordered_must_produce_task_elements_in_the_order_they_are_ready() + public async Task A_Flow_with_SelectAsyncUnordered_must_produce_task_elements_in_the_order_they_are_ready() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c = this.CreateManualSubscriberProbe(); var latch = Enumerable.Range(0, 4).Select(_ => new TestLatch(1)).ToArray(); @@ -111,9 +111,9 @@ public void A_Flow_with_SelectAsyncUnordered_must_not_run_more_futures_than_requ } [Fact] - public void A_Flow_with_SelectAsyncUnordered_must_signal_task_failure() + public async Task A_Flow_with_SelectAsyncUnordered_must_signal_task_failure() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var latch = new TestLatch(1); var c = this.CreateManualSubscriberProbe(); @@ -136,9 +136,9 @@ public void A_Flow_with_SelectAsyncUnordered_must_signal_task_failure() [Fact] - public void A_Flow_with_SelectAsyncUnordered_must_signal_task_failure_asap() + public async Task A_Flow_with_SelectAsyncUnordered_must_signal_task_failure_asap() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var latch = CreateTestLatch(); var done = Source.From(Enumerable.Range(1, 5)) @@ -168,9 +168,9 @@ public void A_Flow_with_SelectAsyncUnordered_must_signal_task_failure_asap() } [Fact] - public void A_Flow_with_SelectAsyncUnordered_must_signal_error_from_SelectAsyncUnordered() + public async Task A_Flow_with_SelectAsyncUnordered_must_signal_error_from_SelectAsyncUnordered() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var latch = new TestLatch(1); var c = this.CreateManualSubscriberProbe(); @@ -195,11 +195,11 @@ public void A_Flow_with_SelectAsyncUnordered_must_signal_error_from_SelectAsyncU } [Fact] - public void A_Flow_with_SelectAsyncUnordered_must_resume_after_task_failure() + public async Task A_Flow_with_SelectAsyncUnordered_must_resume_after_task_failure() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(async () => { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 5)) .SelectAsyncUnordered(4, n => Task.Run(() => @@ -218,9 +218,9 @@ public void A_Flow_with_SelectAsyncUnordered_must_resume_after_task_failure() } [Fact] - public void A_Flow_with_SelectAsyncUnordered_must_resume_after_multiple_failures() + public async Task A_Flow_with_SelectAsyncUnordered_must_resume_after_multiple_failures() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var futures = new[] { @@ -242,9 +242,9 @@ public void A_Flow_with_SelectAsyncUnordered_must_resume_after_multiple_failures } [Fact] - public void A_Flow_with_SelectAsyncUnordered_must_finish_after_task_failure() + public async Task A_Flow_with_SelectAsyncUnordered_must_finish_after_task_failure() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = Source.From(Enumerable.Range(1, 3)) .SelectAsyncUnordered(1, n => Task.Run(() => @@ -308,9 +308,9 @@ public void A_Flow_with_SelectAsyncUnordered_must_resume_when_task_is_completed_ } [Fact] - public void A_Flow_with_SelectAsyncUnordered_must_handle_cancel_properly() + public async Task A_Flow_with_SelectAsyncUnordered_must_handle_cancel_properly() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var pub = this.CreateManualPublisherProbe(); var sub = this.CreateManualSubscriberProbe(); @@ -329,9 +329,9 @@ public void A_Flow_with_SelectAsyncUnordered_must_handle_cancel_properly() } [Fact(Skip = "Racy on AzureDevOps")] - public void A_Flow_with_SelectAsyncUnordered_must_not_run_more_futures_than_configured() + public async Task A_Flow_with_SelectAsyncUnordered_must_not_run_more_futures_than_configured() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { const int parallelism = 8; var counter = new AtomicCounter(); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowSelectErrorSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowSelectErrorSpec.cs index 7a62fb4ffce..23879f415f7 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowSelectErrorSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowSelectErrorSpec.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -31,9 +32,9 @@ public FlowSelectErrorSpec() public ActorMaterializer Materializer { get; } [Fact] - public void A_SelectError_must_select_when_there_is_a_handler() + public async Task A_SelectError_must_select_when_there_is_a_handler() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 3)) .Select(ThrowOnTwo) @@ -46,9 +47,9 @@ public void A_SelectError_must_select_when_there_is_a_handler() } [Fact] - public void A_SelectError_must_fail_the_stream_with_exception_thrown_in_handler_and_log_it() + public async Task A_SelectError_must_fail_the_stream_with_exception_thrown_in_handler_and_log_it() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 3)) .Select(ThrowOnTwo) @@ -78,9 +79,9 @@ public void A_SelectError_must_pass_through_the_original_exception_if_function_d } [Fact] - public void A_SelectError_must_not_influence_stream_when_there_is_no_exceptions() + public async Task A_SelectError_must_not_influence_stream_when_there_is_no_exceptions() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 3)) .Select(x => x) @@ -94,9 +95,9 @@ public void A_SelectError_must_not_influence_stream_when_there_is_no_exceptions( } [Fact] - public void A_SelectError_must_finish_stream_if_it_is_empty() + public async Task A_SelectError_must_finish_stream_if_it_is_empty() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.Empty() .Select(x => x) diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowSkipWhileSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowSkipWhileSpec.cs index bbb3957260a..77e72c862be 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowSkipWhileSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowSkipWhileSpec.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.Supervision; using Akka.Streams.TestKit; @@ -28,9 +29,9 @@ public FlowSkipWhileSpec(ITestOutputHelper helper) : base(helper) } [Fact] - public void A_SkipWhile_must_skip_while_predicate_is_true() + public async Task A_SkipWhile_must_skip_while_predicate_is_true() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 4)) .SkipWhile(x => x < 3) @@ -42,9 +43,9 @@ public void A_SkipWhile_must_skip_while_predicate_is_true() } [Fact] - public void A_SkipWhile_must_complete_the_future_for_an_empty_stream() + public async Task A_SkipWhile_must_complete_the_future_for_an_empty_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.Empty() .SkipWhile(x => x < 2) @@ -55,9 +56,9 @@ public void A_SkipWhile_must_complete_the_future_for_an_empty_stream() } [Fact] - public void A_SkipWhile_must_continue_if_error() + public async Task A_SkipWhile_must_continue_if_error() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 4)).SkipWhile(x => { @@ -73,9 +74,9 @@ public void A_SkipWhile_must_continue_if_error() } [Fact] - public void A_SkipWhile_must_restart_with_strategy() + public async Task A_SkipWhile_must_restart_with_strategy() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 4)).SkipWhile(x => { diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowSlidingSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowSlidingSpec.cs index 586532f2121..b2069044fc7 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowSlidingSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowSlidingSpec.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Akka.Actor; using Akka.Streams.Dsl; using Akka.Streams.TestKit.Tests; @@ -84,9 +85,9 @@ private static List> Sliding(List source, int win, int step) } [Fact] - public void Sliding_must_behave_just_like_collections_sliding_with_step_lower_than_window() + public async Task Sliding_must_behave_just_like_collections_sliding_with_step_lower_than_window() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var random = new Random(); var gen = Enumerable.Range(1, 1000) @@ -101,9 +102,9 @@ public void Sliding_must_behave_just_like_collections_sliding_with_step_lower_th } [Fact] - public void Sliding_must_behave_just_like_collections_sliding_with_step_equals_window() + public async Task Sliding_must_behave_just_like_collections_sliding_with_step_equals_window() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var random = new Random(); var gen = Enumerable.Range(1, 1000) @@ -118,9 +119,9 @@ public void Sliding_must_behave_just_like_collections_sliding_with_step_equals_w } [Fact] - public void Sliding_must_behave_just_like_collections_sliding_with_step_greater_than_window() + public async Task Sliding_must_behave_just_like_collections_sliding_with_step_greater_than_window() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var random = new Random(); var gen = Enumerable.Range(1, 1000) @@ -135,9 +136,9 @@ public void Sliding_must_behave_just_like_collections_sliding_with_step_greater_ } [Fact] - public void Sliding_must_work_with_empty_sources() + public async Task Sliding_must_work_with_empty_sources() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.Empty().Sliding(1).RunForeach(ints => TestActor.Tell(ints), Materializer) .ContinueWith(t => diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowSpec.cs index 5d4f5e9a94d..d0b15d59543 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowSpec.cs @@ -10,6 +10,7 @@ using System.Collections.Immutable; using System.Linq; using System.Threading; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.Pattern; @@ -263,9 +264,9 @@ public void A_Flow_must_perform_transformation_operation_and_subscribe_Subscribe } [Fact] - public void A_Flow_must_be_materializable_several_times_with_fanout_publisher() + public async Task A_Flow_must_be_materializable_several_times_with_fanout_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var flow = Source.From(new[] {1, 2, 3}).Select(i => i.ToString()); var p1 = flow.RunWith(Sink.AsPublisher(true), Materializer); @@ -301,7 +302,7 @@ public void A_Flow_must_be_materializable_several_times_with_fanout_publisher() } [Fact] - public void A_Flow_must_be_covariant() + public async Task A_Flow_must_be_covariant() { Source f1 = Source.From(Apples()); IPublisher p1 = Source.From(Apples()).RunWith(Sink.AsPublisher(false), Materializer); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowSplitAfterSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowSplitAfterSpec.cs index 896625afa68..a21e660234c 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowSplitAfterSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowSplitAfterSpec.cs @@ -11,6 +11,7 @@ using System.Collections.Immutable; using System.Linq; using System.Threading; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.Implementation; using Akka.Streams.TestKit; @@ -87,9 +88,9 @@ private void WithSubstreamsSupport(int splitAfter = 3, int elementCount = 6, } [Fact] - public void SplitAfter_must_work_in_the_happy_case() + public async Task SplitAfter_must_work_in_the_happy_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { WithSubstreamsSupport(3,5,run: (masterSubscriber, masterSubscription, expectSubFlow) => { @@ -117,9 +118,9 @@ public void SplitAfter_must_work_in_the_happy_case() } [Fact] - public void SplitAfter_must_work_when_first_element_is_split_by() + public async Task SplitAfter_must_work_when_first_element_is_split_by() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { WithSubstreamsSupport(1, 3, run: (masterSubscriber, masterSubscription, expectSubFlow) => { @@ -143,9 +144,9 @@ public void SplitAfter_must_work_when_first_element_is_split_by() } [Fact] - public void SplitAfter_must_work_with_single_element_splits_by() + public async Task SplitAfter_must_work_with_single_element_splits_by() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.From(Enumerable.Range(1, 10)) .SplitAfter(_ => true) @@ -159,9 +160,9 @@ public void SplitAfter_must_work_with_single_element_splits_by() } [Fact] - public void SplitAfter_must_support_cancelling_substreams() + public async Task SplitAfter_must_support_cancelling_substreams() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { WithSubstreamsSupport(5, 8, run: (masterSubscriber, masterSubscription, expectSubFlow) => { @@ -180,9 +181,9 @@ public void SplitAfter_must_support_cancelling_substreams() } [Fact] - public void SplitAfter_must_fail_stream_when_SplitAfter_function_throws() + public async Task SplitAfter_must_fail_stream_when_SplitAfter_function_throws() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisherProbe = this.CreateManualPublisherProbe(); var ex = new TestException("test"); @@ -220,18 +221,18 @@ public void SplitAfter_must_fail_stream_when_SplitAfter_function_throws() } [Fact(Skip = "Supervision is not supported fully by GraphStages yet")] - public void SplitAfter_must_resume_stream_when_SplitAfter_function_throws() + public async Task SplitAfter_must_resume_stream_when_SplitAfter_function_throws() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { }, Materializer); } [Fact] - public void SplitAfter_must_pass_along_early_cancellation() + public async Task SplitAfter_must_pass_along_early_cancellation() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var up = this.CreateManualPublisherProbe(); var down = this.CreateManualSubscriberProbe>(); @@ -251,9 +252,9 @@ public void SplitAfter_must_pass_along_early_cancellation() } [Fact] - public void SplitAfter_must_support_eager_cancellation_of_master_stream_on_cancelling_substreams() + public async Task SplitAfter_must_support_eager_cancellation_of_master_stream_on_cancelling_substreams() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { WithSubstreamsSupport(5,8,SubstreamCancelStrategy.Propagate, (masterSubscriber, masterSubscription, expectSubFlow) => @@ -267,7 +268,7 @@ public void SplitAfter_must_support_eager_cancellation_of_master_stream_on_cance } [Fact] - public void SplitAfter_should_work_when_last_element_is_split_by() => this.AssertAllStagesStopped(() => + public async Task SplitAfter_should_work_when_last_element_is_split_by() => await this.AssertAllStagesStoppedAsync(() => { WithSubstreamsSupport(splitAfter: 3, elementCount: 3, run: (masterSubscriber, masterSubscription, expectSubFlow) => @@ -288,7 +289,7 @@ public void SplitAfter_should_work_when_last_element_is_split_by() => this.Asser }, Materializer); [Fact] - public void SplitAfter_should_fail_stream_if_substream_not_materialized_in_time() => this.AssertAllStagesStopped(() => + public async Task SplitAfter_should_fail_stream_if_substream_not_materialized_in_time() => await this.AssertAllStagesStoppedAsync(() => { var timeout = new StreamSubscriptionTimeoutSettings(StreamSubscriptionTimeoutTerminationMode.CancelTermination, TimeSpan.FromMilliseconds(500)); var settings = ActorMaterializerSettings.Create(Sys).WithSubscriptionTimeoutSettings(timeout); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowSplitWhenSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowSplitWhenSpec.cs index 547ef80345c..bc9ba22f0a2 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowSplitWhenSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowSplitWhenSpec.cs @@ -85,9 +85,9 @@ private void WithSubstreamsSupport(int splitWhen = 3, int elementCount = 6, } [Fact] - public void SplitWhen_must_work_in_the_happy_case() + public async Task SplitWhen_must_work_in_the_happy_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { WithSubstreamsSupport(elementCount: 4, run: (masterSubscriber, masterSubscription, getSubFlow) => { @@ -119,9 +119,9 @@ public void SplitWhen_must_work_in_the_happy_case() } [Fact] - public void SplitWhen_must_not_emit_substreams_if_the_parent_stream_is_empty() + public async Task SplitWhen_must_not_emit_substreams_if_the_parent_stream_is_empty() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.Empty() @@ -137,9 +137,9 @@ public void SplitWhen_must_not_emit_substreams_if_the_parent_stream_is_empty() } [Fact] - public void SplitWhen_must_work_when_first_element_is_split_by() + public async Task SplitWhen_must_work_when_first_element_is_split_by() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { WithSubstreamsSupport(1, 3, run: (masterSubscriber, masterSubscription, getSubFlow) => { @@ -158,9 +158,9 @@ public void SplitWhen_must_work_when_first_element_is_split_by() } [Fact] - public void SplitWhen_must_support_cancelling_substreams() + public async Task SplitWhen_must_support_cancelling_substreams() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { WithSubstreamsSupport(5, 8, run: (masterSubscriber, masterSubscription, getSubFlow) => { @@ -183,9 +183,9 @@ public void SplitWhen_must_support_cancelling_substreams() } [Fact] - public void SplitWhen_must_support_cancelling_both_master_and_substream() + public async Task SplitWhen_must_support_cancelling_both_master_and_substream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var inputs = this.CreatePublisherProbe(); @@ -253,9 +253,9 @@ public void SplitWhen_must_support_cancelling_both_master_and_substream() } [Fact] - public void SplitWhen_must_support_cancelling_the_master_stream() + public async Task SplitWhen_must_support_cancelling_the_master_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { WithSubstreamsSupport(5, 8, run: (masterSubscriber, masterSubscription, getSubFlow) => { @@ -274,9 +274,9 @@ public void SplitWhen_must_support_cancelling_the_master_stream() } [Fact] - public void SplitWhen_must_fail_stream_when_SplitWhen_function_throws() + public async Task SplitWhen_must_fail_stream_when_SplitWhen_function_throws() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisherProbe = this.CreateManualPublisherProbe(); var ex = new TestException("test"); @@ -314,9 +314,9 @@ public void SplitWhen_must_fail_stream_when_SplitWhen_function_throws() } [Fact] - public void SplitWhen_must_work_with_single_element_splits() + public async Task SplitWhen_must_work_with_single_element_splits() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.From(Enumerable.Range(1, 100)) .SplitWhen(_ => true) @@ -330,9 +330,9 @@ public void SplitWhen_must_work_with_single_element_splits() } [Fact] - public void SplitWhen_must_fail_substream_if_materialized_twice() + public async Task SplitWhen_must_fail_substream_if_materialized_twice() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.Single(1).SplitWhen(_ => true).Lift() .SelectAsync(1, source => @@ -352,9 +352,9 @@ public void SplitWhen_must_fail_substream_if_materialized_twice() } [Fact] - public void SplitWhen_must_fail_stream_if_substream_not_materialized_in_time() + public async Task SplitWhen_must_fail_stream_if_substream_not_materialized_in_time() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var tightTimeoutMaterializer = ActorMaterializer.Create(Sys, ActorMaterializerSettings.Create(Sys) @@ -383,18 +383,18 @@ public void SplitWhen_must_fail_stream_if_substream_not_materialized_in_time() } [Fact(Skip = "Supervision is not supported fully by GraphStages yet")] - public void SplitWhen_must_resume_stream_when_splitWhen_function_throws() + public async Task SplitWhen_must_resume_stream_when_splitWhen_function_throws() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { }, Materializer); } [Fact] - public void SplitWhen_must_pass_along_early_cancellation() + public async Task SplitWhen_must_pass_along_early_cancellation() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var up = this.CreateManualPublisherProbe(); var down = this.CreateManualSubscriberProbe>(); @@ -414,9 +414,9 @@ public void SplitWhen_must_pass_along_early_cancellation() } [Fact] - public void SplitWhen_must_support_eager_cancellation_of_master_stream_on_cancelling_substreams() + public async Task SplitWhen_must_support_eager_cancellation_of_master_stream_on_cancelling_substreams() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { WithSubstreamsSupport(5, 8, SubstreamCancelStrategy.Propagate, (masterSubscriber, masterSubscription, expectSubFlow) => diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowSumSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowSumSpec.cs index 756506853a5..10647565866 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowSumSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowSumSpec.cs @@ -42,9 +42,9 @@ private static Flow SumFlow private static Sink> SumSink => Sink.Sum((i, i1) => i + i1); [Fact] - public void A_Sum_must_work_when_using_Source_RunSum() + public async Task A_Sum_must_work_when_using_Source_RunSum() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = InputSource.RunSum((i, i1) => i + i1, Materializer); t.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue(); @@ -53,9 +53,9 @@ public void A_Sum_must_work_when_using_Source_RunSum() } [Fact] - public void A_Sum_must_work_when_using_Source_Sum() + public async Task A_Sum_must_work_when_using_Source_Sum() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = SumSource.RunWith(Sink.First(), Materializer); t.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue(); @@ -63,9 +63,9 @@ public void A_Sum_must_work_when_using_Source_Sum() }, Materializer); } [Fact] - public void A_Sum_must_work_when_using_Sink_Sum() + public async Task A_Sum_must_work_when_using_Sink_Sum() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = InputSource.RunWith(SumSink, Materializer); t.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue(); @@ -75,9 +75,9 @@ public void A_Sum_must_work_when_using_Sink_Sum() } [Fact] - public void A_Sum_must_work_when_using_Flow_Sum() + public async Task A_Sum_must_work_when_using_Flow_Sum() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = InputSource.Via(SumFlow).RunWith(Sink.First(), Materializer); t.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue(); @@ -86,9 +86,9 @@ public void A_Sum_must_work_when_using_Flow_Sum() } [Fact] - public void A_Sum_must_work_when_using_Source_Sum_and_Flow_Sum_and_Sink_Sum() + public async Task A_Sum_must_work_when_using_Source_Sum_and_Flow_Sum_and_Sink_Sum() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = SumSource.Via(SumFlow).RunWith(SumSink, Materializer); t.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue(); @@ -98,9 +98,9 @@ public void A_Sum_must_work_when_using_Source_Sum_and_Flow_Sum_and_Sink_Sum() } [Fact] - public void A_Sum_must_propagate_an_error() + public async Task A_Sum_must_propagate_an_error() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var error = new TestException("test"); var task = InputSource.Select(x => @@ -115,9 +115,9 @@ public void A_Sum_must_propagate_an_error() } [Fact] - public void A_Sum_must_complete_task_with_failure_when_reduce_function_throws_and_the_supervisor_strategy_decides_to_stop() + public async Task A_Sum_must_complete_task_with_failure_when_reduce_function_throws_and_the_supervisor_strategy_decides_to_stop() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var error = new TestException("test"); var task = InputSource.RunSum((x, y) => @@ -132,9 +132,9 @@ public void A_Sum_must_complete_task_with_failure_when_reduce_function_throws_an } [Fact] - public void A_Sum_must_resume_with_the_accumulated_state_when_the_reduce_funtion_throws_and_the_supervisor_strategy_decides_to_resume() + public async Task A_Sum_must_resume_with_the_accumulated_state_when_the_reduce_funtion_throws_and_the_supervisor_strategy_decides_to_resume() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var error = new Exception("boom"); var sum = Sink.Sum((int x, int y) => @@ -152,9 +152,9 @@ public void A_Sum_must_resume_with_the_accumulated_state_when_the_reduce_funtion } [Fact] - public void A_Aggregate_must_resume_and_reset_the_state_when_the_reduce_funtion_throws_and_the_supervisor_strategy_decides_to_restart() + public async Task A_Aggregate_must_resume_and_reset_the_state_when_the_reduce_funtion_throws_and_the_supervisor_strategy_decides_to_restart() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var error = new Exception("boom"); var sum = Sink.Sum((int x, int y) => @@ -172,9 +172,9 @@ public void A_Aggregate_must_resume_and_reset_the_state_when_the_reduce_funtion_ } [Fact] - public void A_Sum_must_fail_on_Empty_stream_using_Source_RunSum() + public async Task A_Sum_must_fail_on_Empty_stream_using_Source_RunSum() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var result = Source.Empty().RunSum((i, i1) => i + i1, Materializer); result.Invoking(t => t.Wait(TimeSpan.FromSeconds(3))) @@ -185,9 +185,9 @@ public void A_Sum_must_fail_on_Empty_stream_using_Source_RunSum() } [Fact] - public void A_Sum_must_fail_on_Empty_stream_using_Flow_Sum() + public async Task A_Sum_must_fail_on_Empty_stream_using_Flow_Sum() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var result = Source.Empty() .Via(SumFlow) @@ -200,9 +200,9 @@ public void A_Sum_must_fail_on_Empty_stream_using_Flow_Sum() } [Fact] - public void A_Sum_must_fail_on_Empty_stream_using_Sink_Sum() + public async Task A_Sum_must_fail_on_Empty_stream_using_Sink_Sum() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var result = Source.Empty() .RunWith(SumSink, Materializer); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowTakeWhileSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowTakeWhileSpec.cs index da509280e1a..e1d15206ef3 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowTakeWhileSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowTakeWhileSpec.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.Supervision; using Akka.Streams.TestKit; @@ -28,9 +29,9 @@ public FlowTakeWhileSpec(ITestOutputHelper helper) : base(helper) } [Fact] - public void A_TakeWhile_must_take_while_predicate_is_true() + public async Task A_TakeWhile_must_take_while_predicate_is_true() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 4)) .TakeWhile(i => i < 3) @@ -42,9 +43,9 @@ public void A_TakeWhile_must_take_while_predicate_is_true() } [Fact] - public void A_TakeWhile_must_complete_the_future_for_an_empty_stream() + public async Task A_TakeWhile_must_complete_the_future_for_an_empty_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.Empty() .TakeWhile(i => i < 2) @@ -55,9 +56,9 @@ public void A_TakeWhile_must_complete_the_future_for_an_empty_stream() } [Fact] - public void A_TakeWhile_must_continue_if_error() + public async Task A_TakeWhile_must_continue_if_error() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var testException = new Exception("test"); @@ -76,9 +77,9 @@ public void A_TakeWhile_must_continue_if_error() } [Fact] - public void A_TakeWhile_must_emit_the_element_that_caused_the_predicate_to_return_false_and_then_no_more_with_inclusive_set() + public async Task A_TakeWhile_must_emit_the_element_that_caused_the_predicate_to_return_false_and_then_no_more_with_inclusive_set() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 10)) .TakeWhile(i => i < 3, true) diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowTakeWithinSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowTakeWithinSpec.cs index 589f2b6c7b7..4b5d511bc0d 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowTakeWithinSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowTakeWithinSpec.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -52,9 +53,9 @@ public void A_TakeWithin_must_deliver_elements_within_the_duration_but_not_after } [Fact] - public void A_TakeWithin_must_deliver_buffered_elements_OnComplete_before_the_timeout() + public async Task A_TakeWithin_must_deliver_buffered_elements_OnComplete_before_the_timeout() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c = this.CreateManualSubscriberProbe(); Source.From(Enumerable.Range(1, 3)) diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowThrottleSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowThrottleSpec.cs index 257cac6d1ca..e37d6a76e68 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowThrottleSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowThrottleSpec.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Akka.IO; using Akka.Streams.Actors; using Akka.Streams.Dsl; @@ -45,9 +46,9 @@ private static ByteString GenerateByteString(int length) } [Fact] - public void Throttle_for_single_cost_elements_must_work_for_the_happy_case() + public async Task Throttle_for_single_cost_elements_must_work_for_the_happy_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 5)) .Throttle(1, TimeSpan.FromMilliseconds(100), 0, ThrottleMode.Shaping) @@ -59,9 +60,9 @@ public void Throttle_for_single_cost_elements_must_work_for_the_happy_case() } [Fact] - public void Throttle_for_single_cost_elements_must_accept_very_high_rates() + public async Task Throttle_for_single_cost_elements_must_accept_very_high_rates() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 5)) .Throttle(1, TimeSpan.FromTicks(1), 0, ThrottleMode.Shaping) @@ -73,9 +74,9 @@ public void Throttle_for_single_cost_elements_must_accept_very_high_rates() } [Fact] - public void Throttle_for_single_cost_elements_must_accept_very_low_rates() + public async Task Throttle_for_single_cost_elements_must_accept_very_low_rates() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = Source.From(Enumerable.Range(1, 5)) .Throttle(1, TimeSpan.FromDays(100), 1, ThrottleMode.Shaping) @@ -110,9 +111,9 @@ public void Throttle_for_single_cost_elements_must_() } [Fact] - public void Throttle_for_single_cost_elements_must_emit_single_element_per_tick() + public async Task Throttle_for_single_cost_elements_must_emit_single_element_per_tick() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstream = this.CreatePublisherProbe(); var downstream = this.CreateSubscriberProbe(); @@ -136,9 +137,9 @@ public void Throttle_for_single_cost_elements_must_emit_single_element_per_tick( } [Fact] - public void Throttle_for_single_cost_elements_must_not_send_downstream_if_upstream_does_not_emit_element() + public async Task Throttle_for_single_cost_elements_must_not_send_downstream_if_upstream_does_not_emit_element() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstream = this.CreatePublisherProbe(); var downstream = this.CreateSubscriberProbe(); @@ -161,9 +162,9 @@ public void Throttle_for_single_cost_elements_must_not_send_downstream_if_upstre } [Fact] - public void Throttle_for_single_cost_elements_must_cancel_when_downstream_cancels() + public async Task Throttle_for_single_cost_elements_must_cancel_when_downstream_cancels() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var downstream = this.CreateSubscriberProbe(); Source.From(Enumerable.Range(1, 10)) @@ -174,9 +175,9 @@ public void Throttle_for_single_cost_elements_must_cancel_when_downstream_cancel } [Fact] - public void Throttle_for_single_cost_elements_must_send_elements_downstream_as_soon_as_time_comes() + public async Task Throttle_for_single_cost_elements_must_send_elements_downstream_as_soon_as_time_comes() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = Source.From(Enumerable.Range(1, 10)) @@ -195,9 +196,9 @@ public void Throttle_for_single_cost_elements_must_send_elements_downstream_as_s } [Fact] - public void Throttle_for_single_cost_elements_must_burst_according_to_its_maximum_if_enough_time_passed() + public async Task Throttle_for_single_cost_elements_must_burst_according_to_its_maximum_if_enough_time_passed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var ms = TimeSpan.FromMilliseconds(300); var upstream = this.CreatePublisherProbe(); @@ -237,9 +238,9 @@ public void Throttle_for_single_cost_elements_must_burst_according_to_its_maximu } [Fact] - public void Throttle_for_single_cost_elements_must_burst_some_elements_if_have_enough_time() + public async Task Throttle_for_single_cost_elements_must_burst_some_elements_if_have_enough_time() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstream = this.CreatePublisherProbe(); var downstream = this.CreateSubscriberProbe(); @@ -279,9 +280,9 @@ public void Throttle_for_single_cost_elements_must_burst_some_elements_if_have_e } [Fact] - public void Throttle_for_single_cost_elements_must_throw_exception_when_exceeding_throughtput_in_enforced_mode() + public async Task Throttle_for_single_cost_elements_must_throw_exception_when_exceeding_throughtput_in_enforced_mode() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t1 = Source.From(Enumerable.Range(1, 5)) @@ -299,9 +300,9 @@ public void Throttle_for_single_cost_elements_must_throw_exception_when_exceedin } [Fact] - public void Throttle_for_single_cost_elements_must_properly_combine_shape_and_throttle_modes() + public async Task Throttle_for_single_cost_elements_must_properly_combine_shape_and_throttle_modes() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 5)) .Throttle(1, TimeSpan.FromMilliseconds(100), 5, ThrottleMode.Shaping) @@ -316,9 +317,9 @@ public void Throttle_for_single_cost_elements_must_properly_combine_shape_and_th [Fact] - public void Throttle_for_various_cost_elements_must_work_for_the_happy_case() + public async Task Throttle_for_various_cost_elements_must_work_for_the_happy_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 5)) .Throttle(1, TimeSpan.FromMilliseconds(100), 0, _ => 1, ThrottleMode.Shaping) @@ -330,9 +331,9 @@ public void Throttle_for_various_cost_elements_must_work_for_the_happy_case() } [Fact] - public void Throttle_for_various_cost_elements_must_emit_elements_according_to_cost() + public async Task Throttle_for_various_cost_elements_must_emit_elements_according_to_cost() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var list = Enumerable.Range(1, 4).Select(x => x*2).Select(GenerateByteString).ToList(); @@ -352,9 +353,9 @@ public void Throttle_for_various_cost_elements_must_emit_elements_according_to_c } [Fact] - public void Throttle_for_various_cost_elements_must_not_send_downstream_if_upstream_does_not_emit_element() + public async Task Throttle_for_various_cost_elements_must_not_send_downstream_if_upstream_does_not_emit_element() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstream = this.CreatePublisherProbe(); var downstream = this.CreateSubscriberProbe(); @@ -377,9 +378,9 @@ public void Throttle_for_various_cost_elements_must_not_send_downstream_if_upstr } [Fact] - public void Throttle_for_various_cost_elements_must_cancel_when_downstream_cancels() + public async Task Throttle_for_various_cost_elements_must_cancel_when_downstream_cancels() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var downstream = this.CreateSubscriberProbe(); Source.From(Enumerable.Range(1, 10)) @@ -390,9 +391,9 @@ public void Throttle_for_various_cost_elements_must_cancel_when_downstream_cance } [Fact] - public void Throttle_for_various_cost_elements_must_send_elements_downstream_as_soon_as_time_comes() + public async Task Throttle_for_various_cost_elements_must_send_elements_downstream_as_soon_as_time_comes() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = Source.From(Enumerable.Range(1, 10)) @@ -411,9 +412,9 @@ public void Throttle_for_various_cost_elements_must_send_elements_downstream_as_ } [Fact] - public void Throttle_for_various_cost_elements_must_burst_according_to_its_maximum_if_enough_time_passed() + public async Task Throttle_for_various_cost_elements_must_burst_according_to_its_maximum_if_enough_time_passed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstream = this.CreatePublisherProbe(); var downstream = this.CreateSubscriberProbe(); @@ -453,9 +454,9 @@ public void Throttle_for_various_cost_elements_must_burst_according_to_its_maxim } [Fact] - public void Throttle_for_various_cost_elements_must_burst_some_elements_if_have_enough_time() + public async Task Throttle_for_various_cost_elements_must_burst_some_elements_if_have_enough_time() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstream = this.CreatePublisherProbe(); var downstream = this.CreateSubscriberProbe(); @@ -496,9 +497,9 @@ public void Throttle_for_various_cost_elements_must_burst_some_elements_if_have_ } [Fact] - public void Throttle_for_various_cost_elements_must_throw_exception_when_exceeding_throughtput_in_enforced_mode() + public async Task Throttle_for_various_cost_elements_must_throw_exception_when_exceeding_throughtput_in_enforced_mode() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t1 = Source.From(Enumerable.Range(1, 4)) @@ -516,9 +517,9 @@ public void Throttle_for_various_cost_elements_must_throw_exception_when_exceedi } [Fact] - public void Throttle_for_various_cost_elements_must_properly_combine_shape_and_enforce_modes() + public async Task Throttle_for_various_cost_elements_must_properly_combine_shape_and_enforce_modes() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 5)) .Throttle(2, TimeSpan.FromMilliseconds(200), 0, x => x, ThrottleMode.Shaping) @@ -531,9 +532,9 @@ public void Throttle_for_various_cost_elements_must_properly_combine_shape_and_e } [Fact] - public void Throttle_for_various_cost_elements_must_handle_rate_calculation_function_exception() + public async Task Throttle_for_various_cost_elements_must_handle_rate_calculation_function_exception() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var ex = new Exception(); Source.From(Enumerable.Range(1, 5)) diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowWatchTerminationSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowWatchTerminationSpec.cs index d8fb80faeb6..98a1a48f9ac 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowWatchTerminationSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowWatchTerminationSpec.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -28,9 +29,9 @@ public FlowWatchTerminationSpec(ITestOutputHelper helper) : base(helper) } [Fact] - public void A_WatchTermination_must_complete_the_future_when_stream_is_completed() + public async Task A_WatchTermination_must_complete_the_future_when_stream_is_completed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = Source.From(Enumerable.Range(1, 4)) @@ -47,9 +48,9 @@ public void A_WatchTermination_must_complete_the_future_when_stream_is_completed } [Fact] - public void A_WatchTermination_must_complete_the_future_when_stream_is_cancelled_from_downstream() + public async Task A_WatchTermination_must_complete_the_future_when_stream_is_cancelled_from_downstream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = Source.From(Enumerable.Range(1, 4)) @@ -66,9 +67,9 @@ public void A_WatchTermination_must_complete_the_future_when_stream_is_cancelled } [Fact] - public void A_WatchTermination_must_fail_the_future_when_stream_is_failed() + public async Task A_WatchTermination_must_fail_the_future_when_stream_is_failed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var ex = new Exception("Stream failed."); var t = this.SourceProbe().WatchTermination(Keep.Both).To(Sink.Ignore()).Run(Materializer); @@ -81,9 +82,9 @@ public void A_WatchTermination_must_fail_the_future_when_stream_is_failed() } [Fact] - public void A_WatchTermination_must_complete_the_future_for_an_empty_stream() + public async Task A_WatchTermination_must_complete_the_future_for_an_empty_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = Source.Empty() @@ -98,9 +99,9 @@ public void A_WatchTermination_must_complete_the_future_for_an_empty_stream() } [Fact(Skip = "We need a way to combine multiple sources with different materializer types")] - public void A_WatchTermination_must_complete_the_future_for_graph() + public async Task A_WatchTermination_must_complete_the_future_for_graph() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { //var first = this.SourceProbe().WatchTermination(Keep.Both); //var second = Source.From(Enumerable.Range(2, 4)).MapMaterializedValue(new Func, Task)>(_ => null)); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowWhereSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowWhereSpec.cs index 891da210212..69032b6c38c 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowWhereSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowWhereSpec.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.Supervision; using Akka.Streams.TestKit; @@ -65,9 +66,9 @@ public void A_Where_must_not_blow_up_with_high_request_counts() } [Fact] - public void A_Where_must_continue_if_error() + public async Task A_Where_must_continue_if_error() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var ex = new TestException("Test"); diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowZipSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowZipSpec.cs index d4b3395e836..cafdfd7cf86 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowZipSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowZipSpec.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -33,9 +34,9 @@ public FlowZipSpec(ITestOutputHelper output = null) : base(output) } [Fact] - public void A_Zip_for_Flow_must_work_in_the_happy_case() + public async Task A_Zip_for_Flow_must_work_in_the_happy_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateManualSubscriberProbe<(int, string)>(); Source.From(Enumerable.Range(1, 4)) diff --git a/src/core/Akka.Streams.Tests/Dsl/GraphBalanceSpec.cs b/src/core/Akka.Streams.Tests/Dsl/GraphBalanceSpec.cs index 72c27e3a352..935921731d1 100644 --- a/src/core/Akka.Streams.Tests/Dsl/GraphBalanceSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/GraphBalanceSpec.cs @@ -31,9 +31,9 @@ public GraphBalanceSpec() } [Fact] - public void A_Balance_must_balance_between_subscribers_which_signal_demand() + public async Task A_Balance_must_balance_between_subscribers_which_signal_demand() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c1 = this.CreateManualSubscriberProbe(); var c2 = this.CreateManualSubscriberProbe(); @@ -62,9 +62,9 @@ public void A_Balance_must_balance_between_subscribers_which_signal_demand() } [Fact] - public void A_Balance_must_support_waiting_for_demand_from_all_downstream_subscriptions() + public async Task A_Balance_must_support_waiting_for_demand_from_all_downstream_subscriptions() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s1 = this.CreateManualSubscriberProbe(); @@ -99,9 +99,9 @@ public void A_Balance_must_support_waiting_for_demand_from_all_downstream_subscr } [Fact(Skip = "Racy")] - public void A_Balance_must_support_waiting_for_demand_from_all_non_cancelled_downstream_subscriptions() + public async Task A_Balance_must_support_waiting_for_demand_from_all_non_cancelled_downstream_subscriptions() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s1 = this.CreateManualSubscriberProbe(); @@ -147,9 +147,9 @@ public void A_Balance_must_support_waiting_for_demand_from_all_non_cancelled_dow } [Fact] - public void A_Balance_must_work_with_1_way_balance() + public async Task A_Balance_must_work_with_1_way_balance() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.FromGraph(GraphDsl.Create(b => { @@ -170,9 +170,9 @@ public void A_Balance_must_work_with_1_way_balance() } [Fact] - public void A_Balance_must_work_with_5_way_balance() + public async Task A_Balance_must_work_with_5_way_balance() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var sink = Sink.First>(); var t = RunnableGraph.FromGraph(GraphDsl.Create(sink, sink, sink, sink, sink, ValueTuple.Create, @@ -196,9 +196,9 @@ public void A_Balance_must_work_with_5_way_balance() } [Fact] - public void A_Balance_must_balance_between_all_three_outputs() + public async Task A_Balance_must_balance_between_all_three_outputs() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { const int numElementsForSink = 10000; var outputs = Sink.Aggregate(0, (sum, i) => sum + i); @@ -225,9 +225,9 @@ public void A_Balance_must_balance_between_all_three_outputs() } [Fact] - public void A_Balance_must_fairly_balance_between_three_outputs() + public async Task A_Balance_must_fairly_balance_between_three_outputs() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.SinkProbe(); var t = RunnableGraph.FromGraph(GraphDsl.Create(probe, probe, probe, ValueTuple.Create, @@ -262,9 +262,9 @@ public void A_Balance_must_fairly_balance_between_three_outputs() } [Fact] - public void A_Balance_must_produce_to_second_even_though_first_cancels() + public async Task A_Balance_must_produce_to_second_even_though_first_cancels() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c1 = this.CreateManualSubscriberProbe(); var c2 = this.CreateManualSubscriberProbe(); @@ -289,9 +289,9 @@ public void A_Balance_must_produce_to_second_even_though_first_cancels() } [Fact] - public void A_Balance_must_produce_to_first_even_though_second_cancels() + public async Task A_Balance_must_produce_to_first_even_though_second_cancels() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c1 = this.CreateManualSubscriberProbe(); var c2 = this.CreateManualSubscriberProbe(); @@ -316,9 +316,9 @@ public void A_Balance_must_produce_to_first_even_though_second_cancels() } [Fact] - public void A_Balance_must_cancel_upstream_when_downstream_cancel() + public async Task A_Balance_must_cancel_upstream_when_downstream_cancel() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p1 = this.CreateManualPublisherProbe(); var c1 = this.CreateManualSubscriberProbe(); @@ -354,9 +354,9 @@ public void A_Balance_must_cancel_upstream_when_downstream_cancel() } [Fact] - public void A_Balance_must_not_push_output_twice() + public async Task A_Balance_must_not_push_output_twice() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p1 = this.CreateManualPublisherProbe(); var c1 = this.CreateManualSubscriberProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/GraphBroadcastSpec.cs b/src/core/Akka.Streams.Tests/Dsl/GraphBroadcastSpec.cs index ea08a34bea6..901808ce0be 100644 --- a/src/core/Akka.Streams.Tests/Dsl/GraphBroadcastSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/GraphBroadcastSpec.cs @@ -31,9 +31,9 @@ public GraphBroadcastSpec(ITestOutputHelper helper) : base(helper) } [Fact] - public void A_Broadcast_must_broadcast_to_other_subscriber() + public async Task A_Broadcast_must_broadcast_to_other_subscriber() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c1 = this.CreateManualSubscriberProbe(); var c2 = this.CreateManualSubscriberProbe(); @@ -67,9 +67,9 @@ public void A_Broadcast_must_broadcast_to_other_subscriber() } [Fact] - public void A_Broadcast_must_work_with_one_way_broadcast() + public async Task A_Broadcast_must_work_with_one_way_broadcast() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = Source.FromGraph(GraphDsl.Create(b => { @@ -91,9 +91,9 @@ public void A_Broadcast_must_work_with_one_way_broadcast() } [Fact] - public void A_Broadcast_must_work_with_n_way_broadcast() + public async Task A_Broadcast_must_work_with_n_way_broadcast() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var headSink = Sink.First>(); @@ -120,9 +120,9 @@ public void A_Broadcast_must_work_with_n_way_broadcast() } [Fact(Skip="We don't have enough overloads for GraphDsl.Create")] - public void A_Broadcast_must_with_22_way_broadcast() + public async Task A_Broadcast_must_with_22_way_broadcast() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { //var headSink = Sink.First>(); @@ -167,9 +167,9 @@ public void A_Broadcast_must_with_22_way_broadcast() } [Fact] - public void A_Broadcast_must_produce_to_other_even_though_downstream_cancels() + public async Task A_Broadcast_must_produce_to_other_even_though_downstream_cancels() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c1 = this.CreateManualSubscriberProbe(); var c2 = this.CreateManualSubscriberProbe(); @@ -197,9 +197,9 @@ public void A_Broadcast_must_produce_to_other_even_though_downstream_cancels() } [Fact] - public void A_Broadcast_must_produce_to_downstream_even_though_other_cancels() + public async Task A_Broadcast_must_produce_to_downstream_even_though_other_cancels() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c1 = this.CreateManualSubscriberProbe(); var c2 = this.CreateManualSubscriberProbe(); @@ -227,9 +227,9 @@ public void A_Broadcast_must_produce_to_downstream_even_though_other_cancels() } [Fact] - public void A_Broadcast_must_cancel_upstream_when_downstreams_cancel() + public async Task A_Broadcast_must_cancel_upstream_when_downstreams_cancel() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p1 = this.CreateManualPublisherProbe(); var c1 = this.CreateManualSubscriberProbe(); @@ -268,9 +268,9 @@ public void A_Broadcast_must_cancel_upstream_when_downstreams_cancel() } [Fact] - public void A_Broadcast_must_pass_along_early_cancellation() + public async Task A_Broadcast_must_pass_along_early_cancellation() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c1 = this.CreateManualSubscriberProbe(); var c2 = this.CreateManualSubscriberProbe(); @@ -299,9 +299,9 @@ public void A_Broadcast_must_pass_along_early_cancellation() } [Fact] - public void A_Broadcast_must_AltoTo_must_broadcast() + public async Task A_Broadcast_must_AltoTo_must_broadcast() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = this.SinkProbe(); var p2 = this.SinkProbe(); @@ -325,9 +325,9 @@ public void A_Broadcast_must_AltoTo_must_broadcast() } [Fact] - public void A_Broadcast_must_AlsoTo_must_continue_if_sink_cancels() + public async Task A_Broadcast_must_AlsoTo_must_continue_if_sink_cancels() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = this.SinkProbe(); var p2 = this.SinkProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/GraphConcatSpec.cs b/src/core/Akka.Streams.Tests/Dsl/GraphConcatSpec.cs index f87b173bce7..94537a2fc01 100644 --- a/src/core/Akka.Streams.Tests/Dsl/GraphConcatSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/GraphConcatSpec.cs @@ -45,9 +45,9 @@ public ConcatFixture(GraphDsl.Builder builder) : base(builder) } [Fact] - public void Concat_must_work_in_the_happy_case() + public async Task Concat_must_work_in_the_happy_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateManualSubscriberProbe(); @@ -78,9 +78,9 @@ public void Concat_must_work_in_the_happy_case() } [Fact] - public void Concat_must_work_with_one_immediately_completed_and_one_nonempty_publisher() + public async Task Concat_must_work_with_one_immediately_completed_and_one_nonempty_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber1 = Setup(CompletedPublisher(), NonEmptyPublisher(Enumerable.Range(1, 4))); var subscription1 = subscriber1.ExpectSubscription(); @@ -97,9 +97,9 @@ public void Concat_must_work_with_one_immediately_completed_and_one_nonempty_pub } [Fact] - public void Concat_must_work_with_one_delayed_completed_and_one_nonempty_publisher() + public async Task Concat_must_work_with_one_delayed_completed_and_one_nonempty_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber1 = Setup(SoonToCompletePublisher(), NonEmptyPublisher(Enumerable.Range(1, 4))); var subscription1 = subscriber1.ExpectSubscription(); @@ -116,9 +116,9 @@ public void Concat_must_work_with_one_delayed_completed_and_one_nonempty_publish } [Fact] - public void Concat_must_work_with_one_immediately_failed_and_one_nonempty_publisher() + public async Task Concat_must_work_with_one_immediately_failed_and_one_nonempty_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber1 = Setup(FailedPublisher(), NonEmptyPublisher(Enumerable.Range(1, 4))); subscriber1.ExpectSubscriptionAndError().Should().Be(TestException()); @@ -140,9 +140,9 @@ public void Concat_must_work_with_one_immediately_failed_and_one_nonempty_publis } [Fact] - public void Concat_must_work_with_one_nonempty_publisher_and_one_delayed_failed_and() + public async Task Concat_must_work_with_one_nonempty_publisher_and_one_delayed_failed_and() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber = Setup(NonEmptyPublisher(Enumerable.Range(1, 4)), SoonToFailPublisher()); subscriber.ExpectSubscription().Request(5); @@ -161,9 +161,9 @@ public void Concat_must_work_with_one_nonempty_publisher_and_one_delayed_failed_ } [Fact] - public void Concat_must_work_with_one_delayed_failed_and_one_nonempty_publisher() + public async Task Concat_must_work_with_one_delayed_failed_and_one_nonempty_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber1 = Setup(SoonToFailPublisher(), NonEmptyPublisher(Enumerable.Range(1, 4))); subscriber1.ExpectSubscriptionAndError().Should().Be(TestException()); @@ -171,9 +171,9 @@ public void Concat_must_work_with_one_delayed_failed_and_one_nonempty_publisher( } [Fact] - public void Concat_must_correctly_handle_async_errors_in_secondary_upstream() + public async Task Concat_must_correctly_handle_async_errors_in_secondary_upstream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var promise = new TaskCompletionSource(); var subscriber = this.CreateManualSubscriberProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/GraphMergeSpec.cs b/src/core/Akka.Streams.Tests/Dsl/GraphMergeSpec.cs index cfb427ec620..32d274a02a8 100644 --- a/src/core/Akka.Streams.Tests/Dsl/GraphMergeSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/GraphMergeSpec.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -46,9 +47,9 @@ public MergeFixture(GraphDsl.Builder builder) : base(builder) } [Fact] - public void A_Merge_must_work_in_the_happy_case() + public async Task A_Merge_must_work_in_the_happy_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { // Different input sizes(4 and 6) var source1 = Source.From(Enumerable.Range(0, 4)); @@ -149,9 +150,9 @@ public void A_Merge_must_work_with_n_way_merge() } [Fact] - public void A_Merge_must_work_with_one_immediately_completed_and_one_nonempty_publisher() + public async Task A_Merge_must_work_with_one_immediately_completed_and_one_nonempty_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber1 = Setup(CompletedPublisher(), NonEmptyPublisher(Enumerable.Range(1, 4))); var subscription1 = subscriber1.ExpectSubscription(); @@ -166,9 +167,9 @@ public void A_Merge_must_work_with_one_immediately_completed_and_one_nonempty_pu } [Fact] - public void A_Merge_must_work_with_one_delayed_completed_and_one_nonempty_publisher() + public async Task A_Merge_must_work_with_one_delayed_completed_and_one_nonempty_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber1 = Setup(SoonToCompletePublisher(), NonEmptyPublisher(Enumerable.Range(1, 4))); var subscription1 = subscriber1.ExpectSubscription(); @@ -183,27 +184,27 @@ public void A_Merge_must_work_with_one_delayed_completed_and_one_nonempty_publis } [Fact(Skip = "This is nondeterministic, multiple scenarios can happen")] - public void A_Merge_must_work_with_one_immediately_failed_and_one_nonempty_publisher() + public async Task A_Merge_must_work_with_one_immediately_failed_and_one_nonempty_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { }, Materializer); } [Fact(Skip = "This is nondeterministic, multiple scenarios can happen")] - public void A_Merge_must_work_with_one_delayed_failed_and_one_nonempty_publisher() + public async Task A_Merge_must_work_with_one_delayed_failed_and_one_nonempty_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { }, Materializer); } [Fact] - public void A_Merge_must_pass_along_early_cancellation() + public async Task A_Merge_must_pass_along_early_cancellation() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var up1 = this.CreateManualPublisherProbe(); var up2 = this.CreateManualPublisherProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/GraphPartitionSpec.cs b/src/core/Akka.Streams.Tests/Dsl/GraphPartitionSpec.cs index ed0e9e903ed..1ac9f8c78ea 100644 --- a/src/core/Akka.Streams.Tests/Dsl/GraphPartitionSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/GraphPartitionSpec.cs @@ -32,9 +32,9 @@ public GraphPartitionSpec(ITestOutputHelper helper) : base(helper) } [Fact] - public void A_Partition_must_partition_to_three_subscribers() + public async Task A_Partition_must_partition_to_three_subscribers() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s = Sink.Seq(); var t = RunnableGraph.FromGraph(GraphDsl.Create(s, s, s, ValueTuple.Create, (b, sink1, sink2, sink3) => @@ -61,9 +61,9 @@ public void A_Partition_must_partition_to_three_subscribers() } [Fact] - public void A_Partition_must_complete_stage_after_upstream_completes() + public async Task A_Partition_must_complete_stage_after_upstream_completes() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c1 = this.CreateSubscriberProbe(); var c2 = this.CreateSubscriberProbe(); @@ -90,9 +90,9 @@ public void A_Partition_must_complete_stage_after_upstream_completes() } [Fact] - public void A_Partition_must_remember_first_pull_even_thought_first_element_target_another_out() + public async Task A_Partition_must_remember_first_pull_even_thought_first_element_target_another_out() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c1 = this.CreateSubscriberProbe(); var c2 = this.CreateSubscriberProbe(); @@ -120,9 +120,9 @@ public void A_Partition_must_remember_first_pull_even_thought_first_element_targ } [Fact] - public void A_Partition_must_cancel_upstream_when_downstreams_cancel() + public async Task A_Partition_must_cancel_upstream_when_downstreams_cancel() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p1 = this.CreatePublisherProbe(); var c1 = this.CreateSubscriberProbe(); @@ -162,9 +162,9 @@ public void A_Partition_must_cancel_upstream_when_downstreams_cancel() } [Fact] - public void A_Partition_must_work_with_merge() + public async Task A_Partition_must_work_with_merge() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s = Sink.Seq(); var input = new[] {5, 2, 9, 1, 1, 1, 10}; @@ -189,9 +189,9 @@ public void A_Partition_must_work_with_merge() } [Fact] - public void A_Partition_must_stage_completion_is_waiting_for_pending_output() + public async Task A_Partition_must_stage_completion_is_waiting_for_pending_output() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c1 = this.CreateSubscriberProbe(); var c2 = this.CreateSubscriberProbe(); @@ -218,9 +218,9 @@ public void A_Partition_must_stage_completion_is_waiting_for_pending_output() } [Fact] - public void A_Partition_must_fail_stage_if_partitioner_outcome_is_out_of_bound() + public async Task A_Partition_must_fail_stage_if_partitioner_outcome_is_out_of_bound() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c1 = this.CreateSubscriberProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/GraphStageTimersSpec.cs b/src/core/Akka.Streams.Tests/Dsl/GraphStageTimersSpec.cs index 5b3535562de..c5463b33ce7 100644 --- a/src/core/Akka.Streams.Tests/Dsl/GraphStageTimersSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/GraphStageTimersSpec.cs @@ -32,7 +32,7 @@ public GraphStageTimersSpec(ITestOutputHelper helper) : base(helper) Materializer = ActorMaterializer.Create(Sys, settings); } - private SideChannel SetupIsolatedStage() + private async Task SetupIsolatedStage() { var channel = new SideChannel(); var stopPromise = @@ -41,14 +41,14 @@ private SideChannel SetupIsolatedStage() .To(Sink.Ignore()) .Run(Materializer); channel.StopPromise = stopPromise; - AwaitCondition(()=>channel.IsReady); + await AwaitConditionAsync(()=>channel.IsReady); return channel; } [Fact] - public void GraphStage_timer_support_must_receive_single_shot_timer() + public async Task GraphStage_timer_support_must_receive_single_shot_timer() { - var driver = SetupIsolatedStage(); + var driver = await SetupIsolatedStage(); Within(TimeSpan.FromSeconds(2), () => { Within(TimeSpan.FromMilliseconds(500), TimeSpan.FromSeconds(1), () => @@ -63,9 +63,9 @@ public void GraphStage_timer_support_must_receive_single_shot_timer() } [Fact] - public void GraphStage_timer_support_must_resubmit_single_shot_timer() + public async Task GraphStage_timer_support_must_resubmit_single_shot_timer() { - var driver = SetupIsolatedStage(); + var driver = await SetupIsolatedStage(); Within(TimeSpan.FromSeconds(2.5), () => { Within(TimeSpan.FromMilliseconds(500), TimeSpan.FromSeconds(1), () => @@ -81,9 +81,9 @@ public void GraphStage_timer_support_must_resubmit_single_shot_timer() } [Fact] - public void GraphStage_timer_support_must_correctly_cancel_a_named_timer() + public async Task GraphStage_timer_support_must_correctly_cancel_a_named_timer() { - var driver = SetupIsolatedStage(); + var driver = await SetupIsolatedStage(); driver.Tell(TestCancelTimer.Instance); Within(TimeSpan.FromMilliseconds(500), () => ExpectMsg()); Within(TimeSpan.FromMilliseconds(300), TimeSpan.FromSeconds(1), () => ExpectMsg(new Tick(1))); @@ -92,9 +92,9 @@ public void GraphStage_timer_support_must_correctly_cancel_a_named_timer() } [Fact] - public void GraphStage_timer_support_must_receive_and_cancel_a_repeated_timer() + public async Task GraphStage_timer_support_must_receive_and_cancel_a_repeated_timer() { - var driver = SetupIsolatedStage(); + var driver = await SetupIsolatedStage(); driver.Tell(TestRepeatedTimer.Instance); var seq = ReceiveWhile(TimeSpan.FromSeconds(2), o => (Tick)o); seq.Should().HaveCount(5); @@ -103,9 +103,9 @@ public void GraphStage_timer_support_must_receive_and_cancel_a_repeated_timer() } [Fact] - public void GraphStage_timer_support_must_produce_scheduled_ticks_as_expected() + public async Task GraphStage_timer_support_must_produce_scheduled_ticks_as_expected() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstream = this.CreatePublisherProbe(); var downstream = this.CreateSubscriberProbe(); @@ -125,9 +125,9 @@ public void GraphStage_timer_support_must_produce_scheduled_ticks_as_expected() } [Fact] - public void GraphStage_timer_support_must_propagate_error_if_OnTimer_throws_an_Exception() + public async Task GraphStage_timer_support_must_propagate_error_if_OnTimer_throws_an_Exception() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var exception = new TestException("Expected exception to the rule"); var upstream = this.CreatePublisherProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/GraphUnzipSpec.cs b/src/core/Akka.Streams.Tests/Dsl/GraphUnzipSpec.cs index f19036a9b71..30bf3381dd8 100644 --- a/src/core/Akka.Streams.Tests/Dsl/GraphUnzipSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/GraphUnzipSpec.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -28,9 +29,9 @@ public GraphUnzipSpec(ITestOutputHelper helper) : base (helper) } [Fact] - public void A_Unzip_must_unzip_to_two_subscribers() + public async Task A_Unzip_must_unzip_to_two_subscribers() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c1 = this.CreateManualSubscriberProbe(); var c2 = this.CreateManualSubscriberProbe(); @@ -76,9 +77,9 @@ public void A_Unzip_must_unzip_to_two_subscribers() } [Fact] - public void A_Unzip_must_produce_to_right_downstream_even_though_left_downstream_cancels() + public async Task A_Unzip_must_produce_to_right_downstream_even_though_left_downstream_cancels() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c1 = this.CreateManualSubscriberProbe(); var c2 = this.CreateManualSubscriberProbe(); @@ -112,9 +113,9 @@ public void A_Unzip_must_produce_to_right_downstream_even_though_left_downstream } [Fact] - public void A_Unzip_must_produce_to_left_downstream_even_though_right_downstream_cancels() + public async Task A_Unzip_must_produce_to_left_downstream_even_though_right_downstream_cancels() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c1 = this.CreateManualSubscriberProbe(); var c2 = this.CreateManualSubscriberProbe(); @@ -211,9 +212,9 @@ public void A_Unzip_must_not_loose_elements_when_pull_is_followed_by_cancel_befo } [Fact] - public void A_Unzip_must_cancel_upstream_when_downstream_cancel() + public async Task A_Unzip_must_cancel_upstream_when_downstream_cancel() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p1 = this.CreateManualPublisherProbe>(); var c1 = this.CreateManualSubscriberProbe(); @@ -251,9 +252,9 @@ public void A_Unzip_must_cancel_upstream_when_downstream_cancel() } [Fact] - public void A_Unzip_must_work_with_Zip() + public async Task A_Unzip_must_work_with_Zip() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c1 = this.CreateManualSubscriberProbe<(int, string)>(); diff --git a/src/core/Akka.Streams.Tests/Dsl/GraphUnzipWithSpec.cs b/src/core/Akka.Streams.Tests/Dsl/GraphUnzipWithSpec.cs index 11a7733ef03..527b417c744 100644 --- a/src/core/Akka.Streams.Tests/Dsl/GraphUnzipWithSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/GraphUnzipWithSpec.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -31,9 +32,9 @@ public GraphUnzipWithSpec(ITestOutputHelper helper) : base(helper) } [Fact] - public void UnzipWith_must_work_with_immediately_completed_publisher() + public async Task UnzipWith_must_work_with_immediately_completed_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscribers = Setup(TestPublisher.Empty()); ValidateSubscriptionAndComplete(subscribers); @@ -41,9 +42,9 @@ public void UnzipWith_must_work_with_immediately_completed_publisher() } [Fact] - public void UnzipWith_must_work_with_delayed_completed_publisher() + public async Task UnzipWith_must_work_with_delayed_completed_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscribers = Setup(TestPublisher.LazyEmpty()); ValidateSubscriptionAndComplete(subscribers); @@ -51,9 +52,9 @@ public void UnzipWith_must_work_with_delayed_completed_publisher() } [Fact] - public void UnzipWith_must_work_with_two_immediately_failed_publisher() + public async Task UnzipWith_must_work_with_two_immediately_failed_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscribers = Setup(TestPublisher.Error(TestException)); ValidateSubscriptionAndError(subscribers); @@ -61,9 +62,9 @@ public void UnzipWith_must_work_with_two_immediately_failed_publisher() } [Fact] - public void UnzipWith_must_work_with_two_delayed_failed_publisher() + public async Task UnzipWith_must_work_with_two_delayed_failed_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscribers = Setup(TestPublisher.LazyError(TestException)); ValidateSubscriptionAndError(subscribers); @@ -71,9 +72,9 @@ public void UnzipWith_must_work_with_two_delayed_failed_publisher() } [Fact] - public void UnzipWith_must_work_in_the_happy_case() + public async Task UnzipWith_must_work_in_the_happy_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var leftProbe = this.CreateManualSubscriberProbe(); var rightProbe = this.CreateManualSubscriberProbe(); @@ -127,9 +128,9 @@ public void UnzipWith_must_work_in_the_happy_case() } [Fact] - public void UnzipWith_must_work_in_the_sad_case() + public async Task UnzipWith_must_work_in_the_sad_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var leftProbe = this.CreateManualSubscriberProbe(); var rightProbe = this.CreateManualSubscriberProbe(); @@ -174,9 +175,9 @@ public void UnzipWith_must_work_in_the_sad_case() } [Fact] - public void UnzipWith_must_unzipWith_expanded_Person_unapply_3_outputs() + public async Task UnzipWith_must_unzipWith_expanded_Person_unapply_3_outputs() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe0 = this.CreateManualSubscriberProbe(); var probe1 = this.CreateManualSubscriberProbe(); @@ -214,11 +215,11 @@ public void UnzipWith_must_unzipWith_expanded_Person_unapply_3_outputs() } [Fact] - public void UnzipWith_must_work_with_up_to_6_outputs() + public async Task UnzipWith_must_work_with_up_to_6_outputs() { // the jvm version uses 20 outputs but we have only 7 so changed this spec a little bit - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe0 = this.CreateManualSubscriberProbe(); var probe1 = this.CreateManualSubscriberProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/GraphZipSpec.cs b/src/core/Akka.Streams.Tests/Dsl/GraphZipSpec.cs index e3ed7ca1591..4e814fcc670 100644 --- a/src/core/Akka.Streams.Tests/Dsl/GraphZipSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/GraphZipSpec.cs @@ -44,9 +44,9 @@ public ZipFixture(GraphDsl.Builder builder) : base(builder) } [Fact] - public void Zip_must_work_in_the_happy_case() + public async Task Zip_must_work_in_the_happy_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateManualSubscriberProbe<(int, string)>(); @@ -77,9 +77,9 @@ public void Zip_must_work_in_the_happy_case() } [Fact] - public void Zip_must_complete_if_one_side_is_available_but_other_already_completed() + public async Task Zip_must_complete_if_one_side_is_available_but_other_already_completed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstream1 = this.CreatePublisherProbe(); var upstream2 = this.CreatePublisherProbe(); @@ -108,9 +108,9 @@ public void Zip_must_complete_if_one_side_is_available_but_other_already_complet } [Fact] - public void Zip_must_complete_even_if_no_pending_demand() + public async Task Zip_must_complete_even_if_no_pending_demand() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstream1 = this.CreatePublisherProbe(); var upstream2 = this.CreatePublisherProbe(); @@ -142,9 +142,9 @@ public void Zip_must_complete_even_if_no_pending_demand() } [Fact] - public void Zip_must_complete_if_both_sides_complete_before_requested_with_elements_pending_2() + public async Task Zip_must_complete_if_both_sides_complete_before_requested_with_elements_pending_2() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstream1 = this.CreatePublisherProbe(); var upstream2 = this.CreatePublisherProbe(); @@ -175,9 +175,9 @@ public void Zip_must_complete_if_both_sides_complete_before_requested_with_eleme } [Fact] - public void Zip_must_complete_if_one_side_complete_before_requested_with_elements_pending() + public async Task Zip_must_complete_if_one_side_complete_before_requested_with_elements_pending() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstream1 = this.CreatePublisherProbe(); var upstream2 = this.CreatePublisherProbe(); @@ -209,9 +209,9 @@ public void Zip_must_complete_if_one_side_complete_before_requested_with_element } [Fact] - public void Zip_must_complete_if_one_side_complete_before_requested_with_elements_pending_2() + public async Task Zip_must_complete_if_one_side_complete_before_requested_with_elements_pending_2() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstream1 = this.CreatePublisherProbe(); var upstream2 = this.CreatePublisherProbe(); @@ -245,9 +245,9 @@ public void Zip_must_complete_if_one_side_complete_before_requested_with_element } [Fact] - public void Zip_must_work_with_one_immediately_completed_and_one_nonempty_publisher() + public async Task Zip_must_work_with_one_immediately_completed_and_one_nonempty_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber1 = Setup(CompletedPublisher(), NonEmptyPublisher(Enumerable.Range(1, 4))); subscriber1.ExpectSubscriptionAndComplete(); @@ -258,9 +258,9 @@ public void Zip_must_work_with_one_immediately_completed_and_one_nonempty_publis } [Fact] - public void Zip_must_work_with_one_delayed_completed_and_one_nonempty_publisher() + public async Task Zip_must_work_with_one_delayed_completed_and_one_nonempty_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber1 = Setup(SoonToCompletePublisher(), NonEmptyPublisher(Enumerable.Range(1, 4))); subscriber1.ExpectSubscriptionAndComplete(); @@ -271,9 +271,9 @@ public void Zip_must_work_with_one_delayed_completed_and_one_nonempty_publisher( } [Fact] - public void Zip_must_work_with_one_immediately_failed_and_one_nonempty_publisher() + public async Task Zip_must_work_with_one_immediately_failed_and_one_nonempty_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber1 = Setup(FailedPublisher(), NonEmptyPublisher(Enumerable.Range(1, 4))); subscriber1.ExpectSubscriptionAndError().Should().Be(TestException()); @@ -284,9 +284,9 @@ public void Zip_must_work_with_one_immediately_failed_and_one_nonempty_publisher } [Fact] - public void Zip_must_work_with_one_delayed_failed_and_one_nonempty_publisher() + public async Task Zip_must_work_with_one_delayed_failed_and_one_nonempty_publisher() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber1 = Setup(SoonToFailPublisher(), NonEmptyPublisher(Enumerable.Range(1, 4))); subscriber1.ExpectSubscriptionAndError().Should().Be(TestException()); diff --git a/src/core/Akka.Streams.Tests/Dsl/GraphZipWithSpec.cs b/src/core/Akka.Streams.Tests/Dsl/GraphZipWithSpec.cs index bbd01c2d698..2e73c908337 100644 --- a/src/core/Akka.Streams.Tests/Dsl/GraphZipWithSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/GraphZipWithSpec.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -88,9 +89,9 @@ public void ZipWith_must_work_with_one_delayed_failed_and_one_nonempty_publisher } [Fact] - public void ZipWith_must_work_in_the_happy_case() + public async Task ZipWith_must_work_in_the_happy_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateManualSubscriberProbe(); @@ -124,9 +125,9 @@ public void ZipWith_must_work_in_the_happy_case() [Fact] - public void ZipWith_must_work_in_the_sad_case() + public async Task ZipWith_must_work_in_the_sad_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateManualSubscriberProbe(); @@ -154,9 +155,9 @@ public void ZipWith_must_work_in_the_sad_case() } [Fact] - public void ZipWith_must_ZipWith_expanded_Person_unapply_3_outputs() + public async Task ZipWith_must_ZipWith_expanded_Person_unapply_3_outputs() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateManualSubscriberProbe(); @@ -185,11 +186,11 @@ public void ZipWith_must_ZipWith_expanded_Person_unapply_3_outputs() } [Fact] - public void ZipWith_must_work_with_up_to_9_inputs() + public async Task ZipWith_must_work_with_up_to_9_inputs() { // the jvm version uses 19 inputs but we have only 9 - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateManualSubscriberProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/HeadSinkSpec.cs b/src/core/Akka.Streams.Tests/Dsl/HeadSinkSpec.cs index 519fbb7618e..50f1d587140 100644 --- a/src/core/Akka.Streams.Tests/Dsl/HeadSinkSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/HeadSinkSpec.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -26,9 +27,9 @@ public HeadSinkSpec(ITestOutputHelper helper):base(helper) } [Fact] - public void A_FLow_with_a_Sink_Head_must_yield_the_first_value() + public async Task A_FLow_with_a_Sink_Head_must_yield_the_first_value() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = this.CreateManualPublisherProbe(); var task = Source.FromPublisher(p).Select(x=>x).RunWith(Sink.First(), Materializer); @@ -61,9 +62,9 @@ public void A_FLow_with_a_Sink_Head_must_yield_the_first_value_when_actively_con } [Fact] - public void A_FLow_with_a_Sink_Head_must_yield_the_first_error() + public async Task A_FLow_with_a_Sink_Head_must_yield_the_first_error() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.Failed(new Exception("ex")) .Invoking(s => s.RunWith(Sink.First(), Materializer).Wait(TimeSpan.FromSeconds(1))) @@ -74,9 +75,9 @@ public void A_FLow_with_a_Sink_Head_must_yield_the_first_error() } [Fact] - public void A_FLow_with_a_Sink_Head_must_yield_NoSuchElementException_for_empty_stream() + public async Task A_FLow_with_a_Sink_Head_must_yield_NoSuchElementException_for_empty_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.Empty() .Invoking(s => s.RunWith(Sink.First(), Materializer).Wait(TimeSpan.FromSeconds(1))) @@ -89,9 +90,9 @@ public void A_FLow_with_a_Sink_Head_must_yield_NoSuchElementException_for_empty_ [Fact] - public void A_FLow_with_a_Sink_HeadOption_must_yield_the_first_value() + public async Task A_FLow_with_a_Sink_HeadOption_must_yield_the_first_value() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = this.CreateManualPublisherProbe(); var task = Source.FromPublisher(p).Select(x => x).RunWith(Sink.FirstOrDefault(), Materializer); @@ -105,9 +106,9 @@ public void A_FLow_with_a_Sink_HeadOption_must_yield_the_first_value() } [Fact] - public void A_FLow_with_a_Sink_HeadOption_must_yield_the_first_error() + public async Task A_FLow_with_a_Sink_HeadOption_must_yield_the_first_error() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.Failed(new Exception("ex")) .Invoking(s => s.RunWith(Sink.FirstOrDefault(), Materializer).Wait(TimeSpan.FromSeconds(1))) @@ -118,9 +119,9 @@ public void A_FLow_with_a_Sink_HeadOption_must_yield_the_first_error() } [Fact] - public void A_FLow_with_a_Sink_HeadOption_must_yield_default_for_empty_stream() + public async Task A_FLow_with_a_Sink_HeadOption_must_yield_default_for_empty_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.Empty().RunWith(Sink.FirstOrDefault(), Materializer); task.Wait(TimeSpan.FromSeconds(1)).Should().BeTrue(); diff --git a/src/core/Akka.Streams.Tests/Dsl/HubSpec.cs b/src/core/Akka.Streams.Tests/Dsl/HubSpec.cs index 7c0f175008c..65c80ee8280 100644 --- a/src/core/Akka.Streams.Tests/Dsl/HubSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/HubSpec.cs @@ -33,9 +33,9 @@ public HubSpec(ITestOutputHelper helper) : base(helper) public ActorMaterializer Materializer { get; } [Fact] - public void MergeHub_must_work_in_the_happy_case() + public async Task MergeHub_must_work_in_the_happy_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = MergeHub.Source(16).Take(20).ToMaterialized(Sink.Seq(), Keep.Both).Run(Materializer); var sink = t.Item1; @@ -48,9 +48,9 @@ public void MergeHub_must_work_in_the_happy_case() } [Fact] - public void MergeHub_must_notify_new_producers_if_consumer_cancels_before_first_producer() + public async Task MergeHub_must_notify_new_producers_if_consumer_cancels_before_first_producer() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var sink = Sink.Cancelled().RunWith(MergeHub.Source(16), Materializer); var upstream = this.CreatePublisherProbe(); @@ -62,9 +62,9 @@ public void MergeHub_must_notify_new_producers_if_consumer_cancels_before_first_ } [Fact] - public void MergeHub_must_notify_existing_producers_if_consumer_cancels_after_a_few_elements() + public async Task MergeHub_must_notify_existing_producers_if_consumer_cancels_after_a_few_elements() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = MergeHub.Source(16).Take(5).ToMaterialized(Sink.Seq(), Keep.Both).Run(Materializer); var sink = t.Item1; @@ -81,9 +81,9 @@ public void MergeHub_must_notify_existing_producers_if_consumer_cancels_after_a_ } [Fact] - public void MergeHub_must_notify_new_producers_if_consumer_cancels_after_a_few_elements() + public async Task MergeHub_must_notify_new_producers_if_consumer_cancels_after_a_few_elements() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = MergeHub.Source(16).Take(5).ToMaterialized(Sink.Seq(), Keep.Both).Run(Materializer); var sink = t.Item1; @@ -104,9 +104,9 @@ public void MergeHub_must_notify_new_producers_if_consumer_cancels_after_a_few_e } [Fact] - public void MergeHub_must_respect_the_buffer_size() + public async Task MergeHub_must_respect_the_buffer_size() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var downstream = this.CreateManualSubscriberProbe(); var sink = Sink.FromSubscriber(downstream).RunWith(MergeHub.Source(3), Materializer); @@ -162,9 +162,9 @@ public void MergeHub_must_respect_the_buffer_size() } [Fact] - public void MergeHub_must_work_with_long_streams() + public async Task MergeHub_must_work_with_long_streams() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = MergeHub.Source(16).Take(20000).ToMaterialized(Sink.Seq(), Keep.Both) .Run(Materializer); @@ -179,9 +179,9 @@ public void MergeHub_must_work_with_long_streams() } [Fact] - public void MergeHub_must_work_with_long_streams_when_buffer_size_is_1() + public async Task MergeHub_must_work_with_long_streams_when_buffer_size_is_1() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = MergeHub.Source(1).Take(20000).ToMaterialized(Sink.Seq(), Keep.Both) .Run(Materializer); @@ -196,9 +196,9 @@ public void MergeHub_must_work_with_long_streams_when_buffer_size_is_1() } [Fact] - public void MergeHub_must_work_with_long_streams_when_consumer_is_slower() + public async Task MergeHub_must_work_with_long_streams_when_consumer_is_slower() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = MergeHub.Source(16) .Take(2000) @@ -217,9 +217,9 @@ public void MergeHub_must_work_with_long_streams_when_consumer_is_slower() } [Fact] - public void MergeHub_must_work_with_long_streams_if_one_of_the_producers_is_slower() + public async Task MergeHub_must_work_with_long_streams_if_one_of_the_producers_is_slower() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = MergeHub.Source(16).Take(2000).ToMaterialized(Sink.Seq(), Keep.Both) .Run(Materializer); @@ -236,9 +236,9 @@ public void MergeHub_must_work_with_long_streams_if_one_of_the_producers_is_slow } [Fact] - public void MergeHub_must_work_with_different_producers_separated_over_time() + public async Task MergeHub_must_work_with_different_producers_separated_over_time() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var downstream = this.CreateSubscriberProbe>(); var sink = MergeHub.Source(16) @@ -256,9 +256,9 @@ public void MergeHub_must_work_with_different_producers_separated_over_time() } [Fact] - public void MergeHub_must_keep_working_even_if_one_of_the_producers_fail() + public async Task MergeHub_must_keep_working_even_if_one_of_the_producers_fail() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = MergeHub.Source(16).Take(10).ToMaterialized(Sink.Seq(), Keep.Both).Run(Materializer); var sink = t.Item1; @@ -275,9 +275,9 @@ public void MergeHub_must_keep_working_even_if_one_of_the_producers_fail() } [Fact] - public void BroadcastHub_must_work_in_the_happy_case() + public async Task BroadcastHub_must_work_in_the_happy_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var source = Source.From(Enumerable.Range(1, 10)).RunWith(BroadcastHub.Sink(8), Materializer); source.RunWith(Sink.Seq(), Materializer) @@ -287,9 +287,9 @@ public void BroadcastHub_must_work_in_the_happy_case() } [Fact] - public void BroadcastHub_must_send_the_same_elements_to_consumers_attaching_around_the_same_time() + public async Task BroadcastHub_must_send_the_same_elements_to_consumers_attaching_around_the_same_time() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var other = Source.From(Enumerable.Range(2, 9)) .MapMaterializedValue>(_ => null); @@ -312,9 +312,9 @@ public void BroadcastHub_must_send_the_same_elements_to_consumers_attaching_arou } [Fact] - public void BroadcastHub_must_send_the_same_prefix_to_consumers_attaching_around_the_same_time_if_one_cancels_earlier() + public async Task BroadcastHub_must_send_the_same_prefix_to_consumers_attaching_around_the_same_time_if_one_cancels_earlier() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var other = Source.From(Enumerable.Range(2, 19)) .MapMaterializedValue>(_ => null); @@ -337,9 +337,9 @@ public void BroadcastHub_must_send_the_same_prefix_to_consumers_attaching_around } [Fact] - public void BroadcastHub_must_ensure_that_subsequent_consumers_see_subsequent_elements_without_gap() + public async Task BroadcastHub_must_ensure_that_subsequent_consumers_see_subsequent_elements_without_gap() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var source = Source.From(Enumerable.Range(1, 20)).RunWith(BroadcastHub.Sink(8), Materializer); source.Take(10) @@ -354,9 +354,9 @@ public void BroadcastHub_must_ensure_that_subsequent_consumers_see_subsequent_el } [Fact] - public void BroadcastHub_must_send_the_same_elements_to_consumers_of_different_speed_attaching_around_the_same_time() + public async Task BroadcastHub_must_send_the_same_elements_to_consumers_of_different_speed_attaching_around_the_same_time() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var other = Source.From(Enumerable.Range(2, 9)) .MapMaterializedValue>(_ => null); @@ -380,9 +380,9 @@ public void BroadcastHub_must_send_the_same_elements_to_consumers_of_different_s } [Fact] - public void BroadcastHub_must_send_the_same_elements_to_consumers_of_attaching_around_the_same_time_if_the_producer_is_slow() + public async Task BroadcastHub_must_send_the_same_elements_to_consumers_of_attaching_around_the_same_time_if_the_producer_is_slow() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var other = Source.From(Enumerable.Range(2, 9)) .MapMaterializedValue>(_ => null); @@ -406,9 +406,9 @@ public void BroadcastHub_must_send_the_same_elements_to_consumers_of_attaching_a } [Fact] - public void BroadcastHub_must_ensure_that_from_two_different_speed_consumers_the_slower_controls_the_rate() + public async Task BroadcastHub_must_ensure_that_from_two_different_speed_consumers_the_slower_controls_the_rate() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var other = Source.From(Enumerable.Range(2, 19)) .MapMaterializedValue>(_ => null); @@ -436,9 +436,9 @@ public void BroadcastHub_must_ensure_that_from_two_different_speed_consumers_the } [Fact] - public void BroadcastHub_must_send_the_same_elements_to_consumers_attaching_around_the_same_time_with_a_buffer_size_of_one() + public async Task BroadcastHub_must_send_the_same_elements_to_consumers_attaching_around_the_same_time_with_a_buffer_size_of_one() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var other = Source.From(Enumerable.Range(2, 9)) .MapMaterializedValue>(_ => null); @@ -461,9 +461,9 @@ public void BroadcastHub_must_send_the_same_elements_to_consumers_attaching_arou } [Fact] - public void BroadcastHub_must_be_able_to_implement_a_keep_dropping_if_unsubscribed_policy_with_a_simple_SinkIgnore() + public async Task BroadcastHub_must_be_able_to_implement_a_keep_dropping_if_unsubscribed_policy_with_a_simple_SinkIgnore() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var killSwitch = KillSwitches.Shared("test-switch"); var source = Source.From(Enumerable.Range(1, int.MaxValue)) @@ -514,9 +514,9 @@ public void BroadcastHub_must_remember_completion_for_materialisations_after_com } [Fact] - public void BroadcastHub_must_properly_signal_error_to_consumers() + public async Task BroadcastHub_must_properly_signal_error_to_consumers() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstream = this.CreatePublisherProbe(); var source = Source.FromPublisher(upstream).RunWith(BroadcastHub.Sink(8), Materializer); @@ -544,9 +544,9 @@ public void BroadcastHub_must_properly_signal_error_to_consumers() } [Fact] - public void BroadcastHub_must_properly_signal_completion_to_consumers_arriving_after_producer_finished() + public async Task BroadcastHub_must_properly_signal_completion_to_consumers_arriving_after_producer_finished() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var source = Source.Empty().RunWith(BroadcastHub.Sink(8), Materializer); // Wait enough so the Hub gets the completion. This is racy, but this is fine because both @@ -558,9 +558,9 @@ public void BroadcastHub_must_properly_signal_completion_to_consumers_arriving_a } [Fact] - public void BroadcastHub_must_properly_signal_error_to_consumers_arriving_after_producer_finished() + public async Task BroadcastHub_must_properly_signal_error_to_consumers_arriving_after_producer_finished() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var source = Source.Failed(new TestException("Fail!")) .RunWith(BroadcastHub.Sink(8), Materializer); @@ -574,9 +574,9 @@ public void BroadcastHub_must_properly_signal_error_to_consumers_arriving_after_ } [Fact] - public void PartitionHub_must_work_in_the_happy_case_with_one_stream() + public async Task PartitionHub_must_work_in_the_happy_case_with_one_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var items = Enumerable.Range(1, 10).ToList(); var source = Source.From(items) @@ -587,9 +587,9 @@ public void PartitionHub_must_work_in_the_happy_case_with_one_stream() } [Fact] - public void PartitionHub_must_work_in_the_happy_case_with_two_streams() + public async Task PartitionHub_must_work_in_the_happy_case_with_two_streams() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var source = Source.From(Enumerable.Range(0, 10)) .RunWith(PartitionHub.Sink((size, e) => e % size, 2, 8), Materializer); @@ -603,9 +603,9 @@ public void PartitionHub_must_work_in_the_happy_case_with_two_streams() } [Fact] - public void PartitionHub_must_be_able_to_use_as_rount_robin_router() + public async Task PartitionHub_must_be_able_to_use_as_rount_robin_router() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var source = Source.From(Enumerable.Range(0, 10)) .RunWith(PartitionHub.StatefulSink(() => @@ -625,9 +625,9 @@ public void PartitionHub_must_be_able_to_use_as_rount_robin_router() } [Fact] - public void PartitionHub_must_be_able_to_use_as__sticky_session_rount_robin_router() + public async Task PartitionHub_must_be_able_to_use_as__sticky_session_rount_robin_router() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var source = Source.From(new[] { "usr-1", "usr-2", "usr-1", "usr-3" }) .RunWith(PartitionHub.StatefulSink(() => @@ -652,9 +652,9 @@ public void PartitionHub_must_be_able_to_use_as__sticky_session_rount_robin_rout } [Fact] - public void PartitionHub_must_be_able_to_use_as_fastest_consumer_router() + public async Task PartitionHub_must_be_able_to_use_as_fastest_consumer_router() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var items = Enumerable.Range(0, 999).ToList(); var source = Source.From(items) @@ -670,9 +670,9 @@ public void PartitionHub_must_be_able_to_use_as_fastest_consumer_router() } [Fact] - public void PartitionHub_must_route_evenly() + public async Task PartitionHub_must_route_evenly() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = this.SourceProbe() .ToMaterialized(PartitionHub.Sink((size, e) => e % size, 2, 8), Keep.Both) @@ -715,9 +715,9 @@ public void PartitionHub_must_route_evenly() } [Fact] - public void PartitionHub_must_route_unevenly() + public async Task PartitionHub_must_route_unevenly() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = this.SourceProbe() .ToMaterialized(PartitionHub.Sink((size, e) => (e % 3) % 2, 2, 8), Keep.Both) @@ -756,9 +756,9 @@ public void PartitionHub_must_route_unevenly() } [Fact] - public void PartitionHub_must_backpressure() + public async Task PartitionHub_must_backpressure() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = this.SourceProbe() .ToMaterialized(PartitionHub.Sink((size, e) => 0, 2, 4), Keep.Both) @@ -790,9 +790,9 @@ public void PartitionHub_must_backpressure() } [Fact] - public void PartitionHub_must_ensure_that_from_two_different_speed_consumers_the_slower_controls_the_rate() + public async Task PartitionHub_must_ensure_that_from_two_different_speed_consumers_the_slower_controls_the_rate() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = Source.Maybe().ConcatMaterialized(Source.From(Enumerable.Range(1, 19)), Keep.Left) .ToMaterialized(PartitionHub.Sink((size, e) => e % size, 2, 1), Keep.Both) @@ -824,9 +824,9 @@ public void PartitionHub_must_ensure_that_from_two_different_speed_consumers_the } [Fact] - public void PartitionHub_must_properly_signal_error_to_consumer() + public async Task PartitionHub_must_properly_signal_error_to_consumer() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstream = this.CreatePublisherProbe(); var source = Source.FromPublisher(upstream) @@ -857,9 +857,9 @@ public void PartitionHub_must_properly_signal_error_to_consumer() } [Fact] - public void PartitionHub_must_properly_signal_completion_to_consumers_arriving_after_producer_finished() + public async Task PartitionHub_must_properly_signal_completion_to_consumers_arriving_after_producer_finished() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var source = Source.Empty().RunWith(PartitionHub.Sink((s, e) => e % s, 0), Materializer); // Wait enough so the Hub gets the completion. This is racy, but this is fine because both @@ -871,7 +871,7 @@ public void PartitionHub_must_properly_signal_completion_to_consumers_arriving_a } [Fact] - public void PartitionHub_must_remeber_completion_for_materialisations_after_completion() + public async Task PartitionHub_must_remeber_completion_for_materialisations_after_completion() { var t = this.SourceProbe().ToMaterialized(PartitionHub.Sink((s, e) => 0, 0), Keep.Both) .Run(Materializer); @@ -893,9 +893,9 @@ public void PartitionHub_must_remeber_completion_for_materialisations_after_comp } [Fact] - public void PartitionHub_must_properly_signal_error_to_consumer_arriving_after_producer_finished() + public async Task PartitionHub_must_properly_signal_error_to_consumer_arriving_after_producer_finished() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var failure = new TestException("Fail!"); var source = Source.Failed(failure).RunWith(PartitionHub.Sink((s, e) => 0, 0), Materializer); diff --git a/src/core/Akka.Streams.Tests/Dsl/LastSinkSpec.cs b/src/core/Akka.Streams.Tests/Dsl/LastSinkSpec.cs index efdbf4b1a98..ff085314237 100644 --- a/src/core/Akka.Streams.Tests/Dsl/LastSinkSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/LastSinkSpec.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit.Tests; using FluentAssertions; @@ -26,9 +27,9 @@ public LastSinkSpec(ITestOutputHelper helper):base(helper) } [Fact] - public void A_Flow_with_Sink_Last_must_yield_the_last_value() + public async Task A_Flow_with_Sink_Last_must_yield_the_last_value() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.From(Enumerable.Range(1,42)).Select(x=>x).RunWith(Sink.Last(), Materializer); task.Wait(TimeSpan.FromSeconds(1)).Should().BeTrue(); @@ -37,9 +38,9 @@ public void A_Flow_with_Sink_Last_must_yield_the_last_value() } [Fact] - public void A_Flow_with_Sink_Last_must_yield_the_first_error() + public async Task A_Flow_with_Sink_Last_must_yield_the_first_error() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.Failed(new Exception("ex")) .Invoking(s => s.RunWith(Sink.Last(), Materializer).Wait(TimeSpan.FromSeconds(1))) @@ -50,9 +51,9 @@ public void A_Flow_with_Sink_Last_must_yield_the_first_error() } [Fact] - public void A_Flow_with_Sink_Last_must_yield_NoSuchElementException_for_empty_stream() + public async Task A_Flow_with_Sink_Last_must_yield_NoSuchElementException_for_empty_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.Empty() .Invoking(s => s.RunWith(Sink.Last(), Materializer).Wait(TimeSpan.FromSeconds(1))) @@ -64,9 +65,9 @@ public void A_Flow_with_Sink_Last_must_yield_NoSuchElementException_for_empty_st [Fact] - public void A_Flow_with_Sink_LastOption_must_yield_the_last_value() + public async Task A_Flow_with_Sink_LastOption_must_yield_the_last_value() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.From(Enumerable.Range(1, 42)).Select(x => x).RunWith(Sink.LastOrDefault(), Materializer); task.Wait(TimeSpan.FromSeconds(1)).Should().BeTrue(); @@ -75,9 +76,9 @@ public void A_Flow_with_Sink_LastOption_must_yield_the_last_value() } [Fact] - public void A_Flow_with_Sink_LastOption_must_yield_the_first_error() + public async Task A_Flow_with_Sink_LastOption_must_yield_the_first_error() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.Failed(new Exception("ex")) .Invoking(s => s.RunWith(Sink.LastOrDefault(), Materializer).Wait(TimeSpan.FromSeconds(1))) @@ -88,9 +89,9 @@ public void A_Flow_with_Sink_LastOption_must_yield_the_first_error() } [Fact] - public void A_Flow_with_Sink_LastOption_must_yield_default_for_empty_stream() + public async Task A_Flow_with_Sink_LastOption_must_yield_default_for_empty_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.Empty().RunWith(Sink.LastOrDefault(), Materializer); task.Wait(TimeSpan.FromSeconds(1)).Should().BeTrue(); diff --git a/src/core/Akka.Streams.Tests/Dsl/LazySinkSpec.cs b/src/core/Akka.Streams.Tests/Dsl/LazySinkSpec.cs index 83f3d9f1a6b..36b4e62aa73 100644 --- a/src/core/Akka.Streams.Tests/Dsl/LazySinkSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/LazySinkSpec.cs @@ -43,9 +43,9 @@ private static Func Fallback() private static readonly Exception Ex = new TestException(""); [Fact] - public void A_LazySink_must_work_in_the_happy_case() + public async Task A_LazySink_must_work_in_the_happy_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var lazySink = Sink.LazySink((int _) => Task.FromResult(this.SinkProbe()), Fallback>()); @@ -57,9 +57,9 @@ public void A_LazySink_must_work_in_the_happy_case() } [Fact] - public void A_LazySink_must_work_with_slow_sink_init() + public async Task A_LazySink_must_work_with_slow_sink_init() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = new TaskCompletionSource>>(); var sourceProbe = this.CreateManualPublisherProbe(); @@ -87,9 +87,9 @@ public void A_LazySink_must_work_with_slow_sink_init() } [Fact] - public void A_LazySink_must_complete_when_there_was_no_elements_in_stream() + public async Task A_LazySink_must_complete_when_there_was_no_elements_in_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var lazySink = Sink.LazySink((int _) => Task.FromResult(Sink.Aggregate(0, (int i, int i2) => i + i2)), () => Task.FromResult(0)); @@ -100,9 +100,9 @@ public void A_LazySink_must_complete_when_there_was_no_elements_in_stream() } [Fact] - public void A_LazySink_must_complete_normally_when_upstream_is_completed() + public async Task A_LazySink_must_complete_normally_when_upstream_is_completed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var lazySink = Sink.LazySink((int _) => Task.FromResult(this.SinkProbe()), Fallback>()); @@ -113,9 +113,9 @@ public void A_LazySink_must_complete_normally_when_upstream_is_completed() } [Fact] - public void A_LazySink_must_fail_gracefully_when_sink_factory_method_failed() + public async Task A_LazySink_must_fail_gracefully_when_sink_factory_method_failed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var sourceProbe = this.CreateManualPublisherProbe(); var taskProbe = Source.FromPublisher(sourceProbe).RunWith(Sink.LazySink((int _) => @@ -132,9 +132,9 @@ public void A_LazySink_must_fail_gracefully_when_sink_factory_method_failed() } [Fact] - public void A_LazySink_must_fail_gracefully_when_upstream_failed() + public async Task A_LazySink_must_fail_gracefully_when_upstream_failed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var sourceProbe = this.CreateManualPublisherProbe(); var lazySink = Sink.LazySink((int _) => Task.FromResult(this.SinkProbe()), @@ -152,9 +152,9 @@ public void A_LazySink_must_fail_gracefully_when_upstream_failed() } [Fact] - public void A_LazySink_must_fail_gracefully_when_factory_task_failed() + public async Task A_LazySink_must_fail_gracefully_when_factory_task_failed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var failedTask = new TaskFactory>>().StartNew(() => { @@ -176,9 +176,9 @@ public void A_LazySink_must_fail_gracefully_when_factory_task_failed() } [Fact] - public void A_LazySink_must_cancel_upstream_when_internal_sink_is_cancelled() + public async Task A_LazySink_must_cancel_upstream_when_internal_sink_is_cancelled() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var sourceProbe = this.CreateManualPublisherProbe(); var lazySink = Sink.LazySink((int _) => Task.FromResult(this.SinkProbe()), @@ -196,9 +196,9 @@ public void A_LazySink_must_cancel_upstream_when_internal_sink_is_cancelled() } [Fact] - public void A_LazySink_must_continue_if_supervision_is_resume() + public async Task A_LazySink_must_continue_if_supervision_is_resume() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var sourceProbe = this.CreateManualPublisherProbe(); var lazySink = Sink.LazySink((int a) => @@ -226,9 +226,9 @@ public void A_LazySink_must_continue_if_supervision_is_resume() } [Fact] - public void A_LazySink_must_fail_task_when_zero_throws_exception() + public async Task A_LazySink_must_fail_task_when_zero_throws_exception() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var lazySink = Sink.LazySink((int _) => Task.FromResult(Sink.Aggregate(0, (i, i1) => i + i1)), () => @@ -241,9 +241,9 @@ public void A_LazySink_must_fail_task_when_zero_throws_exception() } [Fact] - public void A_LazySink_must_fail_correctly_when_materialization_of_inner_sink_fails() + public async Task A_LazySink_must_fail_correctly_when_materialization_of_inner_sink_fails() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var matFail = new TestException("fail!"); diff --git a/src/core/Akka.Streams.Tests/Dsl/LazySourceSpec.cs b/src/core/Akka.Streams.Tests/Dsl/LazySourceSpec.cs index d64d5bed03b..8ebef9d70ed 100644 --- a/src/core/Akka.Streams.Tests/Dsl/LazySourceSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/LazySourceSpec.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Immutable; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.Stage; using Akka.Streams.TestKit; @@ -29,9 +30,9 @@ public LazySourceSpec() private ActorMaterializer Materializer { get; } [Fact] - public void A_lazy_source_must_work_like_a_normal_source_happy_path() + public async Task A_lazy_source_must_work_like_a_normal_source_happy_path() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var result = Source.Lazily(() => Source.From(new[] { 1, 2, 3 })).RunWith(Sink.Seq(), Materializer); result.AwaitResult().Should().BeEquivalentTo(ImmutableList.Create(1, 2, 3)); @@ -39,9 +40,9 @@ public void A_lazy_source_must_work_like_a_normal_source_happy_path() } [Fact] - public void A_lazy_source_must_work_never_construct_the_source_when_there_was_no_demand() + public async Task A_lazy_source_must_work_never_construct_the_source_when_there_was_no_demand() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateSubscriberProbe(); var constructed = new AtomicBoolean(); @@ -57,9 +58,9 @@ public void A_lazy_source_must_work_never_construct_the_source_when_there_was_no } [Fact] - public void A_lazy_source_must_fail_the_materialized_value_when_downstream_cancels_without_ever_consuming_any_element() + public async Task A_lazy_source_must_fail_the_materialized_value_when_downstream_cancels_without_ever_consuming_any_element() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var result = Source.Lazily(() => Source.From(new[] { 1, 2, 3 })) .ToMaterialized(Sink.Cancelled(), Keep.Left) @@ -73,9 +74,9 @@ public void A_lazy_source_must_fail_the_materialized_value_when_downstream_cance } [Fact] - public void A_lazy_source_must_stop_consuming_when_downstream_has_cancelled() + public async Task A_lazy_source_must_stop_consuming_when_downstream_has_cancelled() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var outProbe = this.CreateSubscriberProbe(); var inProbe = this.CreatePublisherProbe(); @@ -92,9 +93,9 @@ public void A_lazy_source_must_stop_consuming_when_downstream_has_cancelled() } [Fact] - public void A_lazy_source_must_materialize_when_the_source_has_been_created() + public async Task A_lazy_source_must_materialize_when_the_source_has_been_created() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateSubscriberProbe(); @@ -112,9 +113,9 @@ public void A_lazy_source_must_materialize_when_the_source_has_been_created() } [Fact] - public void A_lazy_source_must_fail_stage_when_upstream_fails() + public async Task A_lazy_source_must_fail_stage_when_upstream_fails() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var outProbe = this.CreateSubscriberProbe(); var inProbe = this.CreatePublisherProbe(); @@ -133,9 +134,9 @@ public void A_lazy_source_must_fail_stage_when_upstream_fails() } [Fact] - public void A_lazy_source_must_propagate_attributes_to_inner_stream() + public async Task A_lazy_source_must_propagate_attributes_to_inner_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var attributesSource = Source.FromGraph(new AttibutesSourceStage()) .AddAttributes(Attributes.CreateName("inner")); @@ -154,9 +155,9 @@ public void A_lazy_source_must_propagate_attributes_to_inner_stream() } [Fact] - public void A_lazy_source_must_fail_correctly_when_materialization_of_inner_source_fails() + public async Task A_lazy_source_must_fail_correctly_when_materialization_of_inner_source_fails() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var matFail = new TestException("fail!"); diff --git a/src/core/Akka.Streams.Tests/Dsl/ObservableSinkSpec.cs b/src/core/Akka.Streams.Tests/Dsl/ObservableSinkSpec.cs index 6a7207f5d8f..15253bc11ad 100644 --- a/src/core/Akka.Streams.Tests/Dsl/ObservableSinkSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/ObservableSinkSpec.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using Akka.Actor; using Akka.Streams.Actors; using Akka.Streams.Dsl; @@ -55,9 +56,9 @@ public ObservableSinkSpec(ITestOutputHelper helper) : base(SpecConfig, helper) } [Fact(Skip = "Racy on Azure DevOps")] - public void An_ObservableSink_must_allow_the_same_observer_to_be_subscribed_only_once() + public async Task An_ObservableSink_must_allow_the_same_observer_to_be_subscribed_only_once() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = new TestObserver(this); var observable = Source.From(new[] { 1, 2, 3 }) @@ -78,9 +79,9 @@ public void An_ObservableSink_must_allow_the_same_observer_to_be_subscribed_only } [Fact(Skip = "Racy on Azure DevOps")] - public void An_ObservableSink_must_propagate_events_to_all_observers() + public async Task An_ObservableSink_must_propagate_events_to_all_observers() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe1 = new TestObserver(this); var probe2 = new TestObserver(this); @@ -104,9 +105,9 @@ public void An_ObservableSink_must_propagate_events_to_all_observers() } [Fact(Skip = "Racy on Azure DevOps")] - public void An_ObservableSink_must_propagate_error_to_all_observers() + public async Task An_ObservableSink_must_propagate_error_to_all_observers() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var e = new Exception("boom"); var probe1 = new TestObserver(this); @@ -129,34 +130,34 @@ public void An_ObservableSink_must_propagate_error_to_all_observers() [Fact] public void An_ObservableSink_subscriber_must_be_disposable() { - var probe = new TestObserver(this); - var tuple = Source.Queue(1, OverflowStrategy.DropHead) - .ToMaterialized(Sink.AsObservable(), Keep.Both) - .Run(Materializer); - var queue = tuple.Item1; - var observable = tuple.Item2; + var probe = new TestObserver(this); + var tuple = Source.Queue(1, OverflowStrategy.DropHead) + .ToMaterialized(Sink.AsObservable(), Keep.Both) + .Run(Materializer); + var queue = tuple.Item1; + var observable = tuple.Item2; - var d1 = observable.Subscribe(probe); + var d1 = observable.Subscribe(probe); - var t = queue.OfferAsync(1); - t.Wait(TimeSpan.FromSeconds(1)).ShouldBeTrue(); - t.Result.ShouldBe(QueueOfferResult.Enqueued.Instance); + var t = queue.OfferAsync(1); + t.Wait(TimeSpan.FromSeconds(1)).ShouldBeTrue(); + t.Result.ShouldBe(QueueOfferResult.Enqueued.Instance); - probe.ExpectEvent(1); + probe.ExpectEvent(1); - t = queue.OfferAsync(2); - t.Wait(TimeSpan.FromSeconds(1)).ShouldBeTrue(); - t.Result.ShouldBe(QueueOfferResult.Enqueued.Instance); + t = queue.OfferAsync(2); + t.Wait(TimeSpan.FromSeconds(1)).ShouldBeTrue(); + t.Result.ShouldBe(QueueOfferResult.Enqueued.Instance); - probe.ExpectEvent(2); + probe.ExpectEvent(2); - d1.Dispose(); + d1.Dispose(); - t = queue.OfferAsync(3); - t.Wait(TimeSpan.FromSeconds(1)).ShouldBeTrue(); + t = queue.OfferAsync(3); + t.Wait(TimeSpan.FromSeconds(1)).ShouldBeTrue(); - probe.ExpectCompleted(); - probe.ExpectNoMsg(); + probe.ExpectCompleted(); + probe.ExpectNoMsg(); } } } diff --git a/src/core/Akka.Streams.Tests/Dsl/ObservableSourceSpec.cs b/src/core/Akka.Streams.Tests/Dsl/ObservableSourceSpec.cs index 509b47dab29..065a8cfb13a 100644 --- a/src/core/Akka.Streams.Tests/Dsl/ObservableSourceSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/ObservableSourceSpec.cs @@ -8,6 +8,7 @@ using System; using System.Runtime.CompilerServices; using System.Threading; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -71,9 +72,9 @@ public ObservableSourceSpec(ITestOutputHelper helper) : base(SpecConfig, helper) } [Fact] - public void An_ObservableSource_must_subscribe_to_an_observable() + public async Task An_ObservableSource_must_subscribe_to_an_observable() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var o = new TestObservable(); @@ -89,9 +90,9 @@ public void An_ObservableSource_must_subscribe_to_an_observable() } [Fact] - public void An_ObservableSource_must_receive_events_from_an_observable() + public async Task An_ObservableSource_must_receive_events_from_an_observable() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var o = new TestObservable(); var s = this.CreateManualSubscriberProbe(); @@ -125,9 +126,9 @@ public void An_ObservableSource_must_receive_events_from_an_observable() } [Fact] - public void An_ObservableSource_must_receive_errors_from_an_observable() + public async Task An_ObservableSource_must_receive_errors_from_an_observable() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var o = new TestObservable(); var s = this.CreateManualSubscriberProbe(); @@ -151,9 +152,9 @@ public void An_ObservableSource_must_receive_errors_from_an_observable() } [Fact] - public void An_ObservableSource_must_receive_completion_from_an_observable() + public async Task An_ObservableSource_must_receive_completion_from_an_observable() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var o = new TestObservable(); var s = this.CreateManualSubscriberProbe(); @@ -173,9 +174,9 @@ public void An_ObservableSource_must_receive_completion_from_an_observable() } [Fact] - public void An_ObservableSource_must_be_able_to_unsubscribe() + public async Task An_ObservableSource_must_be_able_to_unsubscribe() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var o = new TestObservable(); var s = this.CreateManualSubscriberProbe(); @@ -196,9 +197,9 @@ public void An_ObservableSource_must_be_able_to_unsubscribe() } [Fact] - public void An_ObservableSource_must_ignore_new_element_on_DropNew_overflow() + public async Task An_ObservableSource_must_ignore_new_element_on_DropNew_overflow() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var o = new TestObservable(); var s = this.CreateManualSubscriberProbe(); @@ -223,9 +224,9 @@ public void An_ObservableSource_must_ignore_new_element_on_DropNew_overflow() } [Fact] - public void An_ObservableSource_must_drop_oldest_element_on_DropHead_overflow() + public async Task An_ObservableSource_must_drop_oldest_element_on_DropHead_overflow() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var o = new TestObservable(); var s = this.CreateManualSubscriberProbe(); @@ -250,9 +251,9 @@ public void An_ObservableSource_must_drop_oldest_element_on_DropHead_overflow() } [Fact] - public void An_ObservableSource_must_drop_newest_element_on_DropTail_overflow() + public async Task An_ObservableSource_must_drop_newest_element_on_DropTail_overflow() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var o = new TestObservable(); var s = this.CreateManualSubscriberProbe(); @@ -277,9 +278,9 @@ public void An_ObservableSource_must_drop_newest_element_on_DropTail_overflow() } [Fact] - public void An_ObservableSource_must_fail_on_Fail_overflow() + public async Task An_ObservableSource_must_fail_on_Fail_overflow() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var o = new TestObservable(); var s = this.CreateManualSubscriberProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/PublisherSinkSpec.cs b/src/core/Akka.Streams.Tests/Dsl/PublisherSinkSpec.cs index 5364709af0e..6794dc8d8ae 100644 --- a/src/core/Akka.Streams.Tests/Dsl/PublisherSinkSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/PublisherSinkSpec.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit.Tests; using Akka.TestKit; @@ -28,9 +29,9 @@ public PublisherSinkSpec(ITestOutputHelper helper) : base(helper) } [Fact] - public void A_PublisherSink_must_be_unique_when_created_twice() + public async Task A_PublisherSink_must_be_unique_when_created_twice() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = RunnableGraph.FromGraph( diff --git a/src/core/Akka.Streams.Tests/Dsl/QueueSinkSpec.cs b/src/core/Akka.Streams.Tests/Dsl/QueueSinkSpec.cs index aa5b1e32f08..5a4c66bf108 100644 --- a/src/core/Akka.Streams.Tests/Dsl/QueueSinkSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/QueueSinkSpec.cs @@ -39,9 +39,9 @@ public QueueSinkSpec(ITestOutputHelper output) : base(output) } [Fact] - public void QueueSink_should_send_the_elements_as_result_of_future() + public async Task QueueSink_should_send_the_elements_as_result_of_future() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var expected = new List> { @@ -62,9 +62,9 @@ public void QueueSink_should_send_the_elements_as_result_of_future() } [Fact] - public void QueueSink_should_allow_to_have_only_one_future_waiting_for_result_in_each_point_in_time() + public async Task QueueSink_should_allow_to_have_only_one_future_waiting_for_result_in_each_point_in_time() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateManualPublisherProbe(); var queue = Source.FromPublisher(probe).RunWith(Sink.Queue(), _materializer); @@ -83,9 +83,9 @@ public void QueueSink_should_allow_to_have_only_one_future_waiting_for_result_in } [Fact] - public void QueueSink_should_wait_for_next_element_from_upstream() + public async Task QueueSink_should_wait_for_next_element_from_upstream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateManualPublisherProbe(); var queue = Source.FromPublisher(probe).RunWith(Sink.Queue(), _materializer); @@ -102,9 +102,9 @@ public void QueueSink_should_wait_for_next_element_from_upstream() } [Fact] - public void QueueSink_should_fail_future_on_stream_failure() + public async Task QueueSink_should_fail_future_on_stream_failure() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateManualPublisherProbe(); var queue = Source.FromPublisher(probe).RunWith(Sink.Queue(), _materializer); @@ -120,9 +120,9 @@ public void QueueSink_should_fail_future_on_stream_failure() } [Fact] - public void QueueSink_should_fail_future_when_stream_failed() + public async Task QueueSink_should_fail_future_when_stream_failed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateManualPublisherProbe(); var queue = Source.FromPublisher(probe).RunWith(Sink.Queue(), _materializer); @@ -135,9 +135,9 @@ public void QueueSink_should_fail_future_when_stream_failed() } [Fact] - public void QueueSink_should_timeout_future_when_stream_cannot_provide_data() + public async Task QueueSink_should_timeout_future_when_stream_cannot_provide_data() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateManualPublisherProbe(); var queue = Source.FromPublisher(probe).RunWith(Sink.Queue(), _materializer); @@ -154,9 +154,9 @@ public void QueueSink_should_timeout_future_when_stream_cannot_provide_data() } [Fact] - public void QueueSink_should_fail_pull_future_when_stream_is_completed() + public async Task QueueSink_should_fail_pull_future_when_stream_is_completed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = this.CreateManualPublisherProbe(); var queue = Source.FromPublisher(probe).RunWith(Sink.Queue(), _materializer); @@ -179,9 +179,9 @@ public void QueueSink_should_fail_pull_future_when_stream_is_completed() } [Fact] - public void QueueSink_should_keep_on_sending_even_after_the_buffer_has_been_full() + public async Task QueueSink_should_keep_on_sending_even_after_the_buffer_has_been_full() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { const int bufferSize = 16; const int streamElementCount = bufferSize + 4; @@ -207,9 +207,9 @@ public void QueueSink_should_keep_on_sending_even_after_the_buffer_has_been_full } [Fact] - public void QueueSink_should_work_with_one_element_buffer() + public async Task QueueSink_should_work_with_one_element_buffer() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var sink = Sink.Queue().WithAttributes(Attributes.CreateInputBuffer(1, 1)); var probe = this.CreateManualPublisherProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/QueueSourceSpec.cs b/src/core/Akka.Streams.Tests/Dsl/QueueSourceSpec.cs index 629d212c882..21adc3394f6 100644 --- a/src/core/Akka.Streams.Tests/Dsl/QueueSourceSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/QueueSourceSpec.cs @@ -114,9 +114,9 @@ public void QueueSource_should_buffer_when_needed() } [Fact] - public void QueueSource_should_not_fail_when_0_buffer_space_and_demand_is_signalled() + public async Task QueueSource_should_not_fail_when_0_buffer_space_and_demand_is_signalled() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s = this.CreateManualSubscriberProbe(); var queue = @@ -133,9 +133,9 @@ public void QueueSource_should_not_fail_when_0_buffer_space_and_demand_is_signal } [Fact] - public void QueueSource_should_wait_for_demand_when_buffer_is_0() + public async Task QueueSource_should_wait_for_demand_when_buffer_is_0() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s = this.CreateManualSubscriberProbe(); var queue = @@ -154,9 +154,9 @@ public void QueueSource_should_wait_for_demand_when_buffer_is_0() } [Fact] - public void QueueSource_should_finish_offer_and_complete_futures_when_stream_completed() + public async Task QueueSource_should_finish_offer_and_complete_futures_when_stream_completed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s = this.CreateManualSubscriberProbe(); var queue = @@ -178,9 +178,9 @@ public void QueueSource_should_finish_offer_and_complete_futures_when_stream_com } [Fact] - public void QueueSource_should_fail_stream_on_buffer_overflow_in_fail_mode() + public async Task QueueSource_should_fail_stream_on_buffer_overflow_in_fail_mode() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s = this.CreateManualSubscriberProbe(); var queue = @@ -196,9 +196,9 @@ public void QueueSource_should_fail_stream_on_buffer_overflow_in_fail_mode() } [Fact] - public void QueueSource_should_remember_pull_from_downstream_to_send_offered_element_immediately() + public async Task QueueSource_should_remember_pull_from_downstream_to_send_offered_element_immediately() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s = this.CreateManualSubscriberProbe(); var probe = CreateTestProbe(); @@ -217,9 +217,9 @@ public void QueueSource_should_remember_pull_from_downstream_to_send_offered_ele } [Fact] - public void QueueSource_should_fail_offer_future_if_user_does_not_wait_in_backpressure_mode() + public async Task QueueSource_should_fail_offer_future_if_user_does_not_wait_in_backpressure_mode() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var tuple = Source.Queue(5, OverflowStrategy.Backpressure) @@ -245,9 +245,9 @@ public void QueueSource_should_fail_offer_future_if_user_does_not_wait_in_backpr } [Fact] - public void QueueSource_should_complete_watching_future_with_failure_if_stream_failed() + public async Task QueueSource_should_complete_watching_future_with_failure_if_stream_failed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s = this.CreateManualSubscriberProbe(); var queue = @@ -262,9 +262,9 @@ public void QueueSource_should_complete_watching_future_with_failure_if_stream_f } [Fact] - public void QueueSource_should_return_false_when_element_was_not_added_to_buffer() + public async Task QueueSource_should_return_false_when_element_was_not_added_to_buffer() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s = this.CreateManualSubscriberProbe(); var queue = @@ -284,9 +284,9 @@ public void QueueSource_should_return_false_when_element_was_not_added_to_buffer } [Fact] - public void QueueSource_should_wait_when_buffer_is_full_and_backpressure_is_on() + public async Task QueueSource_should_wait_when_buffer_is_full_and_backpressure_is_on() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s = this.CreateManualSubscriberProbe(); var queue = @@ -311,9 +311,9 @@ public void QueueSource_should_wait_when_buffer_is_full_and_backpressure_is_on() } [Fact] - public void QueueSource_should_fail_offer_future_when_stream_is_completed() + public async Task QueueSource_should_fail_offer_future_when_stream_is_completed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var s = this.CreateManualSubscriberProbe(); var queue = diff --git a/src/core/Akka.Streams.Tests/Dsl/RestartSpec.cs b/src/core/Akka.Streams.Tests/Dsl/RestartSpec.cs index ce9ca5cf388..4d8776c8b19 100644 --- a/src/core/Akka.Streams.Tests/Dsl/RestartSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/RestartSpec.cs @@ -36,9 +36,9 @@ public RestartSpec(ITestOutputHelper output) : base("", output) // [Fact] - public void A_restart_with_backoff_source_should_run_normally() + public async Task A_restart_with_backoff_source_should_run_normally() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var created = new AtomicCounter(0); var probe = RestartSource.WithBackoff(() => @@ -60,9 +60,9 @@ public void A_restart_with_backoff_source_should_run_normally() } [Fact] - public void A_restart_with_backoff_source_should_restart_on_completion() + public async Task A_restart_with_backoff_source_should_restart_on_completion() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var created = new AtomicCounter(0); var probe = RestartSource.WithBackoff(() => @@ -84,9 +84,9 @@ public void A_restart_with_backoff_source_should_restart_on_completion() } [Fact] - public void A_restart_with_backoff_source_should_restart_on_failure() + public async Task A_restart_with_backoff_source_should_restart_on_failure() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var created = new AtomicCounter(0); var probe = RestartSource.WithBackoff(() => @@ -114,9 +114,9 @@ public void A_restart_with_backoff_source_should_restart_on_failure() } [Fact] - public void A_restart_with_backoff_source_should_backoff_before_restart() + public async Task A_restart_with_backoff_source_should_backoff_before_restart() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var created = new AtomicCounter(0); var probe = RestartSource.WithBackoff(() => @@ -141,9 +141,9 @@ public void A_restart_with_backoff_source_should_backoff_before_restart() } [Fact] - public void A_restart_with_backoff_source_should_reset_exponential_backoff_back_to_minimum_when_source_runs_for_at_least_minimum_backoff_without_completing() + public async Task A_restart_with_backoff_source_should_reset_exponential_backoff_back_to_minimum_when_source_runs_for_at_least_minimum_backoff_without_completing() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var created = new AtomicCounter(0); var probe = RestartSource.WithBackoff(() => @@ -177,9 +177,9 @@ public void A_restart_with_backoff_source_should_reset_exponential_backoff_back_ } [Fact] - public void A_restart_with_backoff_source_should_cancel_the_currently_running_source_when_cancelled() + public async Task A_restart_with_backoff_source_should_cancel_the_currently_running_source_when_cancelled() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var created = new AtomicCounter(0); var tcs = new TaskCompletionSource(); @@ -206,9 +206,9 @@ public void A_restart_with_backoff_source_should_cancel_the_currently_running_so } [Fact] - public void A_restart_with_backoff_source_should_not_restart_the_source_when_cancelled_while_backing_off() + public async Task A_restart_with_backoff_source_should_not_restart_the_source_when_cancelled_while_backing_off() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var created = new AtomicCounter(0); var probe = RestartSource.WithBackoff(() => @@ -229,9 +229,9 @@ public void A_restart_with_backoff_source_should_not_restart_the_source_when_can } [Fact] - public void A_restart_with_backoff_source_should_stop_on_completion_if_it_should_only_be_restarted_in_failures() + public async Task A_restart_with_backoff_source_should_stop_on_completion_if_it_should_only_be_restarted_in_failures() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var created = new AtomicCounter(0); var probe = RestartSource.OnFailuresWithBackoff(() => @@ -262,9 +262,9 @@ public void A_restart_with_backoff_source_should_stop_on_completion_if_it_should } [Fact] - public void A_restart_with_backoff_source_should_restart_on_failure_when_only_due_to_failures_should_be_restarted() + public async Task A_restart_with_backoff_source_should_restart_on_failure_when_only_due_to_failures_should_be_restarted() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var created = new AtomicCounter(0); var probe = RestartSource.OnFailuresWithBackoff(() => @@ -292,9 +292,9 @@ public void A_restart_with_backoff_source_should_restart_on_failure_when_only_du } [Fact] - public void A_restart_with_backoff_source_should_not_restart_the_source_when_maxRestarts_is_reached() + public async Task A_restart_with_backoff_source_should_not_restart_the_source_when_maxRestarts_is_reached() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var created = new AtomicCounter(0); var probe = RestartSource.WithBackoff(() => @@ -314,9 +314,9 @@ public void A_restart_with_backoff_source_should_not_restart_the_source_when_max } [Fact] - public void A_restart_with_backoff_source_should_reset_maxRestarts_when_source_runs_for_at_least_minimum_backoff_without_completing() + public async Task A_restart_with_backoff_source_should_reset_maxRestarts_when_source_runs_for_at_least_minimum_backoff_without_completing() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var created = new AtomicCounter(0); var probe = RestartSource.WithBackoff(() => @@ -350,9 +350,9 @@ public void A_restart_with_backoff_source_should_reset_maxRestarts_when_source_r // [Fact] - public void A_restart_with_backoff_sink_should_run_normally() + public async Task A_restart_with_backoff_sink_should_run_normally() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var created = new AtomicCounter(0); var tcs = new TaskCompletionSource>(); @@ -377,9 +377,9 @@ public void A_restart_with_backoff_sink_should_run_normally() } [Fact] - public void A_restart_with_backoff_sink_should_restart_on_cancellation() + public async Task A_restart_with_backoff_sink_should_restart_on_cancellation() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var created = new AtomicCounter(0); var tuple = this.SourceProbe().ToMaterialized(this.SinkProbe(), Keep.Both).Run(Materializer); @@ -410,9 +410,9 @@ public void A_restart_with_backoff_sink_should_restart_on_cancellation() } [Fact] - public void A_restart_with_backoff_sink_should_backoff_before_restart() + public async Task A_restart_with_backoff_sink_should_backoff_before_restart() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var created = new AtomicCounter(0); var tuple = this.SourceProbe().ToMaterialized(this.SinkProbe(), Keep.Both).Run(Materializer); @@ -443,9 +443,9 @@ public void A_restart_with_backoff_sink_should_backoff_before_restart() } [Fact] - public void A_restart_with_backoff_sink_should_reset_exponential_backoff_back_to_minimum_when_source_runs_for_at_least_minimum_backoff_without_completing() + public async Task A_restart_with_backoff_sink_should_reset_exponential_backoff_back_to_minimum_when_source_runs_for_at_least_minimum_backoff_without_completing() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var created = new AtomicCounter(0); var tuple = this.SourceProbe().ToMaterialized(this.SinkProbe(), Keep.Both).Run(Materializer); @@ -491,9 +491,9 @@ public void A_restart_with_backoff_sink_should_reset_exponential_backoff_back_to } [Fact] - public void A_restart_with_backoff_sink_should_not_restart_the_sink_when_completed_while_backing_off() + public async Task A_restart_with_backoff_sink_should_not_restart_the_sink_when_completed_while_backing_off() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var created = new AtomicCounter(0); var tuple = this.SourceProbe().ToMaterialized(this.SinkProbe(), Keep.Both).Run(Materializer); @@ -588,9 +588,9 @@ private static Flow RestartFlowFactory(Func } [Fact] - public void A_restart_with_backoff_flow_should_run_normally() + public async Task A_restart_with_backoff_flow_should_run_normally() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var created = new AtomicCounter(0); var tuple = this.SourceProbe().ViaMaterialized(RestartFlow.WithBackoff(() => @@ -734,9 +734,9 @@ public void A_restart_with_backoff_flow_should_backoff_before_restart() } [Fact] - public void A_restart_with_backoff_flow_should_continue_running_flow_out_port_after_in_has_been_sent_completion() + public async Task A_restart_with_backoff_flow_should_continue_running_flow_out_port_after_in_has_been_sent_completion() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var tuple = SetupFlow(TimeSpan.FromMilliseconds(20), TimeSpan.FromMilliseconds(40)); var created = tuple.Item1; diff --git a/src/core/Akka.Streams.Tests/Dsl/SinkForeachParallelSpec.cs b/src/core/Akka.Streams.Tests/Dsl/SinkForeachParallelSpec.cs index c9abbfa0bcb..a925d4f6cf7 100644 --- a/src/core/Akka.Streams.Tests/Dsl/SinkForeachParallelSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/SinkForeachParallelSpec.cs @@ -18,6 +18,7 @@ using Xunit.Abstractions; using System.Collections.Generic; using System.Threading; +using System.Threading.Tasks; namespace Akka.Streams.Tests.Dsl { @@ -32,9 +33,9 @@ public SinkForeachParallelSpec(ITestOutputHelper helper) : base(helper) } [Fact] - public void A_ForeachParallel_must_produce_elements_in_the_order_they_are_ready() + public async Task A_ForeachParallel_must_produce_elements_in_the_order_they_are_ready() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = CreateTestProbe(); var latch = Enumerable.Range(1, 4) @@ -64,9 +65,9 @@ public void A_ForeachParallel_must_produce_elements_in_the_order_they_are_ready( } [Fact(Skip = "Racy - timing is rather sensitive on Azure DevOps")] - public void A_ForeachParallel_must_not_run_more_functions_in_parallel_then_specified() + public async Task A_ForeachParallel_must_not_run_more_functions_in_parallel_then_specified() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = CreateTestProbe(); var latch = Enumerable.Range(1, 5) @@ -95,9 +96,9 @@ public void A_ForeachParallel_must_not_run_more_functions_in_parallel_then_speci } [Fact] - public void A_ForeachParallel_must_resume_after_function_failure() + public async Task A_ForeachParallel_must_resume_after_function_failure() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = CreateTestProbe(); var latch = new TestLatch(1); @@ -119,9 +120,9 @@ public void A_ForeachParallel_must_resume_after_function_failure() } [Fact] - public void A_ForeachParallel_must_finish_after_function_thrown_exception() + public async Task A_ForeachParallel_must_finish_after_function_thrown_exception() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = CreateTestProbe(); var latch = new TestLatch(1); @@ -149,9 +150,9 @@ public void A_ForeachParallel_must_finish_after_function_thrown_exception() } [Fact] - public void A_ForeachParallel_must_handle_empty_source() + public async Task A_ForeachParallel_must_handle_empty_source() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = Source.From(new List()).RunWith(Sink.ForEachParallel(3, i => { }), Materializer); p.Wait(TimeSpan.FromSeconds(2)).Should().BeTrue(); diff --git a/src/core/Akka.Streams.Tests/Dsl/SourceSpec.cs b/src/core/Akka.Streams.Tests/Dsl/SourceSpec.cs index 101bee056b4..4da7b41c987 100644 --- a/src/core/Akka.Streams.Tests/Dsl/SourceSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/SourceSpec.cs @@ -91,9 +91,9 @@ public void Failed_Source_must_emit_error_immediately() } [Fact] - public void Maybe_Source_must_complete_materialized_future_with_None_when_stream_cancels() + public async Task Maybe_Source_must_complete_materialized_future_with_None_when_stream_cancels() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var neverSource = Source.Maybe(); var pubSink = Sink.AsPublisher(false); @@ -115,9 +115,9 @@ public void Maybe_Source_must_complete_materialized_future_with_None_when_stream } [Fact] - public void Maybe_Source_must_allow_external_triggering_of_empty_completion() + public async Task Maybe_Source_must_allow_external_triggering_of_empty_completion() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var neverSource = Source.Maybe().Where(_ => false); var counterSink = Sink.Aggregate(0, (acc, _) => acc + 1); @@ -134,9 +134,9 @@ public void Maybe_Source_must_allow_external_triggering_of_empty_completion() } [Fact] - public void Maybe_Source_must_allow_external_triggering_of_non_empty_completion() + public async Task Maybe_Source_must_allow_external_triggering_of_non_empty_completion() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var neverSource = Source.Maybe(); var counterSink = Sink.First(); @@ -153,9 +153,9 @@ public void Maybe_Source_must_allow_external_triggering_of_non_empty_completion( } [Fact] - public void Maybe_Source_must_allow_external_triggering_of_OnError() + public async Task Maybe_Source_must_allow_external_triggering_of_OnError() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var neverSource = Source.Maybe(); var counterSink = Sink.First(); diff --git a/src/core/Akka.Streams.Tests/Dsl/SubscriberSinkSpec.cs b/src/core/Akka.Streams.Tests/Dsl/SubscriberSinkSpec.cs index f5cce75b906..d3fac167227 100644 --- a/src/core/Akka.Streams.Tests/Dsl/SubscriberSinkSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/SubscriberSinkSpec.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -26,9 +27,9 @@ public SubscriberSinkSpec(ITestOutputHelper helper = null) : base(helper) } [Fact] - public void A_Flow_with_SubscriberSink_must_publish_elements_to_the_subscriber() + public async Task A_Flow_with_SubscriberSink_must_publish_elements_to_the_subscriber() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c = this.CreateManualSubscriberProbe(); Source.From(Enumerable.Range(1, 3)).To(Sink.FromSubscriber(c)).Run(Materializer); diff --git a/src/core/Akka.Streams.Tests/Dsl/SubstreamSubscriptionTimeoutSpec.cs b/src/core/Akka.Streams.Tests/Dsl/SubstreamSubscriptionTimeoutSpec.cs index 130017f9a86..7f6d0ef08d6 100644 --- a/src/core/Akka.Streams.Tests/Dsl/SubstreamSubscriptionTimeoutSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/SubstreamSubscriptionTimeoutSpec.cs @@ -7,6 +7,7 @@ using System; using System.Threading; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.Implementation; using Akka.Streams.TestKit; @@ -40,9 +41,9 @@ public SubstreamSubscriptionTimeoutSpec(ITestOutputHelper helper) : base(Config, } [Fact] - public void GroupBy_and_SplitWhen_must_timeout_and_cancel_substream_publisher_when_no_one_subscribes_to_them_after_some_time() + public async Task GroupBy_and_SplitWhen_must_timeout_and_cancel_substream_publisher_when_no_one_subscribes_to_them_after_some_time() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber = this.CreateManualSubscriberProbe<(int, Source)>(); var publisherProbe = this.CreatePublisherProbe(); @@ -88,9 +89,9 @@ public void GroupBy_and_SplitWhen_must_timeout_and_cancel_substream_publisher_wh } [Fact] - public void GroupBy_and_SplitWhen_must_timeout_and_stop_groupBy_parent_actor_if_none_of_the_substreams_are_actually_consumed() + public async Task GroupBy_and_SplitWhen_must_timeout_and_stop_groupBy_parent_actor_if_none_of_the_substreams_are_actually_consumed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber = this.CreateManualSubscriberProbe<(int, Source)>(); var publisherProbe = this.CreatePublisherProbe(); diff --git a/src/core/Akka.Streams.Tests/Dsl/TickSourceSpec.cs b/src/core/Akka.Streams.Tests/Dsl/TickSourceSpec.cs index e3d76f49bfa..78817f72f9f 100644 --- a/src/core/Akka.Streams.Tests/Dsl/TickSourceSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/TickSourceSpec.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -28,9 +29,9 @@ public TickSourceSpec() } [Fact] - public void A_Flow_based_on_a_tick_publisher_must_produce_ticks() + public async Task A_Flow_based_on_a_tick_publisher_must_produce_ticks() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c = this.CreateManualSubscriberProbe(); Source.Tick(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1), "tick") @@ -68,9 +69,9 @@ public void A_Flow_based_on_a_tick_publisher_must_drop_ticks_when_not_requested( } [Fact] - public void A_Flow_based_on_a_tick_publisher_must_reject_multiple_subscribers_but_keep_the_firs() + public async Task A_Flow_based_on_a_tick_publisher_must_reject_multiple_subscribers_but_keep_the_firs() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = Source.Tick(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1), "tick") .RunWith(Sink.AsPublisher(false), Materializer); @@ -90,9 +91,9 @@ public void A_Flow_based_on_a_tick_publisher_must_reject_multiple_subscribers_bu } [Fact] - public void A_Flow_based_on_a_tick_publisher_must_be_usable_with_zip_for_a_simple_form_of_rate_limiting() + public async Task A_Flow_based_on_a_tick_publisher_must_be_usable_with_zip_for_a_simple_form_of_rate_limiting() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c = this.CreateManualSubscriberProbe(); RunnableGraph.FromGraph(GraphDsl.Create(b => @@ -117,9 +118,9 @@ public void A_Flow_based_on_a_tick_publisher_must_be_usable_with_zip_for_a_simpl } [Fact] - public void A_Flow_based_on_a_tick_publisher_must_be_possible_to_cancel() + public async Task A_Flow_based_on_a_tick_publisher_must_be_possible_to_cancel() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(async () => { var c = this.CreateManualSubscriberProbe(); var tickSource = Source.Tick(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1), "tick"); @@ -131,16 +132,16 @@ public void A_Flow_based_on_a_tick_publisher_must_be_possible_to_cancel() c.ExpectNoMsg(TimeSpan.FromMilliseconds(200)); c.ExpectNext("tick"); cancelable.Cancel(); - AwaitCondition(() => cancelable.IsCancellationRequested); + await AwaitConditionAsync(() => cancelable.IsCancellationRequested); sub.Request(3); c.ExpectComplete(); }, Materializer); } [Fact] - public void A_Flow_based_on_a_tick_publisher_must_have_IsCancelled_mirror_the_cancellation_state() + public async Task A_Flow_based_on_a_tick_publisher_must_have_IsCancelled_mirror_the_cancellation_state() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c = this.CreateManualSubscriberProbe(); var tickSource = Source.Tick(TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(500), "tick"); @@ -156,9 +157,9 @@ public void A_Flow_based_on_a_tick_publisher_must_have_IsCancelled_mirror_the_ca } [Fact] - public void A_Flow_based_on_a_tick_publisher_must_support_being_cancelled_immediately_after_its_materialization() + public async Task A_Flow_based_on_a_tick_publisher_must_support_being_cancelled_immediately_after_its_materialization() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var c = this.CreateManualSubscriberProbe(); var tickSource = Source.Tick(TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(500), "tick"); diff --git a/src/core/Akka.Streams.Tests/Dsl/UnfoldResourceAsyncSourceSpec.cs b/src/core/Akka.Streams.Tests/Dsl/UnfoldResourceAsyncSourceSpec.cs index b96b3b34d2d..b2097eec059 100644 --- a/src/core/Akka.Streams.Tests/Dsl/UnfoldResourceAsyncSourceSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/UnfoldResourceAsyncSourceSpec.cs @@ -72,9 +72,9 @@ public UnfoldResourceAsyncSourceSpec(ITestOutputHelper helper) : base(Utils.Unbo [Fact] - public void A_UnfoldResourceAsyncSource_must_read_contents_from_a_file() + public async Task A_UnfoldResourceAsyncSource_must_read_contents_from_a_file() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var createPromise = new TaskCompletionSource(); var readPromise = new TaskCompletionSource>(); @@ -124,9 +124,9 @@ public void A_UnfoldResourceAsyncSource_must_read_contents_from_a_file() } [Fact] - public void A_UnfoldResourceAsyncSource_must_close_resource_successfully_right_after_open() + public async Task A_UnfoldResourceAsyncSource_must_close_resource_successfully_right_after_open() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var createPromise = new TaskCompletionSource(); var readPromise = new TaskCompletionSource>(); @@ -169,9 +169,9 @@ public void A_UnfoldResourceAsyncSource_must_close_resource_successfully_right_a } [Fact] - public void A_UnfoldResourceAsyncSource_must_continue_when_strategy_is_resume_and_exception_happened() + public async Task A_UnfoldResourceAsyncSource_must_continue_when_strategy_is_resume_and_exception_happened() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = Source.UnfoldResourceAsync(_open, reader => { @@ -198,9 +198,9 @@ public void A_UnfoldResourceAsyncSource_must_continue_when_strategy_is_resume_an } [Fact] - public void A_UnfoldResourceAsyncSource_must_close_and_open_stream_again_when_strategy_is_restart() + public async Task A_UnfoldResourceAsyncSource_must_close_and_open_stream_again_when_strategy_is_restart() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = Source.UnfoldResourceAsync(_open, reader => { @@ -226,9 +226,9 @@ public void A_UnfoldResourceAsyncSource_must_close_and_open_stream_again_when_st } [Fact] - public void A_UnfoldResourceAsyncSource_must_work_with_ByteString_as_well() + public async Task A_UnfoldResourceAsyncSource_must_work_with_ByteString_as_well() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var chunkSize = 50; var buffer = new char[chunkSize]; @@ -275,9 +275,9 @@ public void A_UnfoldResourceAsyncSource_must_work_with_ByteString_as_well() } [Fact] - public void A_UnfoldResourceAsyncSource_must_use_dedicated_blocking_io_dispatcher_by_default() + public async Task A_UnfoldResourceAsyncSource_must_use_dedicated_blocking_io_dispatcher_by_default() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var sys = ActorSystem.Create("dispatcher-testing", Utils.UnboundedMailboxConfig); var materializer = sys.Materializer(); @@ -309,9 +309,9 @@ public void A_UnfoldResourceAsyncSource_must_use_dedicated_blocking_io_dispatche } [Fact] - public void A_UnfoldResourceAsyncSource_must_fail_when_create_throws_exception() + public async Task A_UnfoldResourceAsyncSource_must_fail_when_create_throws_exception() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var testException = new TestException(""); var p = Source.UnfoldResourceAsync(() => @@ -327,9 +327,9 @@ public void A_UnfoldResourceAsyncSource_must_fail_when_create_throws_exception() } [Fact] - public void A_UnfoldResourceAsyncSource_must_fail_when_close_throws_exception() + public async Task A_UnfoldResourceAsyncSource_must_fail_when_close_throws_exception() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var testException = new TestException(""); var p = Source.UnfoldResourceAsync(_open, Read, reader => diff --git a/src/core/Akka.Streams.Tests/Dsl/UnfoldResourceSourceSpec.cs b/src/core/Akka.Streams.Tests/Dsl/UnfoldResourceSourceSpec.cs index 4f3ccfde8db..a5bcf154b50 100644 --- a/src/core/Akka.Streams.Tests/Dsl/UnfoldResourceSourceSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/UnfoldResourceSourceSpec.cs @@ -9,6 +9,7 @@ using System; using System.IO; using System.Linq; +using System.Threading.Tasks; using Akka.Actor; using Akka.IO; using Akka.Streams.Dsl; @@ -66,9 +67,9 @@ public UnfoldResourceSourceSpec(ITestOutputHelper helper) : base(Utils.Unbounded [Fact] - public void A_UnfoldResourceSource_must_read_contents_from_a_file() + public async Task A_UnfoldResourceSource_must_read_contents_from_a_file() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = Source.UnfoldResource(_open, Read, Close).RunWith(Sink.AsPublisher(false), Materializer); @@ -94,9 +95,9 @@ public void A_UnfoldResourceSource_must_read_contents_from_a_file() } [Fact] - public void A_UnfoldResourceSource_must_continue_when_strategy_is_resume_and_exception_happened() + public async Task A_UnfoldResourceSource_must_continue_when_strategy_is_resume_and_exception_happened() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = Source.UnfoldResource(_open, reader => { @@ -123,9 +124,9 @@ public void A_UnfoldResourceSource_must_continue_when_strategy_is_resume_and_exc } [Fact] - public void A_UnfoldResourceSource_must_close_and_open_stream_again_when_strategy_is_restart() + public async Task A_UnfoldResourceSource_must_close_and_open_stream_again_when_strategy_is_restart() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = Source.UnfoldResource(_open, reader => { @@ -151,9 +152,9 @@ public void A_UnfoldResourceSource_must_close_and_open_stream_again_when_strateg } [Fact] - public void A_UnfoldResourceSource_must_work_with_ByteString_as_well() + public async Task A_UnfoldResourceSource_must_work_with_ByteString_as_well() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var chunkSize = 50; var buffer = new char[chunkSize]; @@ -193,9 +194,9 @@ public void A_UnfoldResourceSource_must_work_with_ByteString_as_well() } [Fact] - public void A_UnfoldResourceSource_must_use_dedicated_blocking_io_dispatcher_by_default() + public async Task A_UnfoldResourceSource_must_use_dedicated_blocking_io_dispatcher_by_default() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var sys = ActorSystem.Create("dispatcher-testing", Utils.UnboundedMailboxConfig); var materializer = sys.Materializer(); @@ -227,9 +228,9 @@ public void A_UnfoldResourceSource_must_use_dedicated_blocking_io_dispatcher_by_ } [Fact] - public void A_UnfoldResourceSource_must_fail_when_create_throws_exception() + public async Task A_UnfoldResourceSource_must_fail_when_create_throws_exception() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var testException = new TestException(""); var p = Source.UnfoldResource(() => @@ -245,9 +246,9 @@ public void A_UnfoldResourceSource_must_fail_when_create_throws_exception() } [Fact] - public void A_UnfoldResourceSource_must_fail_when_close_throws_exception() + public async Task A_UnfoldResourceSource_must_fail_when_close_throws_exception() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var testException = new TestException(""); var p = Source.UnfoldResource(_open, Read, reader => diff --git a/src/core/Akka.Streams.Tests/Extra/FlowTimedSpec.cs b/src/core/Akka.Streams.Tests/Extra/FlowTimedSpec.cs index 3afc5af4f18..8cfa1d69015 100644 --- a/src/core/Akka.Streams.Tests/Extra/FlowTimedSpec.cs +++ b/src/core/Akka.Streams.Tests/Extra/FlowTimedSpec.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Akka.Actor; using Akka.Streams.Dsl; using Akka.Streams.Extra; @@ -88,9 +89,9 @@ public void Timed_Source_must_measure_time_it_takes_from_start_to_complete_by_wr [Fact] - public void Timed_Flow_must_measure_time_it_takes_between_elements_matching_a_predicate() + public async Task Timed_Flow_must_measure_time_it_takes_between_elements_matching_a_predicate() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = CreateTestProbe(); @@ -113,9 +114,9 @@ public void Timed_Flow_must_measure_time_it_takes_between_elements_matching_a_pr } [Fact] - public void Timed_Flow_must_measure_time_it_takes_from_start_to_complete_by_wrapping_operations() + public async Task Timed_Flow_must_measure_time_it_takes_from_start_to_complete_by_wrapping_operations() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var probe = CreateTestProbe(); diff --git a/src/core/Akka.Streams.Tests/IO/FileSinkSpec.cs b/src/core/Akka.Streams.Tests/IO/FileSinkSpec.cs index d25805b11ef..4413291ad35 100644 --- a/src/core/Akka.Streams.Tests/IO/FileSinkSpec.cs +++ b/src/core/Akka.Streams.Tests/IO/FileSinkSpec.cs @@ -52,9 +52,9 @@ public FileSinkSpec(ITestOutputHelper helper) : base(Utils.UnboundedMailboxConfi } [Fact] - public void SynchronousFileSink_should_write_lines_to_a_file() + public async Task SynchronousFileSink_should_write_lines_to_a_file() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { TargetFile(f => { @@ -69,9 +69,9 @@ public void SynchronousFileSink_should_write_lines_to_a_file() } [Fact] - public void SynchronousFileSink_should_create_new_file_if_not_exists() + public async Task SynchronousFileSink_should_create_new_file_if_not_exists() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { TargetFile(f => { @@ -85,9 +85,9 @@ public void SynchronousFileSink_should_create_new_file_if_not_exists() } [Fact] - public void SynchronousFileSink_should_write_into_existing_file_without_wiping_existing_data() + public async Task SynchronousFileSink_should_write_into_existing_file_without_wiping_existing_data() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { TargetFile(f => { @@ -115,9 +115,9 @@ Task Write(IEnumerable lines) => Source.From(lines) } [Fact] - public void SynchronousFileSink_should_by_default_replace_the_existing_file() + public async Task SynchronousFileSink_should_by_default_replace_the_existing_file() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { TargetFile(f => { @@ -137,9 +137,9 @@ Task Write(List lines) => } [Fact] - public void SynchronousFileSink_should_allow_appending_to_file() + public async Task SynchronousFileSink_should_allow_appending_to_file() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { TargetFile(f => { @@ -171,9 +171,9 @@ Task Write(List lines) => Source.From(lines) } [Fact] - public void SynchronousFileSink_should_allow_writing_from_specific_position_to_the_file() + public async Task SynchronousFileSink_should_allow_writing_from_specific_position_to_the_file() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { TargetFile(f => { @@ -211,9 +211,9 @@ Task Write(List lines, long pos) => Source.From(lines) } [Fact] - public void SynchronousFileSink_should_use_dedicated_blocking_io_dispatcher_by_default() + public async Task SynchronousFileSink_should_use_dedicated_blocking_io_dispatcher_by_default() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { TargetFile(f => { @@ -242,9 +242,9 @@ public void SynchronousFileSink_should_use_dedicated_blocking_io_dispatcher_by_d // FIXME: overriding dispatcher should be made available with dispatcher alias support in materializer (#17929) [Fact(Skip = "overriding dispatcher should be made available with dispatcher alias support in materializer")] - public void SynchronousFileSink_should_allow_overriding_the_dispatcher_using_Attributes() + public async Task SynchronousFileSink_should_allow_overriding_the_dispatcher_using_Attributes() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { TargetFile(f => { @@ -272,9 +272,9 @@ public void SynchronousFileSink_should_allow_overriding_the_dispatcher_using_Att } [Fact] - public void SynchronousFileSink_should_write_single_line_to_a_file_from_lazy_sink() + public async Task SynchronousFileSink_should_write_single_line_to_a_file_from_lazy_sink() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { TargetFile(f => { diff --git a/src/core/Akka.Streams.Tests/IO/FileSourceSpec.cs b/src/core/Akka.Streams.Tests/IO/FileSourceSpec.cs index 4ee8d847cbe..021366ce49a 100644 --- a/src/core/Akka.Streams.Tests/IO/FileSourceSpec.cs +++ b/src/core/Akka.Streams.Tests/IO/FileSourceSpec.cs @@ -11,6 +11,7 @@ using System.Linq; using System.Text; using System.Threading; +using System.Threading.Tasks; using Akka.Actor; using Akka.IO; using Akka.Streams.Dsl; @@ -48,9 +49,9 @@ public FileSourceSpec(ITestOutputHelper helper) : base(Utils.UnboundedMailboxCon } [Fact] - public void FileSource_should_read_contents_from_a_file() + public async Task FileSource_should_read_contents_from_a_file() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var chunkSize = 512; var bufferAttributes = Attributes.CreateInputBuffer(1, 2); @@ -102,9 +103,9 @@ public void FileSource_should_read_contents_from_a_file() } [Fact] - public void Filesource_could_read_partial_contents_from_a_file() + public async Task Filesource_could_read_partial_contents_from_a_file() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var chunkSize = 512; var startPosition = 1000; @@ -151,9 +152,9 @@ public void Filesource_could_read_partial_contents_from_a_file() } [Fact] - public void FileSource_should_complete_only_when_all_contents_of_a_file_have_been_signalled() + public async Task FileSource_should_complete_only_when_all_contents_of_a_file_have_been_signalled() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var chunkSize = 512; var bufferAttributes = Attributes.CreateInputBuffer(1, 2); @@ -202,9 +203,9 @@ public void FileSource_should_complete_only_when_all_contents_of_a_file_have_bee } [Fact] - public void FileSource_should_open_file_in_shared_mode_for_reading_multiple_times() + public async Task FileSource_should_open_file_in_shared_mode_for_reading_multiple_times() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var testFile = TestFile(); var p1 = FileIO.FromFile(testFile).RunWith(Sink.AsPublisher(false), _materializer); @@ -227,9 +228,9 @@ public void FileSource_should_open_file_in_shared_mode_for_reading_multiple_time } [Fact] - public void FileSource_should_onError_with_failure_and_return_a_failed_IOResult_when_trying_to_read_from_file_which_does_not_exist() + public async Task FileSource_should_onError_with_failure_and_return_a_failed_IOResult_when_trying_to_read_from_file_which_does_not_exist() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = FileIO.FromFile(NotExistingFile()) .ToMaterialized(Sink.AsPublisher(false), Keep.Both) @@ -265,9 +266,9 @@ public void FileSource_should_count_lines_in_a_real_file(int chunkSize, int read } [Fact] - public void FileSource_should_use_dedicated_blocking_io_dispatcher_by_default() + public async Task FileSource_should_use_dedicated_blocking_io_dispatcher_by_default() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var sys = ActorSystem.Create("dispatcher-testing", Utils.UnboundedMailboxConfig); var materializer = sys.Materializer(); diff --git a/src/core/Akka.Streams.Tests/IO/InputStreamSinkSpec.cs b/src/core/Akka.Streams.Tests/IO/InputStreamSinkSpec.cs index aed13f199c9..686c52b142d 100644 --- a/src/core/Akka.Streams.Tests/IO/InputStreamSinkSpec.cs +++ b/src/core/Akka.Streams.Tests/IO/InputStreamSinkSpec.cs @@ -37,9 +37,9 @@ public InputStreamSinkSpec(ITestOutputHelper helper) : base(Utils.UnboundedMailb } [Fact] - public void InputStreamSink_should_read_bytes_from_input_stream() + public async Task InputStreamSink_should_read_bytes_from_input_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var inputStream = Source.Single(_byteString).RunWith(StreamConverters.AsInputStream(), _materializer); var result = ReadN(inputStream, _byteString.Count); @@ -51,9 +51,9 @@ public void InputStreamSink_should_read_bytes_from_input_stream() } [Fact] - public void InputStreamSink_should_read_bytes_correctly_if_requested_by_input_stream_not_in_chunk_size() + public async Task InputStreamSink_should_read_bytes_correctly_if_requested_by_input_stream_not_in_chunk_size() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var sinkProbe = CreateTestProbe(); var byteString2 = RandomByteString(3); @@ -80,9 +80,9 @@ public void InputStreamSink_should_read_bytes_correctly_if_requested_by_input_st } [Fact] - public void InputStreamSink_should_return_less_than_was_expected_when_data_source_has_provided_some_but_not_enough_data() + public async Task InputStreamSink_should_return_less_than_was_expected_when_data_source_has_provided_some_but_not_enough_data() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var inputStream = Source.Single(_byteString).RunWith(StreamConverters.AsInputStream(), _materializer); @@ -95,9 +95,9 @@ public void InputStreamSink_should_return_less_than_was_expected_when_data_sourc } [Fact] - public void InputStreamSink_should_block_read_until_get_requested_number_of_bytes_from_upstream() + public async Task InputStreamSink_should_block_read_until_get_requested_number_of_bytes_from_upstream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var run = this.SourceProbe() @@ -121,9 +121,9 @@ public void InputStreamSink_should_block_read_until_get_requested_number_of_byte } [Fact] - public void InputStreamSink_should_throw_error_when_reactive_stream_is_closed() + public async Task InputStreamSink_should_throw_error_when_reactive_stream_is_closed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = this.SourceProbe() .ToMaterialized(StreamConverters.AsInputStream(), Keep.Both) @@ -141,9 +141,9 @@ public void InputStreamSink_should_throw_error_when_reactive_stream_is_closed() } [Fact] - public void InputStreamSink_should_return_all_data_when_upstream_is_completed() + public async Task InputStreamSink_should_return_all_data_when_upstream_is_completed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var sinkProbe = CreateTestProbe(); var t = this.SourceProbe().ToMaterialized(TestSink(sinkProbe), Keep.Both).Run(_materializer); @@ -164,9 +164,9 @@ public void InputStreamSink_should_return_all_data_when_upstream_is_completed() } [Fact] - public void InputStreamSink_should_work_when_read_chunks_smaller_then_stream_chunks() + public async Task InputStreamSink_should_work_when_read_chunks_smaller_then_stream_chunks() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var bytes = RandomByteString(10); var inputStream = Source.Single(bytes).RunWith(StreamConverters.AsInputStream(), _materializer); @@ -186,9 +186,9 @@ public void InputStreamSink_should_work_when_read_chunks_smaller_then_stream_chu } [Fact] - public void InputStreamSink_should_throw_exception_when_call_read_With_wrong_parameters() + public async Task InputStreamSink_should_throw_exception_when_call_read_With_wrong_parameters() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var inputStream = Source.Single(_byteString).RunWith(StreamConverters.AsInputStream(), _materializer); var buf = new byte[3]; @@ -203,9 +203,9 @@ public void InputStreamSink_should_throw_exception_when_call_read_With_wrong_par private Action Action(Action a) => a; [Fact] - public void InputStreamSink_should_successfully_read_several_chunks_at_once() + public async Task InputStreamSink_should_successfully_read_several_chunks_at_once() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var bytes = Enumerable.Range(1, 4).Select(_ => RandomByteString(4)).ToList(); var sinkProbe = CreateTestProbe(); @@ -226,9 +226,9 @@ public void InputStreamSink_should_successfully_read_several_chunks_at_once() } [Fact] - public void InputStreamSink_should_work_when_read_chunks_bigger_than_stream_chunks() + public async Task InputStreamSink_should_work_when_read_chunks_bigger_than_stream_chunks() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var bytes1 = RandomByteString(10); var bytes2 = RandomByteString(10); @@ -251,9 +251,9 @@ public void InputStreamSink_should_work_when_read_chunks_bigger_than_stream_chun } [Fact] - public void InputStreamSink_should_return_minus_1_when_read_after_stream_is_completed() + public async Task InputStreamSink_should_return_minus_1_when_read_after_stream_is_completed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var inputStream = Source.Single(_byteString).RunWith(StreamConverters.AsInputStream(), _materializer); @@ -267,9 +267,9 @@ public void InputStreamSink_should_return_minus_1_when_read_after_stream_is_comp } [Fact] - public void InputStreamSink_should_return_Exception_when_stream_is_failed() + public async Task InputStreamSink_should_return_Exception_when_stream_is_failed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var sinkProbe = CreateTestProbe(); var t = this.SourceProbe().ToMaterialized(TestSink(sinkProbe), Keep.Both).Run(_materializer); @@ -298,9 +298,9 @@ public void InputStreamSink_should_return_Exception_when_stream_is_failed() } [Fact] - public void InputStreamSink_should_use_dedicated_default_blocking_io_dispatcher_by_default() + public async Task InputStreamSink_should_use_dedicated_default_blocking_io_dispatcher_by_default() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var sys = ActorSystem.Create("dispatcher-testing", Utils.UnboundedMailboxConfig); var materializer = ActorMaterializer.Create(sys); @@ -320,9 +320,9 @@ public void InputStreamSink_should_use_dedicated_default_blocking_io_dispatcher_ } [Fact] - public void InputStreamSink_should_work_when_more_bytes_pulled_from_input_stream_than_available() + public async Task InputStreamSink_should_work_when_more_bytes_pulled_from_input_stream_than_available() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var inputStream = Source.Single(_byteString).RunWith(StreamConverters.AsInputStream(), _materializer); @@ -336,9 +336,9 @@ public void InputStreamSink_should_work_when_more_bytes_pulled_from_input_stream [Fact] - public void InputStreamSink_should_read_next_byte_as_an_int_from_InputStream() + public async Task InputStreamSink_should_read_next_byte_as_an_int_from_InputStream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var bytes = ByteString.CopyFrom(new byte[] { 0, 100, 200, 255 }); var inputStream = Source.Single(bytes).RunWith(StreamConverters.AsInputStream(), _materializer); diff --git a/src/core/Akka.Streams.Tests/IO/InputStreamSourceSpec.cs b/src/core/Akka.Streams.Tests/IO/InputStreamSourceSpec.cs index a17ceb42ada..8e1ebace35a 100644 --- a/src/core/Akka.Streams.Tests/IO/InputStreamSourceSpec.cs +++ b/src/core/Akka.Streams.Tests/IO/InputStreamSourceSpec.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading.Tasks; using Akka.IO; using Akka.Streams.Dsl; using Akka.Streams.TestKit; @@ -175,9 +176,9 @@ public void InputStreamSource_must_not_signal_when_no_demand() } [Fact] - public void InputStreamSource_must_read_bytes_from_InputStream() + public async Task InputStreamSource_must_read_bytes_from_InputStream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var f = StreamConverters.FromInputStream(() => new ListInputStream(new[] {"a", "b", "c"})) .RunWith(Sink.First(), _materializer); @@ -188,9 +189,9 @@ public void InputStreamSource_must_read_bytes_from_InputStream() } [Fact] - public void InputStreamSource_must_emit_as_soon_as_read() + public async Task InputStreamSource_must_emit_as_soon_as_read() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var latch = new TestLatch(1); var probe = StreamConverters.FromInputStream(() => new EmittedInputStream(latch), chunkSize: 1) diff --git a/src/core/Akka.Streams.Tests/IO/OutputStreamSinkSpec.cs b/src/core/Akka.Streams.Tests/IO/OutputStreamSinkSpec.cs index 8a464c0e5bc..f101b4c0100 100644 --- a/src/core/Akka.Streams.Tests/IO/OutputStreamSinkSpec.cs +++ b/src/core/Akka.Streams.Tests/IO/OutputStreamSinkSpec.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Threading.Tasks; using Akka.Actor; using Akka.IO; using Akka.Streams.Dsl; @@ -164,9 +165,9 @@ public OutputStreamSinkSpec(ITestOutputHelper helper) : base(Utils.UnboundedMail } [Fact] - public void OutputStreamSink_must_write_bytes_to_void_OutputStream() + public async Task OutputStreamSink_must_write_bytes_to_void_OutputStream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = CreateTestProbe(); var datas = new List @@ -187,9 +188,9 @@ public void OutputStreamSink_must_write_bytes_to_void_OutputStream() } [Fact] - public void OutputStreamSink_must_close_underlying_stream_when_error_received() + public async Task OutputStreamSink_must_close_underlying_stream_when_error_received() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = CreateTestProbe(); Source.Failed(new Exception("Boom!")) @@ -200,9 +201,9 @@ public void OutputStreamSink_must_close_underlying_stream_when_error_received() } [Fact] - public void OutputStreamSink_must_close_underlying_stream_when_completion_received() + public async Task OutputStreamSink_must_close_underlying_stream_when_completion_received() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var p = CreateTestProbe(); Source.Empty() diff --git a/src/core/Akka.Streams.Tests/IO/OutputStreamSourceSpec.cs b/src/core/Akka.Streams.Tests/IO/OutputStreamSourceSpec.cs index 2ccf2ac3fe0..2bc324d1c7c 100644 --- a/src/core/Akka.Streams.Tests/IO/OutputStreamSourceSpec.cs +++ b/src/core/Akka.Streams.Tests/IO/OutputStreamSourceSpec.cs @@ -60,9 +60,9 @@ private void ExpectSuccess(Task f, T value) } [Fact] - public void OutputStreamSource_must_read_bytes_from_OutputStream() + public async Task OutputStreamSource_must_read_bytes_from_OutputStream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = StreamConverters.AsOutputStream() .ToMaterialized(this.SinkProbe(), Keep.Both) @@ -80,9 +80,9 @@ public void OutputStreamSource_must_read_bytes_from_OutputStream() } [Fact] - public void OutputStreamSource_must_block_flush_call_until_send_all_buffer_to_downstream() + public async Task OutputStreamSource_must_block_flush_call_until_send_all_buffer_to_downstream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = StreamConverters.AsOutputStream() .ToMaterialized(this.SinkProbe(), Keep.Both) @@ -111,9 +111,9 @@ public void OutputStreamSource_must_block_flush_call_until_send_all_buffer_to_do } [Fact] - public void OutputStreamSource_must_not_block_flushes_when_buffer_is_empty() + public async Task OutputStreamSource_must_not_block_flushes_when_buffer_is_empty() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = StreamConverters.AsOutputStream() .ToMaterialized(this.SinkProbe(), Keep.Both) @@ -146,9 +146,9 @@ public void OutputStreamSource_must_not_block_flushes_when_buffer_is_empty() } [Fact] - public void OutputStreamSource_must_block_writes_when_buffer_is_full() + public async Task OutputStreamSource_must_block_writes_when_buffer_is_full() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = StreamConverters.AsOutputStream() .WithAttributes(Attributes.CreateInputBuffer(16, 16)) @@ -180,9 +180,9 @@ public void OutputStreamSource_must_block_writes_when_buffer_is_full() } [Fact] - public void OutputStreamSource_must_throw_error_when_writer_after_stream_is_closed() + public async Task OutputStreamSource_must_throw_error_when_writer_after_stream_is_closed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = StreamConverters.AsOutputStream() .ToMaterialized(this.SinkProbe(), Keep.Both) @@ -199,9 +199,9 @@ public void OutputStreamSource_must_throw_error_when_writer_after_stream_is_clos } [Fact] - public void OutputStreamSource_must_use_dedicated_default_blocking_io_dispatcher_by_default() + public async Task OutputStreamSource_must_use_dedicated_default_blocking_io_dispatcher_by_default() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var sys = ActorSystem.Create("dispatcher-testing", Utils.UnboundedMailboxConfig); var materializer = sys.Materializer(); @@ -224,9 +224,9 @@ public void OutputStreamSource_must_use_dedicated_default_blocking_io_dispatcher } [Fact] - public void OutputStreamSource_must_throw_IOException_when_writing_to_the_stream_after_the_subscriber_has_cancelled_the_reactive_stream() + public async Task OutputStreamSource_must_throw_IOException_when_writing_to_the_stream_after_the_subscriber_has_cancelled_the_reactive_stream() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var sourceProbe = CreateTestProbe(); var t = diff --git a/src/core/Akka.Streams.Tests/IO/TcpSpec.cs b/src/core/Akka.Streams.Tests/IO/TcpSpec.cs index 46a97b803a1..e62e8a68e4c 100644 --- a/src/core/Akka.Streams.Tests/IO/TcpSpec.cs +++ b/src/core/Akka.Streams.Tests/IO/TcpSpec.cs @@ -34,9 +34,9 @@ public TcpSpec(ITestOutputHelper helper) : base(@" } [Fact] - public void Outgoing_TCP_stream_must_work_in_the_happy_case() + public async Task Outgoing_TCP_stream_must_work_in_the_happy_case() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var testData = ByteString.FromBytes(new byte[] {1, 2, 3, 4, 5}); @@ -105,9 +105,9 @@ public async Task Outgoing_TCP_stream_must_be_able_to_read_a_sequence_of_ByteStr } [Fact(Skip="FIXME .net core / linux")] - public void Outgoing_TCP_stream_must_fail_the_materialized_task_when_the_connection_fails() + public async Task Outgoing_TCP_stream_must_fail_the_materialized_task_when_the_connection_fails() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var tcpWriteProbe = new TcpWriteProbe(this); var task = @@ -127,9 +127,9 @@ public void Outgoing_TCP_stream_must_fail_the_materialized_task_when_the_connect } [Fact] - public void Outgoing_TCP_stream_must_work_when_client_closes_write_then_remote_closes_write() + public async Task Outgoing_TCP_stream_must_work_when_client_closes_write_then_remote_closes_write() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var testData = ByteString.FromBytes(new byte[] { 1, 2, 3, 4, 5 }); var server = new Server(this); @@ -165,9 +165,9 @@ public void Outgoing_TCP_stream_must_work_when_client_closes_write_then_remote_c } [Fact] - public void Outgoing_TCP_stream_must_work_when_remote_closes_write_then_client_closes_write() + public async Task Outgoing_TCP_stream_must_work_when_remote_closes_write_then_client_closes_write() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var testData = ByteString.FromBytes(new byte[] {1, 2, 3, 4, 5}); var server = new Server(this); @@ -201,9 +201,9 @@ public void Outgoing_TCP_stream_must_work_when_remote_closes_write_then_client_c } [Fact(Skip = "FIXME: actually this is about half-open connection. No other .NET socket lib supports that")] - public void Outgoing_TCP_stream_must_work_when_client_closes_read_then_client_closes_write() + public async Task Outgoing_TCP_stream_must_work_when_client_closes_read_then_client_closes_write() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(async () => { var testData = ByteString.FromBytes(new byte[] { 1, 2, 3, 4, 5 }); var server = new Server(this); @@ -232,7 +232,7 @@ public void Outgoing_TCP_stream_must_work_when_client_closes_read_then_client_cl tcpWriteProbe.Close(); // Need a write on the server side to detect the close event - AwaitAssert(() => + await AwaitAssertAsync(() => { serverConnection.Write(testData); serverConnection.ExpectClosed(c => c.IsErrorClosed, TimeSpan.FromMilliseconds(500)); @@ -243,9 +243,9 @@ public void Outgoing_TCP_stream_must_work_when_client_closes_read_then_client_cl } [Fact] - public void Outgoing_TCP_stream_must_work_when_client_closes_read_then_server_closes_write_then_client_closes_write() + public async Task Outgoing_TCP_stream_must_work_when_client_closes_read_then_server_closes_write_then_client_closes_write() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var testData = ByteString.FromBytes(new byte[] { 1, 2, 3, 4, 5 }); var server = new Server(this); @@ -280,9 +280,9 @@ public void Outgoing_TCP_stream_must_work_when_client_closes_read_then_server_cl } [Fact] - public void Outgoing_TCP_stream_must_shut_everything_down_if_client_signals_error() + public async Task Outgoing_TCP_stream_must_shut_everything_down_if_client_signals_error() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var testData = ByteString.FromBytes(new byte[] { 1, 2, 3, 4, 5 }); var server = new Server(this); @@ -314,9 +314,9 @@ public void Outgoing_TCP_stream_must_shut_everything_down_if_client_signals_erro } [Fact] - public void Outgoing_TCP_stream_must_shut_everything_down_if_client_signals_error_after_remote_has_closed_write() + public async Task Outgoing_TCP_stream_must_shut_everything_down_if_client_signals_error_after_remote_has_closed_write() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var testData = ByteString.FromBytes(new byte[] { 1, 2, 3, 4, 5 }); var server = new Server(this); @@ -349,9 +349,9 @@ public void Outgoing_TCP_stream_must_shut_everything_down_if_client_signals_erro } [Fact] - public void Outgoing_TCP_stream_must_shut_down_both_streams_when_connection_is_aborted_remotely() + public async Task Outgoing_TCP_stream_must_shut_down_both_streams_when_connection_is_aborted_remotely() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { // Client gets a PeerClosed event and does not know that the write side is also closed var server = new Server(this); @@ -415,9 +415,9 @@ public async Task Outgoing_TCP_stream_must_materialize_correctly_when_used_in_mu } [Fact] - public void Outgoing_TCP_stream_must_properly_full_close_if_requested() + public async Task Outgoing_TCP_stream_must_properly_full_close_if_requested() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var serverAddress = TestUtils.TemporaryServerAddress(); var writeButIgnoreRead = Flow.FromSinkAndSource(Sink.Ignore(), @@ -640,9 +640,9 @@ public void Tcp_listen_stream_must_bind_and_unbind_correctly() } [Fact(Skip = "FIXME: unexpected ErrorClosed")] - public void Tcp_listen_stream_must_not_shut_down_connections_after_the_connection_stream_cancelled() + public async Task Tcp_listen_stream_must_not_shut_down_connections_after_the_connection_stream_cancelled() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var thousandByteStrings = Enumerable.Range(0, 1000) .Select(_ => ByteString.FromBytes(new byte[] { 0 })) @@ -676,9 +676,9 @@ public void Tcp_listen_stream_must_not_shut_down_connections_after_the_connectio } [Fact(Skip="FIXME")] - public void Tcp_listen_stream_must_shut_down_properly_even_if_some_accepted_connection_Flows_have_not_been_subscribed_to () + public async Task Tcp_listen_stream_must_shut_down_properly_even_if_some_accepted_connection_Flows_have_not_been_subscribed_to () { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var serverAddress = TestUtils.TemporaryServerAddress(); var firstClientConnected = new TaskCompletionSource(); diff --git a/src/core/Akka.Streams.Tests/Implementation/Fusing/ActorGraphInterpreterSpec.cs b/src/core/Akka.Streams.Tests/Implementation/Fusing/ActorGraphInterpreterSpec.cs index 0aab8789834..4eded98cb0a 100644 --- a/src/core/Akka.Streams.Tests/Implementation/Fusing/ActorGraphInterpreterSpec.cs +++ b/src/core/Akka.Streams.Tests/Implementation/Fusing/ActorGraphInterpreterSpec.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Text.RegularExpressions; using System.Threading; +using System.Threading.Tasks; using Akka.Pattern; using Akka.Streams.Dsl; using Akka.Streams.Implementation; @@ -35,9 +36,9 @@ public ActorGraphInterpreterSpec(ITestOutputHelper output = null) : base(output) } [Fact] - public void ActorGraphInterpreter_should_be_able_to_interpret_a_simple_identity_graph_stage() + public async Task ActorGraphInterpreter_should_be_able_to_interpret_a_simple_identity_graph_stage() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var identity = GraphStages.Identity(); @@ -51,9 +52,9 @@ public void ActorGraphInterpreter_should_be_able_to_interpret_a_simple_identity_ } [Fact] - public void ActorGraphInterpreter_should_be_able_to_reuse_a_simple_identity_graph_stage() + public async Task ActorGraphInterpreter_should_be_able_to_reuse_a_simple_identity_graph_stage() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var identity = GraphStages.Identity(); @@ -69,9 +70,9 @@ public void ActorGraphInterpreter_should_be_able_to_reuse_a_simple_identity_grap } [Fact] - public void ActorGraphInterpreter_should_be_able_to_interpret_a_simple_bidi_stage() + public async Task ActorGraphInterpreter_should_be_able_to_interpret_a_simple_bidi_stage() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var identityBidi = new IdentityBidiGraphStage(); var identity = BidiFlow.FromGraph(identityBidi).Join(Flow.Identity().Select(x => x)); @@ -86,9 +87,9 @@ public void ActorGraphInterpreter_should_be_able_to_interpret_a_simple_bidi_stag } [Fact] - public void ActorGraphInterpreter_should_be_able_to_interpret_and_reuse_a_simple_bidi_stage() + public async Task ActorGraphInterpreter_should_be_able_to_interpret_and_reuse_a_simple_bidi_stage() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var identityBidi = new IdentityBidiGraphStage(); var identityBidiFlow = BidiFlow.FromGraph(identityBidi); @@ -104,9 +105,9 @@ public void ActorGraphInterpreter_should_be_able_to_interpret_and_reuse_a_simple } [Fact] - public void ActorGraphInterpreter_should_be_able_to_interpret_a_rotated_identity_bidi_stage() + public async Task ActorGraphInterpreter_should_be_able_to_interpret_a_rotated_identity_bidi_stage() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var rotatedBidi = new RotatedIdentityBidiGraphStage(); var takeAll = Flow.Identity() @@ -147,13 +148,13 @@ public void ActorGraphInterpreter_should_be_able_to_report_errors_if_an_error_ha } [Fact] - public void ActorGraphInterpreter_should_be_able_to_properly_handle_case_where_a_stage_fails_before_subscription_happens() + public async Task ActorGraphInterpreter_should_be_able_to_properly_handle_case_where_a_stage_fails_before_subscription_happens() { // Fuzzing needs to be off, so that the failure can propagate to the output boundary // before the ExposedPublisher message. var noFuzzMaterializer = ActorMaterializer.Create(Sys, ActorMaterializerSettings.Create(Sys).WithFuzzingMode(false)); - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var evilLatch = new CountdownEvent(1); @@ -203,9 +204,9 @@ public void ActorGraphInterpreter_should_be_able_to_properly_handle_case_where_a } [Fact] - public void ActorGraphInterpreter_should_be_to_handle_Publisher_spec_violations_without_leaking() + public async Task ActorGraphInterpreter_should_be_to_handle_Publisher_spec_violations_without_leaking() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstream = this.CreatePublisherProbe(); var downstream = this.CreateSubscriberProbe(); @@ -241,9 +242,9 @@ public void Cancel() } [Fact] - public void ActorGraphInterpreter_should_be_to_handle_Subscriber_spec_violations_without_leaking() + public async Task ActorGraphInterpreter_should_be_to_handle_Subscriber_spec_violations_without_leaking() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstream = this.CreatePublisherProbe(); var downstream = this.CreateSubscriberProbe(); @@ -263,9 +264,9 @@ public void ActorGraphInterpreter_should_be_to_handle_Subscriber_spec_violations } [Fact] - public void ActorGraphInterpreter_should_trigger_PostStop_in_all_stages_when_abruptly_terminated_and_no_upstream_boundaries() + public async Task ActorGraphInterpreter_should_trigger_PostStop_in_all_stages_when_abruptly_terminated_and_no_upstream_boundaries() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var materializer = ActorMaterializer.Create(Sys); var gotStop = new TestLatch(1); diff --git a/src/core/Akka.Streams.Tests/Implementation/Fusing/KeepGoingStageSpec.cs b/src/core/Akka.Streams.Tests/Implementation/Fusing/KeepGoingStageSpec.cs index c6ed79813b1..1ff0ca1673c 100644 --- a/src/core/Akka.Streams.Tests/Implementation/Fusing/KeepGoingStageSpec.cs +++ b/src/core/Akka.Streams.Tests/Implementation/Fusing/KeepGoingStageSpec.cs @@ -194,9 +194,9 @@ public KeepGoingStageSpec(ITestOutputHelper helper = null) : base(helper) } [Fact] - public void A_stage_with_keep_going_must_still_be_alive_after_all_ports_have_been_closed_until_explicity_closed() + public async Task A_stage_with_keep_going_must_still_be_alive_after_all_ports_have_been_closed_until_explicity_closed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = Source.Maybe().ToMaterialized(new PingableSink(true), Keep.Both).Run(Materializer); var maybePromise = t.Item1; @@ -229,9 +229,9 @@ public void A_stage_with_keep_going_must_still_be_alive_after_all_ports_have_bee } [Fact] - public void A_stage_with_keep_going_must_still_be_alive_after_all_ports_have_been_closed_until_explicitly_failed() + public async Task A_stage_with_keep_going_must_still_be_alive_after_all_ports_have_been_closed_until_explicitly_failed() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = Source.Maybe().ToMaterialized(new PingableSink(true), Keep.Both).Run(Materializer); var maybePromise = t.Item1; @@ -268,9 +268,9 @@ public void A_stage_with_keep_going_must_still_be_alive_after_all_ports_have_bee } [Fact] - public void A_stage_with_keep_going_must_still_be_alive_after_all_ports_have_been_closed_until_implicity_failed_via_exception() + public async Task A_stage_with_keep_going_must_still_be_alive_after_all_ports_have_been_closed_until_implicity_failed_via_exception() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = Source.Maybe().ToMaterialized(new PingableSink(true), Keep.Both).Run(Materializer); var maybePromise = t.Item1; @@ -309,9 +309,9 @@ public void A_stage_with_keep_going_must_still_be_alive_after_all_ports_have_bee } [Fact] - public void A_stage_with_keep_going_must_close_down_earls_if_keepAlive_is_not_requested() + public async Task A_stage_with_keep_going_must_close_down_earls_if_keepAlive_is_not_requested() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = Source.Maybe().ToMaterialized(new PingableSink(false), Keep.Both).Run(Materializer); var maybePromise = t.Item1; diff --git a/src/core/Akka.Streams.Tests/Implementation/GraphStageLogicSpec.cs b/src/core/Akka.Streams.Tests/Implementation/GraphStageLogicSpec.cs index 62689564ceb..f64d3007cb3 100644 --- a/src/core/Akka.Streams.Tests/Implementation/GraphStageLogicSpec.cs +++ b/src/core/Akka.Streams.Tests/Implementation/GraphStageLogicSpec.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.Pattern; @@ -272,9 +273,9 @@ public GraphStageLogicSpec(ITestOutputHelper output) : base(output, Config) } [Fact] - public void A_GraphStageLogic_must_read_N_and_emit_N_before_completing() + public async Task A_GraphStageLogic_must_read_N_and_emit_N_before_completing() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 10)) .Via(new ReadNEmitN(2)) @@ -286,9 +287,9 @@ public void A_GraphStageLogic_must_read_N_and_emit_N_before_completing() } [Fact] - public void A_GraphStageLogic_must_read_N_should_not_emit_if_upstream_completes_before_N_is_sent() + public async Task A_GraphStageLogic_must_read_N_should_not_emit_if_upstream_completes_before_N_is_sent() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 5)) .Via(new ReadNEmitN(6)) @@ -299,9 +300,9 @@ public void A_GraphStageLogic_must_read_N_should_not_emit_if_upstream_completes_ } [Fact] - public void A_GraphStageLogic_must_read_N_should_not_emit_if_upstream_fails_before_N_is_sent() + public async Task A_GraphStageLogic_must_read_N_should_not_emit_if_upstream_fails_before_N_is_sent() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var error = new ArgumentException("Don't argue like that!"); Source.From(Enumerable.Range(1, 5)) @@ -319,9 +320,9 @@ public void A_GraphStageLogic_must_read_N_should_not_emit_if_upstream_fails_befo } [Fact] - public void A_GraphStageLogic_must_read_N_should_provide_elements_read_if_OnComplete_happens_before_N_elements_have_been_seen() + public async Task A_GraphStageLogic_must_read_N_should_provide_elements_read_if_OnComplete_happens_before_N_elements_have_been_seen() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 5)) .Via(new ReadNEmitRestOnComplete(6)) @@ -333,9 +334,9 @@ public void A_GraphStageLogic_must_read_N_should_provide_elements_read_if_OnComp } [Fact] - public void A_GraphStageLogic_must_emit_all_things_before_completing() + public async Task A_GraphStageLogic_must_emit_all_things_before_completing() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.Empty() .Via(new Emit1234().Named("testStage")) @@ -350,9 +351,9 @@ public void A_GraphStageLogic_must_emit_all_things_before_completing() } [Fact] - public void A_GraphStageLogic_must_emit_all_things_before_completing_with_two_fused_stages() + public async Task A_GraphStageLogic_must_emit_all_things_before_completing_with_two_fused_stages() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var flow = Flow.Create().Via(new Emit1234()).Via(new Emit5678()); var g = Streams.Implementation.Fusing.Fusing.Aggressive(flow); @@ -374,9 +375,9 @@ public void A_GraphStageLogic_must_emit_all_things_before_completing_with_two_fu } [Fact] - public void A_GraphStageLogic_must_emit_all_things_before_completing_with_three_fused_stages() + public async Task A_GraphStageLogic_must_emit_all_things_before_completing_with_three_fused_stages() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var flow = Flow.Create().Via(new Emit1234()).Via(new PassThrough()).Via(new Emit5678()); var g = Streams.Implementation.Fusing.Fusing.Aggressive(flow); @@ -398,9 +399,9 @@ public void A_GraphStageLogic_must_emit_all_things_before_completing_with_three_ } [Fact] - public void A_GraphStageLogic_must_emit_properly_after_empty_iterable() + public async Task A_GraphStageLogic_must_emit_properly_after_empty_iterable() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.FromGraph(new EmitEmptyIterable()) .RunWith(Sink.Seq(), Materializer) @@ -424,9 +425,9 @@ public void A_GraphStageLogic_must_support_logging_in_custom_graphstage() } [Fact] - public void A_GraphStageLogic_must_invoke_livecycle_hooks_in_the_right_order() + public async Task A_GraphStageLogic_must_invoke_livecycle_hooks_in_the_right_order() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var g = new LifecycleStage(TestActor); diff --git a/src/core/Akka.Streams.Tests/Implementation/TimeoutsSpec.cs b/src/core/Akka.Streams.Tests/Implementation/TimeoutsSpec.cs index 18263bb1b54..293b30b4385 100644 --- a/src/core/Akka.Streams.Tests/Implementation/TimeoutsSpec.cs +++ b/src/core/Akka.Streams.Tests/Implementation/TimeoutsSpec.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; +using System.Threading.Tasks; using Akka.Streams.Dsl; using Akka.Streams.TestKit; using Akka.Streams.TestKit.Tests; @@ -29,9 +30,9 @@ public TimeoutsSpec(ITestOutputHelper helper = null) : base(helper) } [Fact] - public void InitialTimeout_must_pass_through_elements_unmodified() + public async Task InitialTimeout_must_pass_through_elements_unmodified() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = Source.From(Enumerable.Range(1, 100)) .InitialTimeout(TimeSpan.FromSeconds(2)).Grouped(200) @@ -43,9 +44,9 @@ public void InitialTimeout_must_pass_through_elements_unmodified() } [Fact] - public void InitialTimeout_must_pass_through_error_unmodified() + public async Task InitialTimeout_must_pass_through_error_unmodified() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.From(Enumerable.Range(1, 100)) .Concat(Source.Failed(new TestException("test"))) @@ -59,9 +60,9 @@ public void InitialTimeout_must_pass_through_error_unmodified() } [Fact] - public void InitialTimeout_must_fail_if_no_initial_element_passes_until_timeout() + public async Task InitialTimeout_must_fail_if_no_initial_element_passes_until_timeout() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var downstreamProbe = this.CreateSubscriberProbe(); Source.Maybe() @@ -78,9 +79,9 @@ public void InitialTimeout_must_fail_if_no_initial_element_passes_until_timeout( [Fact] - public void CompletionTimeout_must_pass_through_elements_unmodified() + public async Task CompletionTimeout_must_pass_through_elements_unmodified() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = Source.From(Enumerable.Range(1, 100)) .CompletionTimeout(TimeSpan.FromSeconds(2)).Grouped(200) @@ -92,9 +93,9 @@ public void CompletionTimeout_must_pass_through_elements_unmodified() } [Fact] - public void CompletionTimeout_must_pass_through_error_unmodified() + public async Task CompletionTimeout_must_pass_through_error_unmodified() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.From(Enumerable.Range(1, 100)) .Concat(Source.Failed(new TestException("test"))) @@ -107,9 +108,9 @@ public void CompletionTimeout_must_pass_through_error_unmodified() } [Fact] - public void CompletionTimeout_must_fail_if_not_completed_until_timeout() + public async Task CompletionTimeout_must_fail_if_not_completed_until_timeout() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstreamProbe = this.CreatePublisherProbe(); var downstreamProbe = this.CreateSubscriberProbe(); @@ -134,9 +135,9 @@ public void CompletionTimeout_must_fail_if_not_completed_until_timeout() [Fact] - public void IdleTimeout_must_pass_through_elements_unmodified() + public async Task IdleTimeout_must_pass_through_elements_unmodified() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var t = Source.From(Enumerable.Range(1, 100)) .IdleTimeout(TimeSpan.FromSeconds(2)).Grouped(200) @@ -148,9 +149,9 @@ public void IdleTimeout_must_pass_through_elements_unmodified() } [Fact] - public void IdleTimeout_must_pass_through_error_unmodified() + public async Task IdleTimeout_must_pass_through_error_unmodified() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var task = Source.From(Enumerable.Range(1, 100)) .Concat(Source.Failed(new TestException("test"))) @@ -163,9 +164,9 @@ public void IdleTimeout_must_pass_through_error_unmodified() } [Fact] - public void IdleTimeout_must_fail_if_time_between_elements_is_too_large() + public async Task IdleTimeout_must_fail_if_time_between_elements_is_too_large() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstreamProbe = this.CreatePublisherProbe(); var downstreamProbe = this.CreateSubscriberProbe(); @@ -190,9 +191,9 @@ public void IdleTimeout_must_fail_if_time_between_elements_is_too_large() [Fact] - public void BackpressureTimeout_must_pass_through_elements_unmodified() + public async Task BackpressureTimeout_must_pass_through_elements_unmodified() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { Source.From(Enumerable.Range(1, 100)) .BackpressureTimeout(TimeSpan.FromSeconds(1)) @@ -204,9 +205,9 @@ public void BackpressureTimeout_must_pass_through_elements_unmodified() } [Fact] - public void BackpressureTimeout_must_succeed_if_subscriber_demand_arrives() + public async Task BackpressureTimeout_must_succeed_if_subscriber_demand_arrives() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var subscriber = this.CreateSubscriberProbe(); @@ -226,9 +227,9 @@ public void BackpressureTimeout_must_succeed_if_subscriber_demand_arrives() } [Fact] - public void BackpressureTimeout_must_not_throw_if_publisher_is_less_frequent_than_timeout() + public async Task BackpressureTimeout_must_not_throw_if_publisher_is_less_frequent_than_timeout() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisher = this.CreatePublisherProbe(); var subscriber = this.CreateSubscriberProbe(); @@ -252,9 +253,9 @@ public void BackpressureTimeout_must_not_throw_if_publisher_is_less_frequent_tha } [Fact] - public void BackpressureTimeout_must_not_throw_if_publisher_wont_perform_emission_ever() + public async Task BackpressureTimeout_must_not_throw_if_publisher_wont_perform_emission_ever() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisher = this.CreatePublisherProbe(); var subscriber = this.CreateSubscriberProbe(); @@ -271,9 +272,9 @@ public void BackpressureTimeout_must_not_throw_if_publisher_wont_perform_emissio } [Fact] - public void BackpressureTimeout_must_throw_if_subscriber_wont_generate_demand_on_time() + public async Task BackpressureTimeout_must_throw_if_subscriber_wont_generate_demand_on_time() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisher = this.CreatePublisherProbe(); var subscriber = this.CreateSubscriberProbe(); @@ -293,9 +294,9 @@ public void BackpressureTimeout_must_throw_if_subscriber_wont_generate_demand_on } [Fact] - public void BackpressureTimeout_must_throw_if_subscriber_never_generate_demand() + public async Task BackpressureTimeout_must_throw_if_subscriber_never_generate_demand() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisher = this.CreatePublisherProbe(); var subscriber = this.CreateSubscriberProbe(); @@ -313,9 +314,9 @@ public void BackpressureTimeout_must_throw_if_subscriber_never_generate_demand() } [Fact] - public void BackpressureTimeout_must_not_throw_if_publisher_completes_without_fulfilling_subscribers_demand() + public async Task BackpressureTimeout_must_not_throw_if_publisher_completes_without_fulfilling_subscribers_demand() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var publisher = this.CreatePublisherProbe(); var subscriber = this.CreateSubscriberProbe(); @@ -337,9 +338,9 @@ public void BackpressureTimeout_must_not_throw_if_publisher_completes_without_fu [Fact] - public void IdleTimeoutBidi_must_not_signal_error_in_simple_loopback_case_and_pass_through_elements_unmodified() + public async Task IdleTimeoutBidi_must_not_signal_error_in_simple_loopback_case_and_pass_through_elements_unmodified() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var timeoutIdentity = BidiFlow.BidirectionalIdleTimeout(TimeSpan.FromSeconds(2)).Join(Flow.Create()); @@ -353,9 +354,9 @@ public void IdleTimeoutBidi_must_not_signal_error_in_simple_loopback_case_and_pa } [Fact] - public void IdleTimeoutBidi_must_not_signal_error_if_traffic_is_one_way() + public async Task IdleTimeoutBidi_must_not_signal_error_if_traffic_is_one_way() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upstreamWriter = this.CreatePublisherProbe(); var downstreamWriter = this.CreatePublisherProbe(); @@ -388,9 +389,9 @@ public void IdleTimeoutBidi_must_not_signal_error_if_traffic_is_one_way() } [Fact] - public void IdleTimeoutBidi_must_be_able_to_signal_timeout_once_no_traffic_on_either_sides() + public async Task IdleTimeoutBidi_must_be_able_to_signal_timeout_once_no_traffic_on_either_sides() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upWrite = this.CreatePublisherProbe(); var upRead = this.CreateSubscriberProbe(); @@ -443,9 +444,9 @@ public void IdleTimeoutBidi_must_be_able_to_signal_timeout_once_no_traffic_on_ei } [Fact] - public void IdleTimeoutBidi_must_signal_error_to_all_outputs() + public async Task IdleTimeoutBidi_must_signal_error_to_all_outputs() { - this.AssertAllStagesStopped(() => + await this.AssertAllStagesStoppedAsync(() => { var upWrite = this.CreatePublisherProbe(); var upRead = this.CreateSubscriberProbe(); diff --git a/src/core/Akka.TestKit.Tests/TestEventListenerTests/AllTestForEventFilterBase.cs b/src/core/Akka.TestKit.Tests/TestEventListenerTests/AllTestForEventFilterBase.cs index 16dd3b3d56c..5a0320c8b0f 100644 --- a/src/core/Akka.TestKit.Tests/TestEventListenerTests/AllTestForEventFilterBase.cs +++ b/src/core/Akka.TestKit.Tests/TestEventListenerTests/AllTestForEventFilterBase.cs @@ -175,9 +175,9 @@ public void Messages_can_be_muted_from_now_on_with_using() [Fact] - public void Make_sure_async_works() + public async Task Make_sure_async_works() { - _testingEventFilter.ForLogLevel(LogLevel).Expect(1, TimeSpan.FromMilliseconds(100), () => + await _testingEventFilter.ForLogLevel(LogLevel).ExpectAsync(1, TimeSpan.FromMilliseconds(100), () => { Task.Delay(TimeSpan.FromMilliseconds(10)).ContinueWith(t => { LogMessage("whatever"); }); }); diff --git a/src/core/Akka.TestKit.Tests/TestFSMRefTests!/TestFSMRefSpec.cs b/src/core/Akka.TestKit.Tests/TestFSMRefTests!/TestFSMRefSpec.cs index 55aa8b474e7..5cbe00fad6f 100644 --- a/src/core/Akka.TestKit.Tests/TestFSMRefTests!/TestFSMRefSpec.cs +++ b/src/core/Akka.TestKit.Tests/TestFSMRefTests!/TestFSMRefSpec.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System; +using System.Threading.Tasks; using Akka.Actor; using Akka.TestKit; using Xunit; @@ -15,7 +16,7 @@ namespace Akka.Testkit.Tests.TestFSMRefTests public class TestFSMRefSpec : AkkaSpec { [Fact] - public void A_TestFSMRef_must_allow_access_to_internal_state() + public async Task A_TestFSMRef_must_allow_access_to_internal_state() { var fsm = ActorOfAsTestFSMRef("test-fsm-ref-1"); @@ -35,9 +36,9 @@ public void A_TestFSMRef_must_allow_access_to_internal_state() fsm.StateData.ShouldBe("buh"); fsm.SetStateTimeout(TimeSpan.FromMilliseconds(100)); - Within(TimeSpan.FromMilliseconds(80), TimeSpan.FromMilliseconds(500), () => - AwaitCondition(() => fsm.StateName == 2 && fsm.StateData == "timeout") - ); + await WithinAsync(TimeSpan.FromMilliseconds(80), TimeSpan.FromMilliseconds(500), async () => + await AwaitConditionAsync(() => fsm.StateName == 2 && fsm.StateData == "timeout") + ); } [Fact] diff --git a/src/core/Akka.TestKit.Tests/TestKitBaseTests/AwaitAssertTests.cs b/src/core/Akka.TestKit.Tests/TestKitBaseTests/AwaitAssertTests.cs index 855ca0ec6a6..11d7aef32e3 100644 --- a/src/core/Akka.TestKit.Tests/TestKitBaseTests/AwaitAssertTests.cs +++ b/src/core/Akka.TestKit.Tests/TestKitBaseTests/AwaitAssertTests.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System; +using System.Threading.Tasks; using Xunit; using Xunit.Sdk; @@ -18,18 +19,20 @@ public AwaitAssertTests() : base("akka.test.timefactor=2") } [Fact] - public void AwaitAssert_must_not_throw_any_exception_when_assertion_is_valid() + public async Task AwaitAssert_must_not_throw_any_exception_when_assertion_is_valid() { - AwaitAssert(() => Assert.Equal("foo", "foo")); + await AwaitAssertAsync(() => Assert.Equal("foo", "foo")); } [Fact] - public void AwaitAssert_must_throw_exception_when_assertion_is_invalid() + public async Task AwaitAssert_must_throw_exception_when_assertion_is_invalid() { - Within(TimeSpan.FromMilliseconds(300), TimeSpan.FromSeconds(1), () => + await WithinAsync(TimeSpan.FromMilliseconds(300), TimeSpan.FromSeconds(1), async () => { - Assert.Throws(() => - AwaitAssert(() => Assert.Equal("foo", "bar"), TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(300))); + await Assert.ThrowsAsync(async () => + { + await AwaitAssertAsync(() => Assert.Equal("foo", "bar"), TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(300)); + }); }); } } diff --git a/src/core/Akka.TestKit.Tests/TestKitBaseTests/DilatedTests.cs b/src/core/Akka.TestKit.Tests/TestKitBaseTests/DilatedTests.cs index cb8a9cd4b19..011b091e089 100644 --- a/src/core/Akka.TestKit.Tests/TestKitBaseTests/DilatedTests.cs +++ b/src/core/Akka.TestKit.Tests/TestKitBaseTests/DilatedTests.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System; +using System.Threading.Tasks; using Akka.TestKit; using Xunit; @@ -30,10 +31,10 @@ public void Dilates_correctly_using_timeFactor() } [Fact] - public void AwaitCondition_should_dilate_timeout() + public async Task AwaitCondition_should_dilate_timeout() { var before = Now; - Intercept(() => AwaitCondition(() => false, TimeSpan.FromMilliseconds(Timeout))); + await InterceptAsync(async () => await AwaitConditionAsync(() => false, TimeSpan.FromMilliseconds(Timeout))); var after = Now; var diff = (after - before).TotalMilliseconds; Assert.True(Math.Abs(diff - ExpectedTimeout) <= DiffDelta); diff --git a/src/core/Akka.TestKit/EventFilter/IEventFilterApplier.cs b/src/core/Akka.TestKit/EventFilter/IEventFilterApplier.cs index 5d84e5b52eb..f454fe4eb9b 100644 --- a/src/core/Akka.TestKit/EventFilter/IEventFilterApplier.cs +++ b/src/core/Akka.TestKit/EventFilter/IEventFilterApplier.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System; +using System.Threading.Tasks; namespace Akka.TestKit { @@ -24,6 +25,26 @@ public interface IEventFilterApplier /// /// The action. void ExpectOne(Action action); + + /// + /// Executes and + /// expects one event to be logged during the execution. + /// This method fails and throws an exception if more than one event is logged, + /// or if a timeout occurs. The timeout is taken from the config value + /// "akka.test.filter-leeway", see . + /// + /// The action. + Task ExpectOneAsync(Action action); + + /// + /// Executes and + /// expects one event to be logged during the execution. + /// This method fails and throws an exception if more than one event is logged, + /// or if a timeout occurs. The timeout is taken from the config value + /// "akka.test.filter-leeway", see . + /// + /// The action. + Task ExpectOneAsync(Func actionAsync); /// /// Executes and @@ -34,7 +55,17 @@ public interface IEventFilterApplier /// The time to wait for a log event after executing /// The action. void ExpectOne(TimeSpan timeout, Action action); - + + /// + /// Executes and + /// expects one event to be logged during the execution. + /// This method fails and throws an exception if more than one event is logged, + /// or if a timeout occurs. + /// + /// The time to wait for a log event after executing + /// The action. + Task ExpectOneAsync(TimeSpan timeout, Action action); + /// /// Executes and expects the specified number /// of events to be logged during the execution. @@ -45,6 +76,28 @@ public interface IEventFilterApplier /// The expected number of events /// The action. void Expect(int expectedCount, Action action); + + /// + /// Executes and expects the specified number + /// of events to be logged during the execution. + /// This method fails and throws an exception if more events than expected are logged, + /// or if a timeout occurs. The timeout is taken from the config value + /// "akka.test.filter-leeway", see . + /// + /// The expected number of events + /// The action. + Task ExpectAsync(int expectedCount, Action action); + + /// + /// Executes task and expects the specified number + /// of events to be logged during the execution. + /// This method fails and throws an exception if more events than expected are logged, + /// or if a timeout occurs. The timeout is taken from the config value + /// "akka.test.filter-leeway", see . + /// + /// The expected number of events + /// The async action. + Task ExpectAsync(int expectedCount, Func actionAsync); /// /// Executes and expects the specified number @@ -57,6 +110,18 @@ public interface IEventFilterApplier /// The expected number of events /// The action. void Expect(int expectedCount, TimeSpan timeout, Action action); + + /// + /// Executes and expects the specified number + /// of events to be logged during the execution. + /// This method fails and throws an exception if more events than expected are logged, + /// or if a timeout occurs. The timeout is taken from the config value + /// "akka.test.filter-leeway", see . + /// + /// The time to wait for log events after executing + /// The expected number of events + /// The action. + Task ExpectAsync(int expectedCount, TimeSpan timeout, Action action); /// /// Executes and @@ -69,6 +134,18 @@ public interface IEventFilterApplier /// The function. /// The returned value from . T ExpectOne(Func func); + + /// + /// Executes and + /// expects one event to be logged during the execution. + /// This function fails and throws an exception if more than one event is logged, + /// or if a timeout occurs. The timeout is taken from the config value + /// "akka.test.filter-leeway", see . + /// + /// The return value of the function + /// The function. + /// The returned value from . + Task ExpectOneAsync(Func func); /// /// Executes and @@ -81,6 +158,18 @@ public interface IEventFilterApplier /// The function. /// The returned value from . T ExpectOne(TimeSpan timeout, Func func); + + /// + /// Executes and + /// expects one event to be logged during the execution. + /// This function fails and throws an exception if more than one event is logged, + /// or if a timeout occurs. + /// + /// The return value of the function + /// The time to wait for a log event after executing + /// The function. + /// The returned value from . + Task ExpectOneAsync(TimeSpan timeout, Func func); /// /// Executes and expects the specified number @@ -94,6 +183,19 @@ public interface IEventFilterApplier /// The function. /// The returned value from . T Expect(int expectedCount, Func func); + + /// + /// Executes and expects the specified number + /// of events to be logged during the execution. + /// This function fails and throws an exception if more events than expected are logged, + /// or if a timeout occurs. The timeout is taken from the config value + /// "akka.test.filter-leeway", see . + /// + /// The return value of the function + /// The expected number of events + /// The function. + /// The returned value from . + Task ExpectAsync(int expectedCount, Func func); /// /// Executes and expects the specified number @@ -108,6 +210,20 @@ public interface IEventFilterApplier /// The function. /// The returned value from . T Expect(int expectedCount, TimeSpan timeout, Func func); + + /// + /// Executes and expects the specified number + /// of events to be logged during the execution. + /// This function fails and throws an exception if more events than expected are logged, + /// or if a timeout occurs. The timeout is taken from the config value + /// "akka.test.filter-leeway", see . + /// + /// The return value of the function + /// The time to wait for log events after executing + /// The expected number of events + /// The function. + /// The returned value from . + Task ExpectAsync(int expectedCount, TimeSpan timeout, Func func); /// /// Executes and prevent events from being logged during the execution. @@ -116,6 +232,14 @@ public interface IEventFilterApplier /// The function. /// The returned value from . T Mute(Func func); + + /// + /// Executes and prevent events from being logged during the execution. + /// + /// The return value of the function + /// The function. + /// The returned value from . + Task MuteAsync(Func func); /// /// Executes and prevent events from being logged during the execution. @@ -123,6 +247,13 @@ public interface IEventFilterApplier /// The function. /// The returned value from . void Mute(Action action); + + /// + /// Executes and prevent events from being logged during the execution. + /// + /// The function. + /// The returned value from . + Task MuteAsync(Action action); /// /// Prevents events from being logged from now on. To allow events to be logged again, call diff --git a/src/core/Akka.TestKit/EventFilter/Internal/EventFilterApplier.cs b/src/core/Akka.TestKit/EventFilter/Internal/EventFilterApplier.cs index d11df487346..0901675ed54 100644 --- a/src/core/Akka.TestKit/EventFilter/Internal/EventFilterApplier.cs +++ b/src/core/Akka.TestKit/EventFilter/Internal/EventFilterApplier.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Threading; +using System.Threading.Tasks; using Akka.Actor; using Akka.Event; using Akka.TestKit.TestEvent; @@ -45,6 +46,20 @@ public void ExpectOne(Action action) InternalExpect(action, _actorSystem, 1); } + public Task ExpectOneAsync(Func actionAsync) + { + return InternalExpectAsync(actionAsync, _actorSystem, 1); + } + + /// + /// Async version of + /// + /// + public async Task ExpectOneAsync(Action action) + { + await InternalExpectAsync(action, _actorSystem, 1); + } + /// /// TBD /// @@ -54,6 +69,15 @@ public void ExpectOne(TimeSpan timeout, Action action) { InternalExpect(action, _actorSystem, 1, timeout); } + + /// + /// Async version of + /// + /// + public async Task ExpectOneAsync(TimeSpan timeout, Action action) + { + await InternalExpectAsync(action, _actorSystem, 1, timeout); + } /// /// TBD @@ -65,6 +89,22 @@ public void Expect(int expectedCount, Action action) InternalExpect(action, _actorSystem, expectedCount, null); } + /// + /// Async version of Expect + /// + public Task ExpectAsync(int expectedCount, Func actionAsync) + { + return InternalExpectAsync(actionAsync, _actorSystem, expectedCount, null); + } + + /// + /// Async version of + /// + public async Task ExpectAsync(int expectedCount, Action action) + { + await InternalExpectAsync(action, _actorSystem, expectedCount, null); + } + /// /// TBD /// @@ -75,6 +115,14 @@ public void Expect(int expectedCount, TimeSpan timeout, Action action) { InternalExpect(action, _actorSystem, expectedCount, timeout); } + + /// + /// Async version of + /// + public async Task ExpectAsync(int expectedCount, TimeSpan timeout, Action action) + { + await InternalExpectAsync(action, _actorSystem, expectedCount, timeout); + } /// /// TBD @@ -86,6 +134,14 @@ public T ExpectOne(Func func) { return Intercept(func, _actorSystem, null, 1); } + + /// + /// Async version of ExpectOne + /// + public async Task ExpectOneAsync(Func func) + { + return await InterceptAsync(func, _actorSystem, null, 1); + } /// /// TBD @@ -98,6 +154,14 @@ public T ExpectOne(TimeSpan timeout, Func func) { return Intercept(func, _actorSystem, timeout, 1); } + + /// + /// Async version of ExpectOne + /// + public async Task ExpectOneAsync(TimeSpan timeout, Func func) + { + return await InterceptAsync(func, _actorSystem, timeout, 1); + } /// /// TBD @@ -111,6 +175,14 @@ public T Expect(int expectedCount, Func func) return Intercept(func, _actorSystem, null, expectedCount); } + /// + /// Async version of Expect + /// + public async Task ExpectAsync(int expectedCount, Func func) + { + return await InterceptAsync(func, _actorSystem, null, expectedCount); + } + /// /// TBD /// @@ -123,6 +195,14 @@ public T Expect(int expectedCount, TimeSpan timeout, Func func) { return Intercept(func, _actorSystem, timeout, expectedCount); } + + /// + /// Async version of Expect + /// + public async Task ExpectAsync(int expectedCount, TimeSpan timeout, Func func) + { + return await InterceptAsync(func, _actorSystem, timeout, expectedCount); + } /// /// TBD @@ -134,6 +214,14 @@ public T Mute(Func func) { return Intercept(func, _actorSystem, null, null); } + + /// + /// Async version of Mute + /// + public async Task MuteAsync(Func func) + { + return await InterceptAsync(func, _actorSystem, null, null); + } /// /// TBD @@ -143,6 +231,14 @@ public void Mute(Action action) { Intercept(() => { action(); return null; }, _actorSystem, null, null); } + + /// + /// Async version of Mute + /// + public async Task MuteAsync(Action action) + { + await InterceptAsync(() => { action(); return null; }, _actorSystem, null, null); + } /// /// TBD @@ -227,6 +323,69 @@ protected T Intercept(Func func, ActorSystem system, TimeSpan? timeout, in } } + /// + /// Async version of + /// + protected Task InterceptAsync(Func func, ActorSystem system, TimeSpan? timeout, int? expectedOccurrences, MatchedEventHandler matchedEventHandler = null) + { + return InterceptAsync(() => Task.FromResult(func()), system, timeout, expectedOccurrences, matchedEventHandler); + } + + /// + /// Async version of + /// + protected async Task InterceptAsync(Func> func, ActorSystem system, TimeSpan? timeout, int? expectedOccurrences, MatchedEventHandler matchedEventHandler = null) + { + var leeway = system.HasExtension() + ? TestKitExtension.For(system).TestEventFilterLeeway + : _testkit.TestKitSettings.TestEventFilterLeeway; + + var timeoutValue = timeout.HasValue ? _testkit.Dilated(timeout.Value) : leeway; + matchedEventHandler = matchedEventHandler ?? new MatchedEventHandler(); + system.EventStream.Publish(new Mute(_filters)); + try + { + foreach(var filter in _filters) + { + filter.EventMatched += matchedEventHandler.HandleEvent; + } + var result = await func(); + + if(!await AwaitDoneAsync(timeoutValue, expectedOccurrences, matchedEventHandler)) + { + var actualNumberOfEvents = matchedEventHandler.ReceivedCount; + string msg; + if(expectedOccurrences.HasValue) + { + var expectedNumberOfEvents = expectedOccurrences.Value; + if(actualNumberOfEvents < expectedNumberOfEvents) + msg = string.Format("Timeout ({0}) while waiting for messages. Only received {1}/{2} messages that matched filter [{3}]", timeoutValue, actualNumberOfEvents, expectedNumberOfEvents, string.Join(",", _filters)); + else + { + var tooMany = actualNumberOfEvents - expectedNumberOfEvents; + msg = string.Format("Received {0} {1} too many. Expected {2} {3} but received {4} that matched filter [{5}]", tooMany, GetMessageString(tooMany), expectedNumberOfEvents, GetMessageString(expectedNumberOfEvents), actualNumberOfEvents, string.Join(",", _filters)); + } + } + else + msg = string.Format("Timeout ({0}) while waiting for messages that matched filter [{1}]", timeoutValue, _filters); + + var assertionsProvider = system.HasExtension() + ? TestKitAssertionsExtension.For(system) + : TestKitAssertionsExtension.For(_testkit.Sys); + assertionsProvider.Assertions.Fail(msg); + } + return result; + } + finally + { + foreach(var filter in _filters) + { + filter.EventMatched -= matchedEventHandler.HandleEvent; + } + system.EventStream.Publish(new Unmute(_filters)); + } + } + /// /// TBD /// @@ -239,7 +398,21 @@ protected bool AwaitDone(TimeSpan timeout, int? expectedOccurrences, MatchedEven if(expectedOccurrences.HasValue) { var expected = expectedOccurrences.GetValueOrDefault(); - _testkit.AwaitConditionNoThrow(() => matchedEventHandler.ReceivedCount >= expected, timeout); + _testkit.AwaitConditionNoThrowAsync(() => matchedEventHandler.ReceivedCount >= expected, timeout).Wait(); + return matchedEventHandler.ReceivedCount == expected; + } + return true; + } + + /// + /// Async version of + /// + protected async Task AwaitDoneAsync(TimeSpan timeout, int? expectedOccurrences, MatchedEventHandler matchedEventHandler) + { + if(expectedOccurrences.HasValue) + { + var expected = expectedOccurrences.GetValueOrDefault(); + await _testkit.AwaitConditionNoThrowAsync(() => matchedEventHandler.ReceivedCount >= expected, timeout); return matchedEventHandler.ReceivedCount == expected; } return true; @@ -259,6 +432,22 @@ private void InternalExpect(Action action, ActorSystem actorSystem, int expected { Intercept(() => { action(); return null; }, actorSystem, timeout, expectedCount); } + + /// + /// Async version of + /// + private async Task InternalExpectAsync(Func actionAsync, ActorSystem actorSystem, int expectedCount, TimeSpan? timeout = null) + { + await InterceptAsync(() => { actionAsync(); return Task.FromResult(null); }, actorSystem, timeout, expectedCount); + } + + /// + /// Async version of + /// + private async Task InternalExpectAsync(Action action, ActorSystem actorSystem, int expectedCount, TimeSpan? timeout = null) + { + await InterceptAsync(() => { action(); return Task.FromResult(null); }, actorSystem, timeout, expectedCount); + } /// /// TBD diff --git a/src/core/Akka.TestKit/TestKitBase.cs b/src/core/Akka.TestKit/TestKitBase.cs index b1130f60a22..c3a98783d36 100644 --- a/src/core/Akka.TestKit/TestKitBase.cs +++ b/src/core/Akka.TestKit/TestKitBase.cs @@ -7,6 +7,7 @@ using System; using System.Threading; +using System.Threading.Tasks; using Akka.Actor; using Akka.Actor.Internal; using Akka.Configuration; @@ -134,6 +135,7 @@ protected void InitializeTest(ActorSystem system, Config config, string actorSys var testActor = CreateTestActor(system, testActorName); //Wait for the testactor to start + // Calling sync version here, since .Wait() causes deadlock AwaitCondition(() => { var repRef = testActor as IRepointableRef; @@ -155,7 +157,7 @@ protected void InitializeTest(ActorSystem system, Config config, string actorSys _testState.TestActor = testActor; } - + private TimeSpan SingleExpectDefaultTimeout { get { return _testState.TestKitSettings.SingleExpectDefault; } } /// diff --git a/src/core/Akka.TestKit/TestKitBase_AwaitAssert.cs b/src/core/Akka.TestKit/TestKitBase_AwaitAssert.cs index 6b202fa9d5d..55ad7693d8d 100644 --- a/src/core/Akka.TestKit/TestKitBase_AwaitAssert.cs +++ b/src/core/Akka.TestKit/TestKitBase_AwaitAssert.cs @@ -7,6 +7,7 @@ using System; using System.Threading; +using System.Threading.Tasks; using Akka.TestKit.Internal; namespace Akka.TestKit @@ -54,5 +55,44 @@ public void AwaitAssert(Action assertion, TimeSpan? duration=null, TimeSpan? int t = (stop - Now).Min(intervalValue); } } + + /// + /// Await until the given assertion does not throw an exception or the timeout + /// expires, whichever comes first. If the timeout expires the last exception + /// is thrown. + /// The action is called, and if it throws an exception the thread sleeps + /// the specified interval before retrying. + /// If no timeout is given, take it from the innermost enclosing `within` + /// block. + /// Note that the timeout is scaled using , + /// which uses the configuration entry "akka.test.timefactor". + /// + /// The action. + /// The timeout. + /// The interval to wait between executing the assertion. + public async Task AwaitAssertAsync(Action assertion, TimeSpan? duration=null, TimeSpan? interval=null) + { + var intervalValue = interval.GetValueOrDefault(TimeSpan.FromMilliseconds(800)); + if(intervalValue == Timeout.InfiniteTimeSpan) intervalValue = TimeSpan.MaxValue; + intervalValue.EnsureIsPositiveFinite("interval"); + var max = RemainingOrDilated(duration); + var stop = Now + max; + var t = max.Min(intervalValue); + while(true) + { + try + { + assertion(); + return; + } + catch(Exception) + { + if(Now + t >= stop) + throw; + } + await Task.Delay(t); + t = (stop - Now).Min(intervalValue); + } + } } } diff --git a/src/core/Akka.TestKit/TestKitBase_AwaitConditions.cs b/src/core/Akka.TestKit/TestKitBase_AwaitConditions.cs index 7f1c128d51a..46dd40c2429 100644 --- a/src/core/Akka.TestKit/TestKitBase_AwaitConditions.cs +++ b/src/core/Akka.TestKit/TestKitBase_AwaitConditions.cs @@ -7,6 +7,7 @@ using System; using System.Threading; +using System.Threading.Tasks; using Akka.Event; using Akka.TestKit.Internal; @@ -37,6 +38,27 @@ public void AwaitCondition(Func conditionIsFulfilled) var logger = _testState.TestKitSettings.LogTestKitCalls ? _testState.Log : null; InternalAwaitCondition(conditionIsFulfilled, maxDur, interval, (format, args) => _assertions.Fail(format, args), logger); } + + /// + /// Await until the given condition evaluates to true or until a timeout + /// The timeout is taken from the innermost enclosing `within` + /// block (if inside a `within` block) or the value specified in config value "akka.test.single-expect-default". + /// The value is dilated, i.e. scaled by the factor + /// specified in config value "akka.test.timefactor".. + /// A call to is done immediately, then the threads sleep + /// for about a tenth of the timeout value, before it checks the condition again. This is repeated until + /// timeout or the condition evaluates to true. To specify another interval, use the overload + /// + /// + /// + /// The condition that must be fulfilled within the duration. + public async Task AwaitConditionAsync(Func conditionIsFulfilled) + { + var maxDur = RemainingOrDefault; + var interval = new TimeSpan(maxDur.Ticks / 10); + var logger = _testState.TestKitSettings.LogTestKitCalls ? _testState.Log : null; + await InternalAwaitConditionAsync(conditionIsFulfilled, maxDur, interval, (format, args) => _assertions.Fail(format, args), logger); + } /// /// Await until the given condition evaluates to true or the timeout @@ -63,6 +85,32 @@ public void AwaitCondition(Func conditionIsFulfilled, TimeSpan? max) var logger = _testState.TestKitSettings.LogTestKitCalls ? _testState.Log : null; InternalAwaitCondition(conditionIsFulfilled, maxDur, interval, (format, args) => _assertions.Fail(format, args), logger); } + + /// + /// Await until the given condition evaluates to true or the timeout + /// expires, whichever comes first. + /// If no timeout is given, take it from the innermost enclosing `within` + /// block (if inside a `within` block) or the value specified in config value "akka.test.single-expect-default". + /// The value is dilated, i.e. scaled by the factor + /// specified in config value "akka.test.timefactor".. + /// A call to is done immediately, then the threads sleep + /// for about a tenth of the timeout value, before it checks the condition again. This is repeated until + /// timeout or the condition evaluates to true. To specify another interval, use the overload + /// + /// + /// + /// The condition that must be fulfilled within the duration. + /// The maximum duration. If undefined, uses the remaining time + /// (if inside a `within` block) or the value specified in config value "akka.test.single-expect-default". + /// The value is dilated, i.e. scaled by the factor + /// specified in config value "akka.test.timefactor". + public async Task AwaitConditionAsync(Func conditionIsFulfilled, TimeSpan? max) + { + var maxDur = RemainingOrDilated(max); + var interval = new TimeSpan(maxDur.Ticks / 10); + var logger = _testState.TestKitSettings.LogTestKitCalls ? _testState.Log : null; + await InternalAwaitConditionAsync(conditionIsFulfilled, maxDur, interval, (format, args) => _assertions.Fail(format, args), logger); + } /// /// Await until the given condition evaluates to true or the timeout @@ -90,6 +138,33 @@ public void AwaitCondition(Func conditionIsFulfilled, TimeSpan? max, strin var logger = _testState.TestKitSettings.LogTestKitCalls ? _testState.Log : null; InternalAwaitCondition(conditionIsFulfilled, maxDur, interval, (format, args) => AssertionsFail(format, args, message), logger); } + + /// + /// Await until the given condition evaluates to true or the timeout + /// expires, whichever comes first. + /// If no timeout is given, take it from the innermost enclosing `within` + /// block (if inside a `within` block) or the value specified in config value "akka.test.single-expect-default". + /// The value is dilated, i.e. scaled by the factor + /// specified in config value "akka.test.timefactor".. + /// A call to is done immediately, then the threads sleep + /// for about a tenth of the timeout value, before it checks the condition again. This is repeated until + /// timeout or the condition evaluates to true. To specify another interval, use the overload + /// + /// + /// + /// The condition that must be fulfilled within the duration. + /// The maximum duration. If undefined, uses the remaining time + /// (if inside a `within` block) or the value specified in config value "akka.test.single-expect-default". + /// The value is dilated, i.e. scaled by the factor + /// specified in config value "akka.test.timefactor". + /// The message used if the timeout expires. + public async Task AwaitConditionAsync(Func conditionIsFulfilled, TimeSpan? max, string message) + { + var maxDur = RemainingOrDilated(max); + var interval = new TimeSpan(maxDur.Ticks / 10); + var logger = _testState.TestKitSettings.LogTestKitCalls ? _testState.Log : null; + await InternalAwaitConditionAsync(conditionIsFulfilled, maxDur, interval, (format, args) => AssertionsFail(format, args, message), logger); + } /// /// Await until the given condition evaluates to true or the timeout @@ -124,13 +199,46 @@ public void AwaitCondition(Func conditionIsFulfilled, TimeSpan? max, TimeS var logger = _testState.TestKitSettings.LogTestKitCalls ? _testState.Log : null; InternalAwaitCondition(conditionIsFulfilled, maxDur, interval, (format, args) => AssertionsFail(format, args, message), logger); } + + /// + /// Await until the given condition evaluates to true or the timeout + /// expires, whichever comes first. + /// If no timeout is given, take it from the innermost enclosing `within` + /// block. + /// Note that the timeout is dilated, i.e. scaled by the factor + /// specified in config value "akka.test.timefactor". + /// The parameter specifies the time between calls to + /// Between calls the thread sleeps. If is undefined the thread only sleeps + /// one time, using the as duration, and then rechecks the condition and ultimately + /// succeeds or fails. + /// To make sure that tests run as fast as possible, make sure you do not leave this value as undefined, + /// instead set it to a relatively small value. + /// + /// The condition that must be fulfilled within the duration. + /// The maximum duration. If undefined, uses the remaining time + /// (if inside a `within` block) or the value specified in config value "akka.test.single-expect-default". + /// The value is dilated, i.e. scaled by the factor + /// specified in config value "akka.test.timefactor". + /// The time between calls to to check + /// if the condition is fulfilled. Between calls the thread sleeps. If undefined, negative or + /// the thread only sleeps one time, using the , + /// and then rechecks the condition and ultimately succeeds or fails. + /// To make sure that tests run as fast as possible, make sure you do not set this value as undefined, + /// instead set it to a relatively small value. + /// + /// The message used if the timeout expires. + public async Task AwaitConditionAsync(Func conditionIsFulfilled, TimeSpan? max, TimeSpan? interval, string message = null) + { + var maxDur = RemainingOrDilated(max); + var logger = _testState.TestKitSettings.LogTestKitCalls ? _testState.Log : null; + await InternalAwaitConditionAsync(conditionIsFulfilled, maxDur, interval, (format, args) => AssertionsFail(format, args, message), logger); + } private void AssertionsFail(string format, object[] args, string message = null) { _assertions.Fail(format + (message ?? ""), args); } - /// /// Await until the given condition evaluates to true or the timeout /// expires, whichever comes first. Returns true if the condition was fulfilled. @@ -148,7 +256,24 @@ public bool AwaitConditionNoThrow(Func conditionIsFulfilled, TimeSpan max, var intervalDur = interval.GetValueOrDefault(TimeSpan.FromMilliseconds(100)); return InternalAwaitCondition(conditionIsFulfilled, max, intervalDur, (f, a) => { }); } - + + /// + /// Await until the given condition evaluates to true or the timeout + /// expires, whichever comes first. Returns true if the condition was fulfilled. + /// The parameter specifies the time between calls to + /// Between calls the thread sleeps. If is not specified or null 100 ms is used. + /// + /// The condition that must be fulfilled within the duration. + /// The maximum duration. + /// Optional. The time between calls to to check + /// if the condition is fulfilled. Between calls the thread sleeps. If undefined, 100 ms is used + /// + /// TBD + public Task AwaitConditionNoThrowAsync(Func conditionIsFulfilled, TimeSpan max, TimeSpan? interval = null) + { + var intervalDur = interval.GetValueOrDefault(TimeSpan.FromMilliseconds(100)); + return InternalAwaitConditionAsync(conditionIsFulfilled, max, intervalDur, (f, a) => { }); + } /// /// Await until the given condition evaluates to true or the timeout @@ -181,6 +306,19 @@ protected static bool InternalAwaitCondition(Func conditionIsFulfilled, Ti { return InternalAwaitCondition(conditionIsFulfilled, max, interval, fail, null); } + + /// + /// Async version of + /// + /// + /// + /// + /// + /// + protected static Task InternalAwaitConditionAsync(Func conditionIsFulfilled, TimeSpan max, TimeSpan? interval, Action fail) + { + return InternalAwaitConditionAsync(conditionIsFulfilled, max, interval, fail, null); + } /// /// Await until the given condition evaluates to true or the timeout @@ -234,6 +372,34 @@ protected static bool InternalAwaitCondition(Func conditionIsFulfilled, Ti ConditionalLog(logger, "Condition fulfilled after {0}", Now-start); return true; } + + /// + /// Async version of + /// + protected static async Task InternalAwaitConditionAsync(Func conditionIsFulfilled, TimeSpan max, TimeSpan? interval, Action fail, ILoggingAdapter logger) + { + max.EnsureIsPositiveFinite("max"); + var start = Now; + var stop = start + max; + ConditionalLog(logger, "Awaiting condition for {0}.{1}", max, interval.HasValue ? " Will sleep " + interval.Value + " between checks" : ""); + + while (!conditionIsFulfilled()) + { + var now = Now; + + if (now > stop) + { + const string message = "Timeout {0} expired while waiting for condition."; + ConditionalLog(logger, message, max); + fail(message, new object[] { max }); + return false; + } + var sleepDuration = (stop - now).Min(interval); + await Task.Delay(sleepDuration); + } + ConditionalLog(logger, "Condition fulfilled after {0}", Now-start); + return true; + } private static void ConditionalLog(ILoggingAdapter logger, string format, params object[] args) { diff --git a/src/core/Akka.TestKit/TestKitBase_Within.cs b/src/core/Akka.TestKit/TestKitBase_Within.cs index 0556d525dd0..6ed21924456 100644 --- a/src/core/Akka.TestKit/TestKitBase_Within.cs +++ b/src/core/Akka.TestKit/TestKitBase_Within.cs @@ -7,6 +7,7 @@ using System; using System.Threading; +using System.Threading.Tasks; using Akka.TestKit.Internal; namespace Akka.TestKit @@ -30,6 +31,14 @@ public void Within(TimeSpan max, Action action, TimeSpan? epsilonValue = null) { Within(TimeSpan.Zero, max, action, epsilonValue: epsilonValue); } + + /// + /// Async version of Within + /// + public Task WithinAsync(TimeSpan max, Func actionAsync, TimeSpan? epsilonValue = null) + { + return WithinAsync(TimeSpan.Zero, max, actionAsync, epsilonValue: epsilonValue); + } /// /// Execute code block while bounding its execution time between and . @@ -47,7 +56,14 @@ public void Within(TimeSpan min, TimeSpan max, Action action, string hint = null { Within(min, max, () => { action(); return null; }, hint, epsilonValue); } - + + /// + /// Async version of + /// + public Task WithinAsync(TimeSpan min, TimeSpan max, Func actionAsync, string hint = null, TimeSpan? epsilonValue = null) + { + return WithinAsync(min, max, async () => { await actionAsync(); return null; }, hint, epsilonValue); + } /// /// Execute code block while bounding its execution time between 0 seconds and . @@ -65,6 +81,23 @@ public T Within(TimeSpan max, Func function, TimeSpan? epsilonValue = null { return Within(TimeSpan.Zero, max, function, epsilonValue: epsilonValue); } + + /// + /// Execute code block while bounding its execution time between 0 seconds and . + /// `within` blocks may be nested. All methods in this class which take maximum wait times + /// are available in a version which implicitly uses the remaining time governed by + /// the innermost enclosing `within` block. + /// Note that the max duration is scaled using which uses the config value "akka.test.timefactor" + /// + /// TBD + /// TBD + /// TBD + /// TBD + /// TBD + public Task WithinAsync(TimeSpan max, Func> function, TimeSpan? epsilonValue = null) + { + return WithinAsync(TimeSpan.Zero, max, function, epsilonValue: epsilonValue); + } /// /// Execute code block while bounding its execution time between and . @@ -128,5 +161,66 @@ public T Within(TimeSpan min, TimeSpan max, Func function, string hint = n return ret; } + /// + /// Execute code block while bounding its execution time between and . + /// `within` blocks may be nested. All methods in this class which take maximum wait times + /// are available in a version which implicitly uses the remaining time governed by + /// the innermost enclosing `within` block. + /// Note that the max duration is scaled using which uses the config value "akka.test.timefactor" + /// + /// TBD + /// TBD + /// TBD + /// TBD + /// TBD + /// TBD + /// TBD + public async Task WithinAsync(TimeSpan min, TimeSpan max, Func> function, string hint = null, TimeSpan? epsilonValue = null) + { + min.EnsureIsPositiveFinite("min"); + min.EnsureIsPositiveFinite("max"); + max = Dilated(max); + var start = Now; + var rem = _testState.End.HasValue ? _testState.End.Value - start : Timeout.InfiniteTimeSpan; + _assertions.AssertTrue(rem.IsInfiniteTimeout() || rem >= min, "Required min time {0} not possible, only {1} left. {2}", min, rem, hint ?? ""); + + _testState.LastWasNoMsg = false; + + var maxDiff = max.Min(rem); + var prevEnd = _testState.End; + _testState.End = start + maxDiff; + + T ret; + try + { + ret = await function(); + } + finally + { + _testState.End = prevEnd; + } + + var elapsed = Now - start; + var wasTooFast = elapsed < min; + if(wasTooFast) + { + const string failMessage = "Failed: Block took {0}, should have at least been {1}. {2}"; + ConditionalLog(failMessage, elapsed, min, hint ?? ""); + _assertions.Fail(failMessage, elapsed, min, hint ?? ""); + } + if (!_testState.LastWasNoMsg) + { + epsilonValue = epsilonValue ?? TimeSpan.Zero; + var tookTooLong = elapsed > maxDiff + epsilonValue; + if(tookTooLong) + { + const string failMessage = "Failed: Block took {0}, exceeding {1}. {2}"; + ConditionalLog(failMessage, elapsed, maxDiff, hint ?? ""); + _assertions.Fail(failMessage, elapsed, maxDiff, hint ?? ""); + } + } + + return ret; + } } } diff --git a/src/core/Akka.Tests.Shared.Internals/AkkaSpec.cs b/src/core/Akka.Tests.Shared.Internals/AkkaSpec.cs index 3df9e710c32..f19ff092269 100644 --- a/src/core/Akka.Tests.Shared.Internals/AkkaSpec.cs +++ b/src/core/Akka.Tests.Shared.Internals/AkkaSpec.cs @@ -11,6 +11,7 @@ using System.Reflection; using System.Text.RegularExpressions; using System.Threading; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.TestKit.Internal.StringMatcher; @@ -150,6 +151,19 @@ protected void Intercept(Action actionThatThrows) } throw new ThrowsException(typeof(Exception)); } + + protected async Task InterceptAsync(Func asyncActionThatThrows) + { + try + { + await asyncActionThatThrows(); + } + catch(Exception) + { + return; + } + throw new ThrowsException(typeof(Exception)); + } [Obsolete("Use Intercept instead. This member will be removed.")] protected void intercept(Action actionThatThrows) where T : Exception diff --git a/src/core/Akka.Tests/Actor/ActorLookupSpec.cs b/src/core/Akka.Tests/Actor/ActorLookupSpec.cs index e8319b235ef..a787686ad84 100644 --- a/src/core/Akka.Tests/Actor/ActorLookupSpec.cs +++ b/src/core/Akka.Tests/Actor/ActorLookupSpec.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System.Collections.Generic; +using System.Threading.Tasks; using Akka.Actor; using Akka.Actor.Internal; using Akka.TestKit; @@ -159,7 +160,7 @@ public void ActorSystem_must_take_actor_incarnation_into_account_when_comparing_ } [Fact] - public void ActorSystem_must_find_temporary_actors() + public async Task ActorSystem_must_find_temporary_actors() { var f = c1.Ask(new GetSender(TestActor)); var a = ExpectMsg(); @@ -170,8 +171,8 @@ public void ActorSystem_must_find_temporary_actors() f.IsCompleted.Should().Be(false); a.IsTerminated.Should().Be(false); a.Tell(42); - AwaitAssert(() => f.IsCompleted.Should().Be(true)); - AwaitAssert(() => f.Result.Should().Be(42)); + await AwaitAssertAsync(() => f.IsCompleted.Should().Be(true)); + await AwaitAssertAsync(() => f.Result.Should().Be(42)); } /* diff --git a/src/core/Akka.Tests/Actor/ActorRefSpec.cs b/src/core/Akka.Tests/Actor/ActorRefSpec.cs index 8a03fab8b86..4f69466c0dc 100644 --- a/src/core/Akka.Tests/Actor/ActorRefSpec.cs +++ b/src/core/Akka.Tests/Actor/ActorRefSpec.cs @@ -7,6 +7,7 @@ using System; using System.Threading; +using System.Threading.Tasks; using Akka.Actor; using Akka.Actor.Internal; using Akka.Serialization; @@ -107,9 +108,7 @@ public void An_ActorRef_should_throw_an_exception_on_deserialize_if_no_system_in } [Fact] - public void - An_ActoRef_should_return_EmptyLocalActorRef_on_deserialize_if_not_present_in_actor_hierarchy_and_remoting_is_not_enabled - () + public async Task An_ActoRef_should_return_EmptyLocalActorRef_on_deserialize_if_not_present_in_actor_hierarchy_and_remoting_is_not_enabled() { var aref = ActorOf("non-existing"); var aserializer = Sys.Serialization.FindSerializerForType(typeof (IActorRef)); @@ -123,7 +122,7 @@ public void var bserializer = Sys.Serialization.FindSerializerForType(typeof (IActorRef)); - AwaitCondition(() => + await AwaitConditionAsync(() => { var bref = (IActorRef) bserializer.FromBinary(binary, typeof (IActorRef)); try diff --git a/src/core/Akka.Tests/Actor/AskSpec.cs b/src/core/Akka.Tests/Actor/AskSpec.cs index d3a177c157f..c6775d842ec 100644 --- a/src/core/Akka.Tests/Actor/AskSpec.cs +++ b/src/core/Akka.Tests/Actor/AskSpec.cs @@ -192,14 +192,14 @@ public void AskDoesNotDeadlockWhenWaitForResultInGuiApplication() }); } - private void Are_Temp_Actors_Removed(IActorRef actor) + private async Task Are_Temp_Actors_Removed(IActorRef actor) { var actorCell = actor as ActorRefWithCell; Assert.True(actorCell != null, "Test method only valid with ActorRefWithCell actors."); // ReSharper disable once PossibleNullReferenceException var container = actorCell.Provider.TempContainer as VirtualPathContainer; - AwaitAssert(() => + await AwaitAssertAsync(() => { var childCounter = 0; // ReSharper disable once PossibleNullReferenceException diff --git a/src/core/Akka.Tests/Actor/Dispatch/ActorModelSpec.cs b/src/core/Akka.Tests/Actor/Dispatch/ActorModelSpec.cs index 9cd1176e689..f64c490b3e1 100644 --- a/src/core/Akka.Tests/Actor/Dispatch/ActorModelSpec.cs +++ b/src/core/Akka.Tests/Actor/Dispatch/ActorModelSpec.cs @@ -418,9 +418,9 @@ protected IActorRef NewTestActor(string dispatcher) return Sys.ActorOf(Props.Create().WithDispatcher(dispatcher)); } - void AwaitStarted(IActorRef actorRef) + async Task AwaitStartedAsync(IActorRef actorRef) { - AwaitCondition(() => + await AwaitConditionAsync(() => { if (actorRef is RepointableActorRef) return actorRef.AsInstanceOf().IsStarted; @@ -453,13 +453,13 @@ public void A_dispatcher_must_dynamically_handle_its_own_lifecycle() } [Fact] - public void A_dispatcher_must_process_messages_one_at_a_time() + public async Task A_dispatcher_must_process_messages_one_at_a_time() { var dispatcher = InterceptedDispatcher(); var start = new CountdownEvent(1); var oneAtTime = new CountdownEvent(1); var a = NewTestActor(dispatcher.Id); - AwaitStarted(a); + await AwaitStartedAsync(a); a.Tell(new CountDown(start)); AssertCountdown(start, (int)Dilated(TimeSpan.FromSeconds(3.0)).TotalMilliseconds, "Should process first message within 3 seconds"); @@ -499,11 +499,11 @@ public void A_dispatcher_must_handle_queuing_from_multiple_threads() } [Fact] - public void A_dispatcher_should_not_process_messages_for_a_suspended_actor() + public async Task A_dispatcher_should_not_process_messages_for_a_suspended_actor() { var dispatcher = InterceptedDispatcher(); var a = NewTestActor(dispatcher.Id).AsInstanceOf(); - AwaitStarted(a); + await AwaitStartedAsync(a); var done = new CountdownEvent(1); a.Suspend(); a.Tell(new CountDown(done)); @@ -613,7 +613,7 @@ public void A_dispatcher_must_continue_to_process_messages_when_exception_is_thr } [Fact] - public void A_dispatcher_must_not_double_deregister() + public async Task A_dispatcher_must_not_double_deregister() { var dispatcher = InterceptedDispatcher(); for (var i = 1; i <= 1000; i++) @@ -622,8 +622,8 @@ public void A_dispatcher_must_not_double_deregister() } var a = NewTestActor(dispatcher.Id); a.Tell(DoubleStop.Instance); - AwaitCondition(() => StatsFor(a, dispatcher).Registers.Current == 1); - AwaitCondition(() => StatsFor(a, dispatcher).Unregisters.Current == 1); + await AwaitConditionAsync(() => StatsFor(a, dispatcher).Registers.Current == 1); + await AwaitConditionAsync(() => StatsFor(a, dispatcher).Unregisters.Current == 1); } } diff --git a/src/core/Akka.Tests/Actor/Dispatch/Bug2640Spec.cs b/src/core/Akka.Tests/Actor/Dispatch/Bug2640Spec.cs index 56dc8ed86f6..e34f0a0a56e 100644 --- a/src/core/Akka.Tests/Actor/Dispatch/Bug2640Spec.cs +++ b/src/core/Akka.Tests/Actor/Dispatch/Bug2640Spec.cs @@ -78,12 +78,12 @@ public async Task ForkJoinExecutorShouldShutdownUponActorSystemTermination() .ToDictionary(x => x.Key, grouping => grouping.First()); await Sys.Terminate(); - AwaitAssert(() => + await AwaitAssertAsync(() => threads.Values.All(x => x.IsAlive == false).Should().BeTrue("All threads should be stopped")); } [Fact(DisplayName = "ForkJoinExecutor should terminate all threads upon all attached actors shutting down")] - public void ForkJoinExecutorShouldShutdownUponAllActorsTerminating() + public async Task ForkJoinExecutorShouldShutdownUponAllActorsTerminating() { var actor = Sys.ActorOf(Props.Create(() => new ThreadReporterActor()) .WithDispatcher("myapp.my-fork-join-dispatcher").WithRouter(new RoundRobinPool(4))); @@ -99,12 +99,12 @@ public void ForkJoinExecutorShouldShutdownUponAllActorsTerminating() Sys.Stop(actor); ExpectTerminated(actor); - AwaitAssert(() => + await AwaitAssertAsync(() => threads.Values.All(x => x.IsAlive == false).Should().BeTrue("All threads should be stopped")); } [Fact(DisplayName = "PinnedDispatcher should terminate its thread upon actor shutdown")] - public void PinnedDispatcherShouldShutdownUponActorTermination() + public async Task PinnedDispatcherShouldShutdownUponActorTermination() { var actor = Sys.ActorOf(Props.Create(() => new ThreadReporterActor()) .WithDispatcher("myapp.my-pinned-dispatcher")); @@ -116,7 +116,7 @@ public void PinnedDispatcherShouldShutdownUponActorTermination() Sys.Stop(actor); ExpectTerminated(actor); - AwaitCondition(() => !thread.IsAlive); // wait for thread to terminate + await AwaitConditionAsync(() => !thread.IsAlive); // wait for thread to terminate } } } diff --git a/src/core/Akka.Tests/Actor/FSMTimingSpec.cs b/src/core/Akka.Tests/Actor/FSMTimingSpec.cs index a1e883a26ce..523e0a812e5 100644 --- a/src/core/Akka.Tests/Actor/FSMTimingSpec.cs +++ b/src/core/Akka.Tests/Actor/FSMTimingSpec.cs @@ -274,7 +274,7 @@ public Unhandled(object msg) public static void StaticAwaitCond(Func evaluator, TimeSpan max, TimeSpan? interval) { - InternalAwaitCondition(evaluator, max, interval,(format,args)=> XAssert.Fail(string.Format(format,args))); + InternalAwaitConditionAsync(evaluator, max, interval,(format,args)=> XAssert.Fail(string.Format(format,args))).Wait(); } public class StateMachine : FSM, ILoggingFSM diff --git a/src/core/Akka.Tests/Actor/HotSwapSpec.cs b/src/core/Akka.Tests/Actor/HotSwapSpec.cs index cc75b508658..7746a644f2b 100644 --- a/src/core/Akka.Tests/Actor/HotSwapSpec.cs +++ b/src/core/Akka.Tests/Actor/HotSwapSpec.cs @@ -6,6 +6,7 @@ //----------------------------------------------------------------------- using System; +using System.Threading.Tasks; using Akka.Actor; using Akka.TestKit; using Xunit; @@ -81,7 +82,8 @@ public void Must_be_able_to_revert_hotswap_its_behaviour_with_unbecome() { } [Fact] - public void Must_be_able_to_revert_to_initial_state_on_restart() { + public async Task Must_be_able_to_revert_to_initial_state_on_restart() + { var a = Sys.ActorOf(); a.Tell("state"); @@ -93,7 +95,7 @@ public void Must_be_able_to_revert_to_initial_state_on_restart() { a.Tell("state"); ExpectMsg("1"); - EventFilter.Exception("Crash (expected)!").Expect(1, () => { + await EventFilter.Exception("Crash (expected)!").ExpectAsync(1, () => { a.Tell("crash"); }); diff --git a/src/core/Akka.Tests/Actor/LocalActorRefProviderSpec.cs b/src/core/Akka.Tests/Actor/LocalActorRefProviderSpec.cs index 4bf3c74f344..d18d647ae06 100644 --- a/src/core/Akka.Tests/Actor/LocalActorRefProviderSpec.cs +++ b/src/core/Akka.Tests/Actor/LocalActorRefProviderSpec.cs @@ -19,7 +19,7 @@ namespace Akka.Tests.Actor public class LocalActorRefProviderSpec : AkkaSpec { [Fact] - public void A_LocalActorRefs_ActorCell_must_not_retain_its_original_Props_when_Terminated() + public async Task A_LocalActorRefs_ActorCell_must_not_retain_its_original_Props_when_Terminated() { var parent = Sys.ActorOf(Props.Create(() => new ParentActor())); parent.Tell("GetChild", TestActor); @@ -29,7 +29,7 @@ public void A_LocalActorRefs_ActorCell_must_not_retain_its_original_Props_when_T Watch(parent); Sys.Stop(parent); ExpectTerminated(parent); - AwaitAssert(() => + await AwaitAssertAsync(() => { var childPropsAfterTermination = ((LocalActorRef)child).Underlying.Props; Assert.NotEqual(childPropsBeforeTermination, childPropsAfterTermination); diff --git a/src/core/Akka.Tests/Actor/Scheduler/TaskBasedScheduler_ActionScheduler_Schedule_Tests.cs b/src/core/Akka.Tests/Actor/Scheduler/TaskBasedScheduler_ActionScheduler_Schedule_Tests.cs index ff32c164010..653fc9c1de9 100644 --- a/src/core/Akka.Tests/Actor/Scheduler/TaskBasedScheduler_ActionScheduler_Schedule_Tests.cs +++ b/src/core/Akka.Tests/Actor/Scheduler/TaskBasedScheduler_ActionScheduler_Schedule_Tests.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Threading; +using System.Threading.Tasks; using Akka.Actor; using Akka.TestKit; using Akka.Util.Internal; @@ -273,7 +274,7 @@ public void When_ScheduleRepeatedly_with_0_delay_Then_action_is_executed_immedia } [Fact] - public void When_ScheduleRepeatedly_action_crashes_Then_no_more_calls_will_be_scheduled() + public async Task When_ScheduleRepeatedly_action_crashes_Then_no_more_calls_will_be_scheduled() { IActionScheduler testScheduler = new HashedWheelTimerScheduler(Sys.Settings.Config, Log); @@ -285,7 +286,7 @@ public void When_ScheduleRepeatedly_action_crashes_Then_no_more_calls_will_be_sc Interlocked.Increment(ref timesCalled); throw new Exception("Crash"); }); - AwaitCondition(() => timesCalled >= 1); + await AwaitConditionAsync(() => timesCalled >= 1); Thread.Sleep(200); //Allow any scheduled actions to be fired. //We expect only one of the scheduled actions to actually fire diff --git a/src/core/Akka.Tests/Actor/SupervisorHierarchySpec.cs b/src/core/Akka.Tests/Actor/SupervisorHierarchySpec.cs index 7754bdf40e5..7cdc8d09af6 100644 --- a/src/core/Akka.Tests/Actor/SupervisorHierarchySpec.cs +++ b/src/core/Akka.Tests/Actor/SupervisorHierarchySpec.cs @@ -7,6 +7,7 @@ using System; using System.Threading; +using System.Threading.Tasks; using Akka.Actor; using Akka.Actor.Dsl; using Akka.TestKit; @@ -212,7 +213,7 @@ public void A_supervisor_hierarchy_must_resume_children_after_Resume() } [Fact] - public void A_supervisor_hierarchy_must_suspend_children_while_failing() + public async Task A_supervisor_hierarchy_must_suspend_children_while_failing() { var latch = CreateTestLatch(); var slowResumer = ActorOf(c => @@ -240,11 +241,11 @@ public void A_supervisor_hierarchy_must_suspend_children_while_failing() //Check everything is in place by sending ping to worker and expect it to respond with pong worker.Tell("ping"); ExpectMsg("pong"); - EventFilter.Warning("expected").ExpectOne(() => //expected exception is thrown by the boss when it crashes + await EventFilter.Warning("expected").ExpectOneAsync(async () => //expected exception is thrown by the boss when it crashes { //Let boss crash, this means any child under boss should be suspended, so we wait for worker to become suspended. boss.Tell("fail"); - AwaitCondition(() => ((LocalActorRef)worker).Cell.Mailbox.IsSuspended()); + await AwaitConditionAsync(() => ((LocalActorRef)worker).Cell.Mailbox.IsSuspended()); //At this time slowresumer is currently handling the failure, in supervisestrategy, waiting for latch to be opened //We verify that no message is handled by worker, by sending it a ping @@ -261,17 +262,17 @@ public void A_supervisor_hierarchy_must_suspend_children_while_failing() } [Fact] - public void A_supervisor_hierarchy_must_handle_failure_in_creation_when_supervision_strategy_returns_Resume_and_Restart() + public async Task A_supervisor_hierarchy_must_handle_failure_in_creation_when_supervision_strategy_returns_Resume_and_Restart() { var createAttempt = new AtomicCounter(0); var preStartCalled = new AtomicCounter(0); var postRestartCalled = new AtomicCounter(0); - EventFilter.Exception() + await EventFilter.Exception() .And.Exception("OH NO!") .And.Error(start: "changing Recreate into Create") .And.Error(start: "changing Resume into Create") - .Mute(() => + .MuteAsync(() => { //Create: // failresumer diff --git a/src/core/Akka.Tests/Dispatch/MailboxesSpec.cs b/src/core/Akka.Tests/Dispatch/MailboxesSpec.cs index 3f8742549ba..8419233cbac 100644 --- a/src/core/Akka.Tests/Dispatch/MailboxesSpec.cs +++ b/src/core/Akka.Tests/Dispatch/MailboxesSpec.cs @@ -178,7 +178,7 @@ public Property UnboundedPriorityQueue_should_sort_items_in_expected_order(int[] { pq.Enqueue(ActorRefs.Nobody, new Envelope(i, ActorRefs.NoSender)); }); - AwaitCondition(() => loop.IsCompleted); + await AwaitConditionAsync(() => loop.IsCompleted); Envelope e; @@ -195,7 +195,7 @@ public Property UnboundedPriorityQueue_should_sort_items_in_expected_order(int[] #endif [Fact] - public void Can_use_unbounded_priority_mailbox() + public async Task Can_use_unbounded_priority_mailbox() { var actor = (IInternalActorRef)Sys.ActorOf(EchoActor.Props(this).WithMailbox("string-prio-mailbox"), "echo"); @@ -203,7 +203,7 @@ public void Can_use_unbounded_priority_mailbox() actor.SendSystemMessage(new Suspend()); // wait until we can confirm that the mailbox is suspended before we begin sending messages - AwaitCondition(() => (((ActorRefWithCell)actor).Underlying is ActorCell) && ((ActorRefWithCell)actor).Underlying.AsInstanceOf().Mailbox.IsSuspended()); + await AwaitConditionAsync(() => (((ActorRefWithCell)actor).Underlying is ActorCell) && ((ActorRefWithCell)actor).Underlying.AsInstanceOf().Mailbox.IsSuspended()); actor.Tell(true); for (var i = 0; i < 30; i++) @@ -233,7 +233,7 @@ public void Can_use_unbounded_priority_mailbox() } [Fact] - public void Can_use_unbounded_stable_priority_mailbox() + public async Task Can_use_unbounded_stable_priority_mailbox() { var actor = (IInternalActorRef)Sys.ActorOf(EchoActor.Props(this).WithMailbox("stable-prio-mailbox"), "echo"); @@ -241,7 +241,7 @@ public void Can_use_unbounded_stable_priority_mailbox() actor.SendSystemMessage(new Suspend()); // wait until we can confirm that the mailbox is suspended before we begin sending messages - AwaitCondition(() => (((ActorRefWithCell)actor).Underlying is ActorCell) && ((ActorRefWithCell)actor).Underlying.AsInstanceOf().Mailbox.IsSuspended()); + await AwaitConditionAsync(() => (((ActorRefWithCell)actor).Underlying is ActorCell) && ((ActorRefWithCell)actor).Underlying.AsInstanceOf().Mailbox.IsSuspended()); actor.Tell(true); for (var i = 0; i < 30; i++) @@ -271,14 +271,14 @@ public void Can_use_unbounded_stable_priority_mailbox() } [Fact] - public void Priority_mailbox_keeps_ordering_with_many_priority_values() + public async Task Priority_mailbox_keeps_ordering_with_many_priority_values() { var actor = (IInternalActorRef)Sys.ActorOf(EchoActor.Props(this).WithMailbox("int-prio-mailbox"), "echo"); //pause mailbox until all messages have been told actor.SendSystemMessage(new Suspend()); - AwaitCondition(()=> (((ActorRefWithCell)actor).Underlying is ActorCell) && ((ActorRefWithCell)actor).Underlying.AsInstanceOf().Mailbox.IsSuspended()); + await AwaitConditionAsync(()=> (((ActorRefWithCell)actor).Underlying is ActorCell) && ((ActorRefWithCell)actor).Underlying.AsInstanceOf().Mailbox.IsSuspended()); // creates 50 messages with values spanning from Int32.MinValue to Int32.MaxValue var values = new int[50]; var increment = (int)(UInt32.MaxValue / values.Length); @@ -309,14 +309,14 @@ public void Priority_mailbox_keeps_ordering_with_many_priority_values() } [Fact] - public void Unbounded_Priority_Mailbox_Supports_Unbounded_Stashing() + public async Task Unbounded_Priority_Mailbox_Supports_Unbounded_Stashing() { var actor = (IInternalActorRef)Sys.ActorOf(StashingActor.Props(this).WithMailbox("int-prio-mailbox"), "echo"); //pause mailbox until all messages have been told actor.SendSystemMessage(new Suspend()); - AwaitCondition(() => (((ActorRefWithCell)actor).Underlying is ActorCell) && ((ActorRefWithCell)actor).Underlying.AsInstanceOf().Mailbox.IsSuspended()); + await AwaitConditionAsync(() => (((ActorRefWithCell)actor).Underlying is ActorCell) && ((ActorRefWithCell)actor).Underlying.AsInstanceOf().Mailbox.IsSuspended()); var values = new int[10]; var increment = (int)(UInt32.MaxValue / values.Length); @@ -352,14 +352,14 @@ public void Unbounded_Priority_Mailbox_Supports_Unbounded_Stashing() } [Fact] - public void Unbounded_Stable_Priority_Mailbox_Supports_Unbounded_Stashing() + public async Task Unbounded_Stable_Priority_Mailbox_Supports_Unbounded_Stashing() { var actor = (IInternalActorRef)Sys.ActorOf(StashingActor.Props(this).WithMailbox("stable-prio-mailbox"), "echo"); //pause mailbox until all messages have been told actor.SendSystemMessage(new Suspend()); - AwaitCondition(() => (((ActorRefWithCell)actor).Underlying is ActorCell) && ((ActorRefWithCell)actor).Underlying.AsInstanceOf().Mailbox.IsSuspended()); + await AwaitConditionAsync(() => (((ActorRefWithCell)actor).Underlying is ActorCell) && ((ActorRefWithCell)actor).Underlying.AsInstanceOf().Mailbox.IsSuspended()); var values = new int[10]; var increment = (int)(UInt32.MaxValue / values.Length); diff --git a/src/core/Akka.Tests/IO/TcpIntegrationSpec.cs b/src/core/Akka.Tests/IO/TcpIntegrationSpec.cs index 13c9e7e5d52..472f40ae6de 100644 --- a/src/core/Akka.Tests/IO/TcpIntegrationSpec.cs +++ b/src/core/Akka.Tests/IO/TcpIntegrationSpec.cs @@ -471,9 +471,9 @@ public void The_TCP_transport_implementation_dont_report_Connected_when_endpoint } [Fact] - public void The_TCP_transport_implementation_handle_tcp_connection_actor_death_properly() + public async Task The_TCP_transport_implementation_handle_tcp_connection_actor_death_properly() { - new TestSetup(this, shouldBindServer:false).Run(x => + await new TestSetup(this, shouldBindServer:false).RunAsync(async x => { var serverSocket = new Socket(SocketType.Stream, ProtocolType.Tcp); serverSocket.Bind(x.Endpoint); @@ -488,7 +488,7 @@ public void The_TCP_transport_implementation_handle_tcp_connection_actor_death_p var connectionActor = connectCommander.LastSender; connectCommander.Send(connectionActor, PoisonPill.Instance); - AwaitConditionNoThrow(() => + await AwaitConditionNoThrowAsync(() => { try { @@ -591,6 +591,12 @@ public void Run(Action action) if (_shouldBindServer) BindServer(); action(this); } + + public Task RunAsync(Func actionAsync) + { + if (_shouldBindServer) BindServer(); + return actionAsync(this); + } } } diff --git a/src/core/Akka.Tests/Pattern/BackoffOnRestartSupervisorSpec.cs b/src/core/Akka.Tests/Pattern/BackoffOnRestartSupervisorSpec.cs index 646443fc2cc..86a8d8e9c6e 100644 --- a/src/core/Akka.Tests/Pattern/BackoffOnRestartSupervisorSpec.cs +++ b/src/core/Akka.Tests/Pattern/BackoffOnRestartSupervisorSpec.cs @@ -12,6 +12,7 @@ using Xunit; using FluentAssertions; using System.Threading; +using System.Threading.Tasks; namespace Akka.Tests.Pattern { @@ -219,7 +220,7 @@ public void BackoffOnRestartSupervisor_must_forward_messages_from_the_child_to_t } [Fact] - public void BackoffOnRestartSupervisor_must_accept_commands_while_child_is_terminating() + public async Task BackoffOnRestartSupervisor_must_accept_commands_while_child_is_terminating() { var postStopLatch = CreateTestLatch(1); var options = Backoff.OnFailure(SlowlyFailingActor.Props(postStopLatch), "someChildName", 1.Ticks(), 1.Ticks(), 0.0, -1) @@ -250,7 +251,7 @@ public void BackoffOnRestartSupervisor_must_accept_commands_while_child_is_termi postStopLatch.CountDown(); // New child is ready - AwaitAssert(() => + await AwaitAssertAsync(() => { supervisor.Tell(BackoffSupervisor.GetCurrentChild.Instance); // new instance diff --git a/src/core/Akka.Tests/Pattern/BackoffSupervisorSpec.cs b/src/core/Akka.Tests/Pattern/BackoffSupervisorSpec.cs index 92ed9be76b2..9f5592457a2 100644 --- a/src/core/Akka.Tests/Pattern/BackoffSupervisorSpec.cs +++ b/src/core/Akka.Tests/Pattern/BackoffSupervisorSpec.cs @@ -9,6 +9,7 @@ using System.Collections; using System.Collections.Generic; using System.Threading; +using System.Threading.Tasks; using Akka.Actor; using Akka.Pattern; using Akka.TestKit; @@ -90,7 +91,7 @@ public static Props Props(IActorRef probe) #endregion [Fact(Skip = "Racy on Azure DevOps")] - public void BackoffSupervisor_must_start_child_again_when_it_stops_when_using_Backoff_OnStop() + public async Task BackoffSupervisor_must_start_child_again_when_it_stops_when_using_Backoff_OnStop() { var supervisor = Create(OnStopOptions()); supervisor.Tell(BackoffSupervisor.GetCurrentChild.Instance); @@ -98,7 +99,7 @@ public void BackoffSupervisor_must_start_child_again_when_it_stops_when_using_Ba Watch(c1); c1.Tell(PoisonPill.Instance); ExpectTerminated(c1); - AwaitAssert(() => + await AwaitAssertAsync(() => { supervisor.Tell(BackoffSupervisor.GetCurrentChild.Instance); // new instance @@ -120,16 +121,16 @@ public void BackoffSupervisor_must_forward_messages_to_the_child() } [Fact] - public void BackoffSupervisor_must_support_custom_supervision_strategy() + public async Task BackoffSupervisor_must_support_custom_supervision_strategy() { - Action assertCustomStrategy = supervisor => + Func assertCustomStrategy = async supervisor => { supervisor.Tell(BackoffSupervisor.GetCurrentChild.Instance); var c1 = ExpectMsg().Ref; Watch(c1); c1.Tell("boom"); ExpectTerminated(c1); - AwaitAssert(() => + await AwaitAssertAsync(() => { supervisor.Tell(BackoffSupervisor.GetCurrentChild.Instance); // new instance @@ -138,7 +139,7 @@ public void BackoffSupervisor_must_support_custom_supervision_strategy() }; // TODO: use FilterException - EventFilter.Exception().Expect(2, () => + await EventFilter.Exception().ExpectAsync(2, async () => { var stoppingStrategy = new OneForOneStrategy(ex => { @@ -160,16 +161,16 @@ public void BackoffSupervisor_must_support_custom_supervision_strategy() return Directive.Escalate; }); - assertCustomStrategy(Create(OnStopOptions().WithSupervisorStrategy(stoppingStrategy))); - assertCustomStrategy(Create(OnFailureOptions().WithSupervisorStrategy(restartingStrategy))); + await assertCustomStrategy(Create(OnStopOptions().WithSupervisorStrategy(stoppingStrategy))); + await assertCustomStrategy(Create(OnFailureOptions().WithSupervisorStrategy(restartingStrategy))); }); } [Fact] - public void BackoffSupervisor_must_support_default_stopping_strategy_when_using_Backoff_OnStop() + public async Task BackoffSupervisor_must_support_default_stopping_strategy_when_using_Backoff_OnStop() { // TODO: use FilterException - EventFilter.Exception().Expect(1, () => + await EventFilter.Exception().ExpectAsync(1, async () => { var supervisor = Create(OnStopOptions().WithDefaultStoppingStrategy()); supervisor.Tell(BackoffSupervisor.GetCurrentChild.Instance); @@ -180,7 +181,7 @@ public void BackoffSupervisor_must_support_default_stopping_strategy_when_using_ c1.Tell("boom"); ExpectTerminated(c1); - AwaitAssert(() => + await AwaitAssertAsync(() => { supervisor.Tell(BackoffSupervisor.GetCurrentChild.Instance); // new instance @@ -192,9 +193,9 @@ public void BackoffSupervisor_must_support_default_stopping_strategy_when_using_ } [Fact] - public void BackoffSupervisor_must_support_manual_reset() + public async Task BackoffSupervisor_must_support_manual_reset() { - Action assertManualReset = supervisor => + Func assertManualReset = async supervisor => { supervisor.Tell(BackoffSupervisor.GetCurrentChild.Instance); var c1 = ExpectMsg().Ref; @@ -202,13 +203,13 @@ public void BackoffSupervisor_must_support_manual_reset() c1.Tell("boom"); ExpectTerminated(c1); - AwaitAssert(() => + await AwaitAssertAsync(() => { supervisor.Tell(BackoffSupervisor.GetRestartCount.Instance); ExpectMsg().Count.Should().Be(1); }); - AwaitAssert(() => + await AwaitAssertAsync(() => { supervisor.Tell(BackoffSupervisor.GetCurrentChild.Instance); // new instance @@ -230,7 +231,7 @@ public void BackoffSupervisor_must_support_manual_reset() }; // TODO: use FilterException - EventFilter.Exception().Expect(2, () => + await EventFilter.Exception().ExpectAsync(2, async () => { var stoppingStrategy = new OneForOneStrategy(ex => { @@ -254,12 +255,12 @@ public void BackoffSupervisor_must_support_manual_reset() return Directive.Restart; }); - assertManualReset( + await assertManualReset( Create(OnStopOptions(ManualChild.Props(TestActor)) .WithManualReset() .WithSupervisorStrategy(stoppingStrategy))); - assertManualReset( + await assertManualReset( Create(OnFailureOptions(ManualChild.Props(TestActor)) .WithManualReset() .WithSupervisorStrategy(restartingStrategy))); @@ -267,9 +268,9 @@ public void BackoffSupervisor_must_support_manual_reset() } [Fact] - public void BackoffSupervisor_must_reply_to_sender_if_replyWhileStopped_is_specified() + public async Task BackoffSupervisor_must_reply_to_sender_if_replyWhileStopped_is_specified() { - EventFilter.Exception().Expect(1, () => + await EventFilter.Exception().ExpectAsync(1, async () => { var supervisor = Create(Backoff.OnFailure(Child.Props(TestActor), "c1", TimeSpan.FromSeconds(100), TimeSpan.FromSeconds(300), 0.2, -1) .WithReplyWhileStopped("child was stopped")); @@ -283,7 +284,7 @@ public void BackoffSupervisor_must_reply_to_sender_if_replyWhileStopped_is_speci c1.Tell("boom"); ExpectTerminated(c1); - AwaitAssert(() => + await AwaitAssertAsync(() => { supervisor.Tell(BackoffSupervisor.GetRestartCount.Instance); ExpectMsg().Count.Should().Be(1); @@ -295,9 +296,9 @@ public void BackoffSupervisor_must_reply_to_sender_if_replyWhileStopped_is_speci } [Fact] - public void BackoffSupervisor_must_not_reply_to_sender_if_replyWhileStopped_is_not_specified() + public async Task BackoffSupervisor_must_not_reply_to_sender_if_replyWhileStopped_is_not_specified() { - EventFilter.Exception().Expect(1, () => + await EventFilter.Exception().ExpectAsync(1, async () => { var supervisor = Create(Backoff.OnFailure(Child.Props(TestActor), "c1", TimeSpan.FromSeconds(100), TimeSpan.FromSeconds(300), 0.2, -1)); supervisor.Tell(BackoffSupervisor.GetCurrentChild.Instance); @@ -310,7 +311,7 @@ public void BackoffSupervisor_must_not_reply_to_sender_if_replyWhileStopped_is_n c1.Tell("boom"); ExpectTerminated(c1); - AwaitAssert(() => + await AwaitAssertAsync(() => { supervisor.Tell(BackoffSupervisor.GetRestartCount.Instance); ExpectMsg().Count.Should().Be(1); @@ -345,13 +346,13 @@ internal class DelayTable : IEnumerable } [Fact(Skip = "Racy on Azure DevOps")] - public void BackoffSupervisor_must_stop_restarting_the_child_after_reaching_maxNrOfRetries_limit_using_BackOff_OnStop() + public async Task BackoffSupervisor_must_stop_restarting_the_child_after_reaching_maxNrOfRetries_limit_using_BackOff_OnStop() { var supervisor = Create(OnStopOptions(maxNrOfRetries: 2)); - IActorRef WaitForChild() + async Task WaitForChild() { - AwaitCondition(() => + await AwaitConditionAsync(() => { supervisor.Tell(BackoffSupervisor.GetCurrentChild.Instance); var c = ExpectMsg().Ref; @@ -376,8 +377,8 @@ IActorRef WaitForChild() supervisor.Tell(BackoffSupervisor.GetRestartCount.Instance); ExpectMsg().Count.Should().Be(1); - var c2 = WaitForChild(); - AwaitAssert(() => c2.ShouldNotBe(c1)); + var c2 = await WaitForChild(); + await AwaitAssertAsync(() => c2.ShouldNotBe(c1)); Watch(c2); c2.Tell(PoisonPill.Instance); ExpectTerminated(c2); @@ -385,8 +386,8 @@ IActorRef WaitForChild() supervisor.Tell(BackoffSupervisor.GetRestartCount.Instance); ExpectMsg().Count.Should().Be(2); - var c3 = WaitForChild(); - AwaitAssert(() => c3.ShouldNotBe(c2)); + var c3 = await WaitForChild(); + await AwaitAssertAsync(() => c3.ShouldNotBe(c2)); Watch(c3); c3.Tell(PoisonPill.Instance); ExpectTerminated(c3); @@ -394,15 +395,15 @@ IActorRef WaitForChild() } [Fact(Skip = "Racy on Azure DevOps")] - public void BackoffSupervisor_must_stop_restarting_the_child_after_reaching_maxNrOfRetries_limit_using_BackOff_OnFailure() + public async Task BackoffSupervisor_must_stop_restarting_the_child_after_reaching_maxNrOfRetries_limit_using_BackOff_OnFailure() { - EventFilter.Exception().Expect(3, () => + await EventFilter.Exception().ExpectAsync(3, async () => { var supervisor = Create(OnFailureOptions(maxNrOfRetries: 2)); - IActorRef WaitForChild() + async Task WaitForChild() { - AwaitCondition(() => + await AwaitConditionAsync(() => { supervisor.Tell(BackoffSupervisor.GetCurrentChild.Instance); var c = ExpectMsg().Ref; @@ -427,8 +428,8 @@ IActorRef WaitForChild() supervisor.Tell(BackoffSupervisor.GetRestartCount.Instance); ExpectMsg().Count.Should().Be(1); - var c2 = WaitForChild(); - AwaitAssert(() => c2.ShouldNotBe(c1)); + var c2 = await WaitForChild(); + await AwaitAssertAsync(() => c2.ShouldNotBe(c1)); Watch(c2); c2.Tell("boom"); ExpectTerminated(c2); @@ -436,8 +437,8 @@ IActorRef WaitForChild() supervisor.Tell(BackoffSupervisor.GetRestartCount.Instance); ExpectMsg().Count.Should().Be(2); - var c3 = WaitForChild(); - AwaitAssert(() => c3.ShouldNotBe(c2)); + var c3 = await WaitForChild(); + await AwaitAssertAsync(() => c3.ShouldNotBe(c2)); Watch(c3); c3.Tell("boom"); ExpectTerminated(c3); diff --git a/src/core/Akka.Tests/Routing/ConfiguredLocalRoutingSpec.cs b/src/core/Akka.Tests/Routing/ConfiguredLocalRoutingSpec.cs index 1f4d3a8a9fe..990c8dc271c 100644 --- a/src/core/Akka.Tests/Routing/ConfiguredLocalRoutingSpec.cs +++ b/src/core/Akka.Tests/Routing/ConfiguredLocalRoutingSpec.cs @@ -127,7 +127,7 @@ public Parent() } } - private RouterConfig RouterConfig(IActorRef actor) + private async Task RouterConfigAsync(IActorRef actor) { var routedActor = (RoutedActorRef)actor; if (routedActor != null) @@ -139,8 +139,8 @@ private RouterConfig RouterConfig(IActorRef actor) } else { - AwaitCondition(() => routedActor.IsStarted, TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(10)); - return RouterConfig(actor); + await AwaitConditionAsync(() => routedActor.IsStarted, TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(10)); + return await RouterConfigAsync(actor); } } @@ -201,7 +201,7 @@ public override void Send(object message, IActorRef sender) public async Task RouterConfig_must_be_picked_up_from_Props() { var actor = Sys.ActorOf(new RoundRobinPool(12).Props(Props.Create()), "someOther"); - var routerConfig = RouterConfig(actor); + var routerConfig = await RouterConfigAsync(actor); routerConfig.Should().BeOfType(); var roundRobinPool = (RoundRobinPool)routerConfig; @@ -215,7 +215,7 @@ public async Task RouterConfig_must_be_picked_up_from_Props() public async Task RouterConfig_must_be_overridable_in_config() { var actor = Sys.ActorOf(new RoundRobinPool(12).Props(Props.Create()), "config"); - var routerConfig = RouterConfig(actor); + var routerConfig = await RouterConfigAsync(actor); routerConfig.Should().BeOfType(); var randomPool = (RandomPool)routerConfig; @@ -230,7 +230,7 @@ public async Task RouterConfig_must_be_overridable_in_config() public async Task RouterConfig_must_use_routeesPaths_from_config() { var actor = Sys.ActorOf(new RandomPool(12).Props(Props.Create()), "paths"); - var routerConfig = RouterConfig(actor); + var routerConfig = await RouterConfigAsync(actor); routerConfig.Should().BeOfType(); var randomGroup = (RandomGroup)routerConfig; @@ -244,7 +244,7 @@ public async Task RouterConfig_must_use_routeesPaths_from_config() public async Task RouterConfig_must_be_overridable_in_explicit_deployment() { var actor = Sys.ActorOf(FromConfig.Instance.Props(Props.Create()).WithDeploy(new Deploy(new RoundRobinPool(12))), "someOther"); - var routerConfig = RouterConfig(actor); + var routerConfig = await RouterConfigAsync(actor); routerConfig.Should().BeOfType(); var roundRobinPool = (RoundRobinPool)routerConfig; @@ -258,7 +258,7 @@ public async Task RouterConfig_must_be_overridable_in_explicit_deployment() public async Task RouterConfig_must_be_overridable_in_config_even_with_explicit_deployment() { var actor = Sys.ActorOf(FromConfig.Instance.Props(Props.Create()).WithDeploy(new Deploy(new RoundRobinPool(12))), "config"); - var routerConfig = RouterConfig(actor); + var routerConfig = await RouterConfigAsync(actor); routerConfig.GetType().ShouldBe(typeof(RandomPool)); var randomPool = (RandomPool)routerConfig; diff --git a/src/core/Akka.Tests/Routing/ResizerSpec.cs b/src/core/Akka.Tests/Routing/ResizerSpec.cs index 451dff1e780..01e5abfe2e5 100644 --- a/src/core/Akka.Tests/Routing/ResizerSpec.cs +++ b/src/core/Akka.Tests/Routing/ResizerSpec.cs @@ -8,6 +8,7 @@ using System; using System.Linq; using System.Threading; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.Routing; @@ -266,9 +267,9 @@ public void DefaultResizer_must_grow_as_needed_under_pressure() } [Fact(Skip = "Racy due to Resizer / Mailbox impl")] - public void DefaultResizer_must_backoff() + public async Task DefaultResizer_must_backoff() { - Within(10.Seconds(), () => + await WithinAsync(10.Seconds(), async () => { var resizer = new DefaultResizer( lower: 2, @@ -296,7 +297,7 @@ public void DefaultResizer_must_backoff() Thread.Sleep(Dilated(300.Milliseconds())); // let it cool down - AwaitCondition(() => + await AwaitConditionAsync(() => { router.Tell(0); //trigger resize Thread.Sleep(Dilated(20.Milliseconds())); diff --git a/src/core/Akka.Tests/Routing/RoutingSpec.cs b/src/core/Akka.Tests/Routing/RoutingSpec.cs index c49dd2a950e..b3473dac2f8 100644 --- a/src/core/Akka.Tests/Routing/RoutingSpec.cs +++ b/src/core/Akka.Tests/Routing/RoutingSpec.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Threading.Tasks; using Akka.Actor; using Akka.Configuration; using Akka.Dispatch; @@ -160,7 +161,7 @@ public ForwardActor(IActorRef testActor) } [Fact] - public void Routers_in_general_must_evict_terminated_routees() + public async Task Routers_in_general_must_evict_terminated_routees() { var router = Sys.ActorOf(new RoundRobinPool(2).Props(Props.Create())); router.Tell(""); @@ -175,7 +176,7 @@ public void Routers_in_general_must_evict_terminated_routees() ExpectTerminated(c2).ExistenceConfirmed.Should().BeTrue(); // it might take a while until the Router has actually processed the Terminated message - AwaitCondition(() => + await AwaitConditionAsync(() => { router.Tell(""); router.Tell("");