diff --git a/src/Akka.Hosting.TestKit.Tests/TestActorRefTests/TestActorRefSpec.cs b/src/Akka.Hosting.TestKit.Tests/TestActorRefTests/TestActorRefSpec.cs index 1b6cd5fc..9bb108d2 100644 --- a/src/Akka.Hosting.TestKit.Tests/TestActorRefTests/TestActorRefSpec.cs +++ b/src/Akka.Hosting.TestKit.Tests/TestActorRefTests/TestActorRefSpec.cs @@ -64,21 +64,21 @@ public void TestActorRef_name_must_start_with_double_dollar_sign() } [Fact] - public void TestActorRef_must_support_nested_Actor_creation_when_used_with_TestActorRef() + public async Task TestActorRef_must_support_nested_Actor_creation_when_used_with_TestActorRef() { var a = new TestActorRef(Sys, Props.Create(() => new NestingActor(true))); Assert.NotNull(a); - var nested = a.Ask("any", DefaultTimeout).Result; + var nested = await a.Ask("any", DefaultTimeout); Assert.NotNull(nested); Assert.NotSame(a, nested); } [Fact] - public void TestActorRef_must_support_nested_Actor_creation_when_used_with_ActorRef() + public async Task TestActorRef_must_support_nested_Actor_creation_when_used_with_ActorRef() { var a = new TestActorRef(Sys, Props.Create(() => new NestingActor(false))); Assert.NotNull(a); - var nested = a.Ask("any", DefaultTimeout).Result; + var nested = await a.Ask("any", DefaultTimeout); Assert.NotNull(nested); Assert.NotSame(a, nested); } @@ -135,13 +135,13 @@ public void TestActorRef_must_restart_when_killed() } [Fact] - public void TestActorRef_must_support_futures() + public async Task TestActorRef_must_support_futures() { var worker = new TestActorRef(Sys, Props.Create()); var task = worker.Ask("work"); Assert.True(task.IsCompleted, "Task should be completed"); - if(!task.Wait(DefaultTimeout)) throw new TimeoutException("Timed out"); //Using a timeout to stop the test if there is something wrong with the code - Assert.Equal("workDone", task.Result); + var result = await task.WaitAsync(DefaultTimeout); //Using a timeout to stop the test if there is something wrong with the code + Assert.Equal("workDone", result); } [Fact] diff --git a/src/Akka.Hosting.TestKit.Tests/TestSchedulerTests.cs b/src/Akka.Hosting.TestKit.Tests/TestSchedulerTests.cs index ea71433d..d42075d0 100644 --- a/src/Akka.Hosting.TestKit.Tests/TestSchedulerTests.cs +++ b/src/Akka.Hosting.TestKit.Tests/TestSchedulerTests.cs @@ -36,95 +36,95 @@ protected override async Task BeforeTestStart() protected override Config Config { get; } = TestConfigs.TestSchedulerConfig; [Fact] - public void Delivers_message_when_scheduled_time_reached() + public async Task Delivers_message_when_scheduled_time_reached() { _testReceiveActor.Tell(new ScheduleOnceMessage(TimeSpan.FromSeconds(1))); - _testReceiveActor.Ask(new Identify(null), RemainingOrDefault) - .Wait(RemainingOrDefault).Should().BeTrue(); // verify that the ActorCell has started + (await _testReceiveActor.Ask(new Identify(null), RemainingOrDefault).WaitAsync(RemainingOrDefault)) + .Should().BeOfType(); // verify that the ActorCell has started Scheduler.Advance(TimeSpan.FromSeconds(1)); - ExpectMsg(); + await ExpectMsgAsync(); } [Fact] - public void Does_not_deliver_message_prematurely() + public async Task Does_not_deliver_message_prematurely() { _testReceiveActor.Tell(new ScheduleOnceMessage(TimeSpan.FromSeconds(1))); - _testReceiveActor.Ask(new Identify(null), RemainingOrDefault) - .Wait(RemainingOrDefault).Should().BeTrue(); // verify that the ActorCell has started + (await _testReceiveActor.Ask(new Identify(null), RemainingOrDefault).WaitAsync(RemainingOrDefault)) + .Should().BeOfType(); // verify that the ActorCell has started Scheduler.Advance(TimeSpan.FromMilliseconds(999)); - ExpectNoMsg(TimeSpan.FromMilliseconds(20)); + await ExpectNoMsgAsync(TimeSpan.FromMilliseconds(20)); } [Fact] - public void Delivers_messages_scheduled_for_same_time_in_order_they_were_added() + public async Task Delivers_messages_scheduled_for_same_time_in_order_they_were_added() { _testReceiveActor.Tell(new ScheduleOnceMessage(TimeSpan.FromSeconds(1), 1)); _testReceiveActor.Tell(new ScheduleOnceMessage(TimeSpan.FromSeconds(1), 2)); - _testReceiveActor.Ask(new Identify(null), RemainingOrDefault) - .Wait(RemainingOrDefault).Should().BeTrue(); // verify that the ActorCell has started + (await _testReceiveActor.Ask(new Identify(null), RemainingOrDefault).WaitAsync(RemainingOrDefault)) + .Should().BeOfType(); // verify that the ActorCell has started Scheduler.Advance(TimeSpan.FromSeconds(1)); - var firstId = ExpectMsg().Id; - var secondId = ExpectMsg().Id; + var firstId = (await ExpectMsgAsync()).Id; + var secondId = (await ExpectMsgAsync()).Id; Assert.Equal(1, firstId); Assert.Equal(2, secondId); } [Fact] - public void Keeps_delivering_rescheduled_message() + public async Task Keeps_delivering_rescheduled_message() { _testReceiveActor.Tell(new RescheduleMessage(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5))); - _testReceiveActor.Ask(new Identify(null), RemainingOrDefault) - .Wait(RemainingOrDefault).Should().BeTrue(); // verify that the ActorCell has started + (await _testReceiveActor.Ask(new Identify(null), RemainingOrDefault).WaitAsync(RemainingOrDefault)) + .Should().BeOfType(); // verify that the ActorCell has started for (int i = 0; i < 500; i ++) { Scheduler.Advance(TimeSpan.FromSeconds(5)); - ExpectMsg(); + await ExpectMsgAsync(); } } [Fact] - public void Uses_initial_delay_to_schedule_first_rescheduled_message() + public async Task Uses_initial_delay_to_schedule_first_rescheduled_message() { _testReceiveActor.Tell(new RescheduleMessage(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5))); - _testReceiveActor.Ask(new Identify(null), RemainingOrDefault) - .Wait(RemainingOrDefault).Should().BeTrue(); // verify that the ActorCell has started + (await _testReceiveActor.Ask(new Identify(null), RemainingOrDefault).WaitAsync(RemainingOrDefault)) + .Should().BeOfType(); // verify that the ActorCell has started Scheduler.Advance(TimeSpan.FromSeconds(1)); - ExpectMsg(); + await ExpectMsgAsync(); } [Fact] - public void Doesnt_reschedule_cancelled() + public async Task Doesnt_reschedule_cancelled() { _testReceiveActor.Tell(new CancelableMessage(TimeSpan.FromSeconds(1))); - _testReceiveActor.Ask(new Identify(null), RemainingOrDefault) - .Wait(RemainingOrDefault).Should().BeTrue(); // verify that the ActorCell has started + (await _testReceiveActor.Ask(new Identify(null), RemainingOrDefault).WaitAsync(RemainingOrDefault)) + .Should().BeOfType(); // verify that the ActorCell has started Scheduler.Advance(TimeSpan.FromSeconds(1)); - ExpectMsg(); + await ExpectMsgAsync(); _testReceiveActor.Tell(new CancelMessage()); Scheduler.Advance(TimeSpan.FromSeconds(1)); - ExpectNoMsg(TimeSpan.FromMilliseconds(20)); + await ExpectNoMsgAsync(TimeSpan.FromMilliseconds(20)); } [Fact] - public void Advance_to_takes_us_to_correct_time() + public async Task Advance_to_takes_us_to_correct_time() { _testReceiveActor.Tell(new ScheduleOnceMessage(TimeSpan.FromSeconds(1), 1)); _testReceiveActor.Tell(new ScheduleOnceMessage(TimeSpan.FromSeconds(2), 2)); _testReceiveActor.Tell(new ScheduleOnceMessage(TimeSpan.FromSeconds(3), 3)); - _testReceiveActor.Ask(new Identify(null), RemainingOrDefault) - .Wait(RemainingOrDefault).Should().BeTrue(); // verify that the ActorCell has started + (await _testReceiveActor.Ask(new Identify(null), RemainingOrDefault).WaitAsync(RemainingOrDefault)) + .Should().BeOfType(); // verify that the ActorCell has started Scheduler.AdvanceTo(Scheduler.Now.AddSeconds(2)); - var firstId = ExpectMsg().Id; - var secondId = ExpectMsg().Id; - ExpectNoMsg(TimeSpan.FromMilliseconds(20)); + var firstId = (await ExpectMsgAsync()).Id; + var secondId = (await ExpectMsgAsync()).Id; + await ExpectNoMsgAsync(TimeSpan.FromMilliseconds(20)); Assert.Equal(1, firstId); Assert.Equal(2, secondId); } diff --git a/src/Akka.Hosting.Tests/ActorRegistrySpecs.cs b/src/Akka.Hosting.Tests/ActorRegistrySpecs.cs index 2353ebe3..953cd909 100644 --- a/src/Akka.Hosting.Tests/ActorRegistrySpecs.cs +++ b/src/Akka.Hosting.Tests/ActorRegistrySpecs.cs @@ -5,6 +5,7 @@ using Akka.Actor; using FluentAssertions; using Xunit; +using static FluentAssertions.FluentActions; namespace Akka.Hosting.Tests; @@ -129,7 +130,7 @@ public void GetAsync_should_return_CompletedTask_if_Key_AlreadyExists() } [Fact] - public void GetAsync_should_Cancel_after_Timeout() + public async Task GetAsync_should_Cancel_after_Timeout() { // arrange var registry = new ActorRegistry(); @@ -137,13 +138,11 @@ public void GetAsync_should_Cancel_after_Timeout() // act var task = registry.GetAsync(cancellationTokenSource.Token); - Action cancel = () => + // assert + await Awaiting(async () => { cancellationTokenSource.Cancel(); - task.Wait(TimeSpan.FromSeconds(3)); - }; - - // assert - cancel.Should().Throw(); + await task.WaitAsync(TimeSpan.FromSeconds(3)); + }).Should().ThrowAsync(); } } \ No newline at end of file diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 6c1879be..3f491959 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -22,7 +22,7 @@ netstandard2.0 net6.0 - 2.5.0 + 2.5.1 17.7.2 6.0.0 2.5.1