16
16
using Xunit . Abstractions ;
17
17
using UdpListener = Akka . IO . UdpListener ;
18
18
using FluentAssertions ;
19
+ using System . Threading . Tasks ;
19
20
20
21
namespace Akka . Tests . IO
21
22
{
@@ -32,15 +33,15 @@ public UdpListenerSpec(ITestOutputHelper output)
32
33
{ }
33
34
34
35
[ Fact ]
35
- public void UDP_should_return_IPv4_endpoint_if_bound_using_IPv4_address ( )
36
+ public async Task UDP_should_return_IPv4_endpoint_if_bound_using_IPv4_address ( )
36
37
{
37
38
var probe = CreateTestProbe ( ) ;
38
39
try
39
40
{
40
41
var endpoint = new IPEndPoint ( IPAddress . Loopback , 12345 ) ;
41
42
var handler = Sys . ActorOf ( Props . Create ( ( ) => new MockUdpHandler ( ) ) ) ;
42
43
Sys . Udp ( ) . Tell ( new Udp . Bind ( handler , endpoint ) , probe . Ref ) ;
43
- var bound = probe . ExpectMsg < Udp . Bound > ( ) ;
44
+ var bound = await probe . ExpectMsgAsync < Udp . Bound > ( ) ;
44
45
45
46
bound . LocalAddress . Should ( ) . BeOfType < IPEndPoint > ( ) ;
46
47
var boundEndpoint = ( IPEndPoint ) bound . LocalAddress ;
@@ -56,15 +57,15 @@ public void UDP_should_return_IPv4_endpoint_if_bound_using_IPv4_address()
56
57
}
57
58
58
59
[ Fact ]
59
- public void UDP_should_return_IPv6_endpoint_if_bound_using_IPv6_address ( )
60
+ public async Task UDP_should_return_IPv6_endpoint_if_bound_using_IPv6_address ( )
60
61
{
61
62
var probe = CreateTestProbe ( ) ;
62
63
try
63
64
{
64
65
var endpoint = new IPEndPoint ( IPAddress . IPv6Loopback , 12345 ) ;
65
66
var handler = Sys . ActorOf ( Props . Create ( ( ) => new MockUdpHandler ( ) ) ) ;
66
67
Sys . Udp ( ) . Tell ( new Udp . Bind ( handler , endpoint ) , probe . Ref ) ;
67
- var bound = probe . ExpectMsg < Udp . Bound > ( ) ;
68
+ var bound = await probe . ExpectMsgAsync < Udp . Bound > ( ) ;
68
69
69
70
bound . LocalAddress . Should ( ) . BeOfType < IPEndPoint > ( ) ;
70
71
var boundEndpoint = ( IPEndPoint ) bound . LocalAddress ;
@@ -80,39 +81,39 @@ public void UDP_should_return_IPv6_endpoint_if_bound_using_IPv6_address()
80
81
}
81
82
82
83
[ Fact ]
83
- public void A_UDP_Listener_must_let_the_bind_commander_know_when_binding_is_complete ( )
84
+ public async Task A_UDP_Listener_must_let_the_bind_commander_know_when_binding_is_complete ( )
84
85
{
85
- new TestSetup ( this ) . Run ( x =>
86
+ await new TestSetup ( this ) . RunAsync ( async x =>
86
87
{
87
- x . BindCommander . ExpectMsg < Udp . Bound > ( ) ;
88
+ await x . BindCommander . ExpectMsgAsync < Udp . Bound > ( ) ;
88
89
} ) ;
89
90
}
90
91
91
92
[ Fact ]
92
- public void A_UDP_Listener_must_forward_incoming_packets_to_handler_actor ( )
93
+ public async Task A_UDP_Listener_must_forward_incoming_packets_to_handler_actor ( )
93
94
{
94
95
const string dgram = "Fly little packet!" ;
95
- new TestSetup ( this ) . Run ( x =>
96
+ await new TestSetup ( this ) . RunAsync ( async x =>
96
97
{
97
- x . BindCommander . ExpectMsg < Udp . Bound > ( ) ;
98
+ await x . BindCommander . ExpectMsgAsync < Udp . Bound > ( ) ;
98
99
x . SendDataToLocal ( Encoding . UTF8 . GetBytes ( dgram ) ) ;
99
- x . Handler . ExpectMsg < Udp . Received > ( _ => Assert . Equal ( dgram , Encoding . UTF8 . GetString ( _ . Data . ToArray ( ) ) ) ) ;
100
+ await x . Handler . ExpectMsgAsync < Udp . Received > ( _ => Assert . Equal ( dgram , Encoding . UTF8 . GetString ( _ . Data . ToArray ( ) ) ) ) ;
100
101
x . SendDataToLocal ( Encoding . UTF8 . GetBytes ( dgram ) ) ;
101
- x . Handler . ExpectMsg < Udp . Received > ( _ => Assert . Equal ( dgram , Encoding . UTF8 . GetString ( _ . Data . ToArray ( ) ) ) ) ;
102
+ await x . Handler . ExpectMsgAsync < Udp . Received > ( _ => Assert . Equal ( dgram , Encoding . UTF8 . GetString ( _ . Data . ToArray ( ) ) ) ) ;
102
103
} ) ;
103
104
}
104
105
105
106
[ Fact ]
106
- public void A_UDP_Listener_must_be_able_to_send_and_receive_when_server_goes_away ( )
107
+ public async Task A_UDP_Listener_must_be_able_to_send_and_receive_when_server_goes_away ( )
107
108
{
108
- new TestSetup ( this ) . Run ( x =>
109
+ await new TestSetup ( this ) . RunAsync ( async x =>
109
110
{
110
- x . BindCommander . ExpectMsg < Udp . Bound > ( ) ;
111
+ await x . BindCommander . ExpectMsgAsync < Udp . Bound > ( ) ;
111
112
112
113
// Receive UDP messages from a sender
113
114
const string requestMessage = "This is my last request!" ;
114
115
var notExistingEndPoint = x . SendDataToLocal ( Encoding . UTF8 . GetBytes ( requestMessage ) ) ;
115
- x . Handler . ExpectMsg < Udp . Received > ( _ =>
116
+ await x . Handler . ExpectMsgAsync < Udp . Received > ( _ =>
116
117
{
117
118
Assert . Equal ( requestMessage , Encoding . UTF8 . GetString ( _ . Data . ToArray ( ) ) ) ;
118
119
} ) ;
@@ -126,11 +127,11 @@ public void A_UDP_Listener_must_be_able_to_send_and_receive_when_server_goes_awa
126
127
localSender . Tell ( Udp . Send . Create ( ByteString . FromBytes ( Encoding . UTF8 . GetBytes ( response ) ) , notExistingEndPoint ) ) ;
127
128
128
129
// Now an ICMP error message "port unreachable" (SocketError.ConnectionReset) is sent to our UDP server port
129
- x . Handler . ExpectNoMsg ( TimeSpan . FromSeconds ( 1 ) ) ;
130
+ await x . Handler . ExpectNoMsgAsync ( TimeSpan . FromSeconds ( 1 ) ) ;
130
131
131
132
const string followUpMessage = "Back online!" ;
132
133
x . SendDataToLocal ( Encoding . UTF8 . GetBytes ( followUpMessage ) ) ;
133
- x . Handler . ExpectMsg < Udp . Received > ( _ => Assert . Equal ( followUpMessage , Encoding . UTF8 . GetString ( _ . Data . ToArray ( ) ) ) ) ;
134
+ await x . Handler . ExpectMsgAsync < Udp . Received > ( _ => Assert . Equal ( followUpMessage , Encoding . UTF8 . GetString ( _ . Data . ToArray ( ) ) ) ) ;
134
135
} ) ;
135
136
}
136
137
@@ -168,10 +169,13 @@ public void Run(Action<TestSetup> test)
168
169
{
169
170
test ( this ) ;
170
171
}
171
-
172
- public void BindListener ( )
172
+ public async Task RunAsync ( Func < TestSetup , Task > test )
173
+ {
174
+ await test ( this ) ;
175
+ }
176
+ public async Task BindListener ( )
173
177
{
174
- _bindCommander . ExpectMsg < Udp . Bound > ( ) ;
178
+ await _bindCommander . ExpectMsgAsync < Udp . Bound > ( ) ;
175
179
}
176
180
177
181
public IPEndPoint SendDataToLocal ( byte [ ] buffer )
0 commit comments