diff --git a/src/core/Akka.Tests/IO/UdpListenerSpec.cs b/src/core/Akka.Tests/IO/UdpListenerSpec.cs index 27eda4f0a9b..60e744ebf94 100644 --- a/src/core/Akka.Tests/IO/UdpListenerSpec.cs +++ b/src/core/Akka.Tests/IO/UdpListenerSpec.cs @@ -16,6 +16,7 @@ using Xunit.Abstractions; using UdpListener = Akka.IO.UdpListener; using FluentAssertions; +using System.Threading.Tasks; namespace Akka.Tests.IO { @@ -32,7 +33,7 @@ public UdpListenerSpec(ITestOutputHelper output) { } [Fact] - public void UDP_should_return_IPv4_endpoint_if_bound_using_IPv4_address() + public async Task UDP_should_return_IPv4_endpoint_if_bound_using_IPv4_address() { var probe = CreateTestProbe(); try @@ -40,7 +41,7 @@ public void UDP_should_return_IPv4_endpoint_if_bound_using_IPv4_address() var endpoint = new IPEndPoint(IPAddress.Loopback, 12345); var handler = Sys.ActorOf(Props.Create(() => new MockUdpHandler())); Sys.Udp().Tell(new Udp.Bind(handler, endpoint), probe.Ref); - var bound = probe.ExpectMsg(); + var bound = await probe.ExpectMsgAsync(); bound.LocalAddress.Should().BeOfType(); var boundEndpoint = (IPEndPoint)bound.LocalAddress; @@ -56,7 +57,7 @@ public void UDP_should_return_IPv4_endpoint_if_bound_using_IPv4_address() } [Fact] - public void UDP_should_return_IPv6_endpoint_if_bound_using_IPv6_address() + public async Task UDP_should_return_IPv6_endpoint_if_bound_using_IPv6_address() { var probe = CreateTestProbe(); try @@ -64,7 +65,7 @@ public void UDP_should_return_IPv6_endpoint_if_bound_using_IPv6_address() var endpoint = new IPEndPoint(IPAddress.IPv6Loopback, 12345); var handler = Sys.ActorOf(Props.Create(() => new MockUdpHandler())); Sys.Udp().Tell(new Udp.Bind(handler, endpoint), probe.Ref); - var bound = probe.ExpectMsg(); + var bound = await probe.ExpectMsgAsync(); bound.LocalAddress.Should().BeOfType(); var boundEndpoint = (IPEndPoint)bound.LocalAddress; @@ -80,39 +81,39 @@ public void UDP_should_return_IPv6_endpoint_if_bound_using_IPv6_address() } [Fact] - public void A_UDP_Listener_must_let_the_bind_commander_know_when_binding_is_complete() + public async Task A_UDP_Listener_must_let_the_bind_commander_know_when_binding_is_complete() { - new TestSetup(this).Run(x => + await new TestSetup(this).RunAsync(async x => { - x.BindCommander.ExpectMsg(); + await x.BindCommander.ExpectMsgAsync(); }); } [Fact] - public void A_UDP_Listener_must_forward_incoming_packets_to_handler_actor() + public async Task A_UDP_Listener_must_forward_incoming_packets_to_handler_actor() { const string dgram = "Fly little packet!"; - new TestSetup(this).Run(x => + await new TestSetup(this).RunAsync(async x => { - x.BindCommander.ExpectMsg(); + await x.BindCommander.ExpectMsgAsync(); x.SendDataToLocal(Encoding.UTF8.GetBytes(dgram)); - x.Handler.ExpectMsg(_ => Assert.Equal(dgram, Encoding.UTF8.GetString(_.Data.ToArray()))); + await x.Handler.ExpectMsgAsync(_ => Assert.Equal(dgram, Encoding.UTF8.GetString(_.Data.ToArray()))); x.SendDataToLocal(Encoding.UTF8.GetBytes(dgram)); - x.Handler.ExpectMsg(_ => Assert.Equal(dgram, Encoding.UTF8.GetString(_.Data.ToArray()))); + await x.Handler.ExpectMsgAsync(_ => Assert.Equal(dgram, Encoding.UTF8.GetString(_.Data.ToArray()))); }); } [Fact] - public void A_UDP_Listener_must_be_able_to_send_and_receive_when_server_goes_away() + public async Task A_UDP_Listener_must_be_able_to_send_and_receive_when_server_goes_away() { - new TestSetup(this).Run(x => + await new TestSetup(this).RunAsync(async x => { - x.BindCommander.ExpectMsg(); + await x.BindCommander.ExpectMsgAsync(); // Receive UDP messages from a sender const string requestMessage = "This is my last request!"; var notExistingEndPoint = x.SendDataToLocal(Encoding.UTF8.GetBytes(requestMessage)); - x.Handler.ExpectMsg(_ => + await x.Handler.ExpectMsgAsync(_ => { Assert.Equal(requestMessage, Encoding.UTF8.GetString(_.Data.ToArray())); }); @@ -126,11 +127,11 @@ public void A_UDP_Listener_must_be_able_to_send_and_receive_when_server_goes_awa localSender.Tell(Udp.Send.Create(ByteString.FromBytes(Encoding.UTF8.GetBytes(response)), notExistingEndPoint)); // Now an ICMP error message "port unreachable" (SocketError.ConnectionReset) is sent to our UDP server port - x.Handler.ExpectNoMsg(TimeSpan.FromSeconds(1)); + await x.Handler.ExpectNoMsgAsync(TimeSpan.FromSeconds(1)); const string followUpMessage = "Back online!"; x.SendDataToLocal(Encoding.UTF8.GetBytes(followUpMessage)); - x.Handler.ExpectMsg(_ => Assert.Equal(followUpMessage, Encoding.UTF8.GetString(_.Data.ToArray()))); + await x.Handler.ExpectMsgAsync(_ => Assert.Equal(followUpMessage, Encoding.UTF8.GetString(_.Data.ToArray()))); }); } @@ -168,10 +169,13 @@ public void Run(Action test) { test(this); } - - public void BindListener() + public async Task RunAsync(Func test) + { + await test(this); + } + public async Task BindListener() { - _bindCommander.ExpectMsg(); + await _bindCommander.ExpectMsgAsync(); } public IPEndPoint SendDataToLocal(byte[] buffer)