@@ -7,76 +7,86 @@ import "dart:io";
7
7
8
8
import "package:expect/expect.dart" ;
9
9
10
- Future testCustomPortIPv4 () async {
10
+ Future testCustomPortIPv4 () {
11
11
String clientAddress = "127.0.0.1" ;
12
12
int customLocalPort = 50988 ;
13
13
String serverAddress = clientAddress;
14
14
int port = 50989 ;
15
15
16
- testCustomPort (serverAddress, port, clientAddress, customLocalPort);
16
+ return testCustomPort (serverAddress, port, clientAddress, customLocalPort);
17
17
}
18
18
19
- Future testCustomPortIPv6 () async {
19
+ Future testCustomPortIPv6 () {
20
20
String clientAddress = "::1" ;
21
21
int customLocalPort = 50988 ;
22
22
String serverAddress = clientAddress;
23
23
int port = 50989 ;
24
24
25
- testCustomPort (serverAddress, port, clientAddress, customLocalPort);
25
+ return testCustomPort (serverAddress, port, clientAddress, customLocalPort);
26
26
}
27
27
28
- Future testCustomPortIPv4NoSourceAddress () async {
28
+ Future testCustomPortIPv4NoSourceAddress () {
29
29
String expectedClientAddress = "127.0.0.1" ;
30
30
int customLocalPort = 50988 ;
31
31
String serverAddress = expectedClientAddress;
32
32
int port = 50989 ;
33
33
34
- testCustomPort (serverAddress, port, expectedClientAddress, customLocalPort);
34
+ return testCustomPort (
35
+ serverAddress,
36
+ port,
37
+ expectedClientAddress,
38
+ customLocalPort,
39
+ );
35
40
}
36
41
37
- Future testCustomPortIPv6NoSourceAddress () async {
42
+ Future testCustomPortIPv6NoSourceAddress () {
38
43
String expectedClientAddress = "::1" ;
39
44
int customLocalPort = 50988 ;
40
45
String serverAddress = expectedClientAddress;
41
46
int port = 50989 ;
42
47
43
- testCustomPort (serverAddress, port, expectedClientAddress, customLocalPort);
48
+ return testCustomPort (
49
+ serverAddress,
50
+ port,
51
+ expectedClientAddress,
52
+ customLocalPort,
53
+ );
44
54
}
45
55
46
- Future testNoCustomPortIPv4 () async {
56
+ Future testNoCustomPortIPv4 () {
47
57
String host = "127.0.0.1" ;
48
58
String clientAddress = host;
49
59
int serverPort = 39998 ;
50
60
51
- await testNoCustomPortNoSourceAddress (host, serverPort, clientAddress);
61
+ return testNoCustomPortNoSourceAddress (host, serverPort, clientAddress);
52
62
}
53
63
54
- Future testNoCustomPortIPv6 () async {
64
+ Future testNoCustomPortIPv6 () {
55
65
String host = "::1" ;
56
66
String clientAddress = host;
57
67
int serverPort = 39998 ;
58
68
59
- await testNoCustomPortNoSourceAddress (host, serverPort, clientAddress);
69
+ return testNoCustomPortNoSourceAddress (host, serverPort, clientAddress);
60
70
}
61
71
62
- Future testNoCustomPortNoSourceAddressIPv4 () async {
72
+ Future testNoCustomPortNoSourceAddressIPv4 () {
63
73
String host = "127.0.0.1" ;
64
74
String expectedAddress = host;
65
75
int serverPort = 39998 ;
66
76
67
- await testNoCustomPortNoSourceAddress (host, serverPort, expectedAddress);
77
+ return testNoCustomPortNoSourceAddress (host, serverPort, expectedAddress);
68
78
}
69
79
70
- Future testNoCustomPortNoSourceAddressIPv6 () async {
80
+ Future testNoCustomPortNoSourceAddressIPv6 () {
71
81
String host = "::1" ;
72
82
String expectedAddress = host;
73
83
int serverPort = 39998 ;
74
84
75
- await testNoCustomPortNoSourceAddress (host, serverPort, expectedAddress);
85
+ return testNoCustomPortNoSourceAddress (host, serverPort, expectedAddress);
76
86
}
77
87
78
88
// Core functionality
79
- void testCustomPort (
89
+ Future testCustomPort (
80
90
String host,
81
91
int port,
82
92
String sourceAddress,
@@ -97,7 +107,7 @@ void testCustomPort(
97
107
sourcePort: sourcePort,
98
108
);
99
109
s.destroy ();
100
- server.close ();
110
+ await server.close ();
101
111
}
102
112
103
113
Future testCustomPortNoSourceAddress (
@@ -119,29 +129,34 @@ Future testCustomPortNoSourceAddress(
119
129
120
130
Socket s = await Socket .connect (host, port, sourcePort: sourcePort);
121
131
s.destroy ();
122
- server.close ();
132
+ await server.close ();
123
133
124
134
return completer.future;
125
135
}
126
136
127
137
Future testNoCustomPort (String host, int port, String sourceAddress) async {
128
- Completer completer = new Completer ();
138
+ Completer serverCompleter = new Completer ();
139
+ Completer clientCompleter = new Completer ();
129
140
var server = await ServerSocket .bind (host, port);
130
- Socket .connect (host, port, sourceAddress: sourceAddress).then ((clientSocket) {
131
- server.listen ((client) {
141
+ Socket .connect (host, port, sourceAddress: sourceAddress).then ((
142
+ clientSocket,
143
+ ) async {
144
+ server.listen ((client) async {
132
145
Expect .equals (server.port, port);
133
146
Expect .equals (client.remotePort, clientSocket.port);
134
147
Expect .equals (client.address.address, sourceAddress);
135
148
136
149
client.destroy ();
137
- completer .complete ();
150
+ clientCompleter .complete ();
138
151
});
139
152
140
153
clientSocket.destroy ();
141
- server.close ();
154
+ await server.close ();
155
+ serverCompleter.complete ();
142
156
});
143
157
144
- return completer.future;
158
+ await serverCompleter.future;
159
+ await clientCompleter.future;
145
160
}
146
161
147
162
Future testNoCustomPortNoSourceAddress (
@@ -152,13 +167,13 @@ Future testNoCustomPortNoSourceAddress(
152
167
Completer completer = new Completer ();
153
168
var server = await ServerSocket .bind (host, port);
154
169
Socket .connect (host, port).then ((clientSocket) {
155
- server.listen ((client) {
170
+ server.listen ((client) async {
156
171
Expect .equals (server.port, port);
157
172
Expect .equals (client.remotePort, clientSocket.port);
158
173
Expect .equals (client.address.address, expectedAddress);
159
174
clientSocket.destroy ();
160
175
client.destroy ();
161
- server.close ();
176
+ await server.close ();
162
177
completer.complete ();
163
178
});
164
179
});
0 commit comments