Skip to content

Commit b3beefb

Browse files
rmacnak-googleCommit Queue
authored and
Commit Queue
committed
[test] Await closing server socket before reusing the same fixed port.
Bug: #51477 Change-Id: I591fb791d262d392212995bd75b6ff865b9fc5df Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427323 Commit-Queue: Ryan Macnak <[email protected]> Reviewed-by: Brian Quinlan <[email protected]>
1 parent 0a6fa7a commit b3beefb

File tree

1 file changed

+42
-27
lines changed

1 file changed

+42
-27
lines changed

tests/standalone/io/socket_local_port_test.dart

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,76 +7,86 @@ import "dart:io";
77

88
import "package:expect/expect.dart";
99

10-
Future testCustomPortIPv4() async {
10+
Future testCustomPortIPv4() {
1111
String clientAddress = "127.0.0.1";
1212
int customLocalPort = 50988;
1313
String serverAddress = clientAddress;
1414
int port = 50989;
1515

16-
testCustomPort(serverAddress, port, clientAddress, customLocalPort);
16+
return testCustomPort(serverAddress, port, clientAddress, customLocalPort);
1717
}
1818

19-
Future testCustomPortIPv6() async {
19+
Future testCustomPortIPv6() {
2020
String clientAddress = "::1";
2121
int customLocalPort = 50988;
2222
String serverAddress = clientAddress;
2323
int port = 50989;
2424

25-
testCustomPort(serverAddress, port, clientAddress, customLocalPort);
25+
return testCustomPort(serverAddress, port, clientAddress, customLocalPort);
2626
}
2727

28-
Future testCustomPortIPv4NoSourceAddress() async {
28+
Future testCustomPortIPv4NoSourceAddress() {
2929
String expectedClientAddress = "127.0.0.1";
3030
int customLocalPort = 50988;
3131
String serverAddress = expectedClientAddress;
3232
int port = 50989;
3333

34-
testCustomPort(serverAddress, port, expectedClientAddress, customLocalPort);
34+
return testCustomPort(
35+
serverAddress,
36+
port,
37+
expectedClientAddress,
38+
customLocalPort,
39+
);
3540
}
3641

37-
Future testCustomPortIPv6NoSourceAddress() async {
42+
Future testCustomPortIPv6NoSourceAddress() {
3843
String expectedClientAddress = "::1";
3944
int customLocalPort = 50988;
4045
String serverAddress = expectedClientAddress;
4146
int port = 50989;
4247

43-
testCustomPort(serverAddress, port, expectedClientAddress, customLocalPort);
48+
return testCustomPort(
49+
serverAddress,
50+
port,
51+
expectedClientAddress,
52+
customLocalPort,
53+
);
4454
}
4555

46-
Future testNoCustomPortIPv4() async {
56+
Future testNoCustomPortIPv4() {
4757
String host = "127.0.0.1";
4858
String clientAddress = host;
4959
int serverPort = 39998;
5060

51-
await testNoCustomPortNoSourceAddress(host, serverPort, clientAddress);
61+
return testNoCustomPortNoSourceAddress(host, serverPort, clientAddress);
5262
}
5363

54-
Future testNoCustomPortIPv6() async {
64+
Future testNoCustomPortIPv6() {
5565
String host = "::1";
5666
String clientAddress = host;
5767
int serverPort = 39998;
5868

59-
await testNoCustomPortNoSourceAddress(host, serverPort, clientAddress);
69+
return testNoCustomPortNoSourceAddress(host, serverPort, clientAddress);
6070
}
6171

62-
Future testNoCustomPortNoSourceAddressIPv4() async {
72+
Future testNoCustomPortNoSourceAddressIPv4() {
6373
String host = "127.0.0.1";
6474
String expectedAddress = host;
6575
int serverPort = 39998;
6676

67-
await testNoCustomPortNoSourceAddress(host, serverPort, expectedAddress);
77+
return testNoCustomPortNoSourceAddress(host, serverPort, expectedAddress);
6878
}
6979

70-
Future testNoCustomPortNoSourceAddressIPv6() async {
80+
Future testNoCustomPortNoSourceAddressIPv6() {
7181
String host = "::1";
7282
String expectedAddress = host;
7383
int serverPort = 39998;
7484

75-
await testNoCustomPortNoSourceAddress(host, serverPort, expectedAddress);
85+
return testNoCustomPortNoSourceAddress(host, serverPort, expectedAddress);
7686
}
7787

7888
// Core functionality
79-
void testCustomPort(
89+
Future testCustomPort(
8090
String host,
8191
int port,
8292
String sourceAddress,
@@ -97,7 +107,7 @@ void testCustomPort(
97107
sourcePort: sourcePort,
98108
);
99109
s.destroy();
100-
server.close();
110+
await server.close();
101111
}
102112

103113
Future testCustomPortNoSourceAddress(
@@ -119,29 +129,34 @@ Future testCustomPortNoSourceAddress(
119129

120130
Socket s = await Socket.connect(host, port, sourcePort: sourcePort);
121131
s.destroy();
122-
server.close();
132+
await server.close();
123133

124134
return completer.future;
125135
}
126136

127137
Future testNoCustomPort(String host, int port, String sourceAddress) async {
128-
Completer completer = new Completer();
138+
Completer serverCompleter = new Completer();
139+
Completer clientCompleter = new Completer();
129140
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 {
132145
Expect.equals(server.port, port);
133146
Expect.equals(client.remotePort, clientSocket.port);
134147
Expect.equals(client.address.address, sourceAddress);
135148

136149
client.destroy();
137-
completer.complete();
150+
clientCompleter.complete();
138151
});
139152

140153
clientSocket.destroy();
141-
server.close();
154+
await server.close();
155+
serverCompleter.complete();
142156
});
143157

144-
return completer.future;
158+
await serverCompleter.future;
159+
await clientCompleter.future;
145160
}
146161

147162
Future testNoCustomPortNoSourceAddress(
@@ -152,13 +167,13 @@ Future testNoCustomPortNoSourceAddress(
152167
Completer completer = new Completer();
153168
var server = await ServerSocket.bind(host, port);
154169
Socket.connect(host, port).then((clientSocket) {
155-
server.listen((client) {
170+
server.listen((client) async {
156171
Expect.equals(server.port, port);
157172
Expect.equals(client.remotePort, clientSocket.port);
158173
Expect.equals(client.address.address, expectedAddress);
159174
clientSocket.destroy();
160175
client.destroy();
161-
server.close();
176+
await server.close();
162177
completer.complete();
163178
});
164179
});

0 commit comments

Comments
 (0)