Skip to content

Commit 5eaefe7

Browse files
aamCommit Queue
authored andcommitted
[io/win/test] Fix socket_udp_readwrite_test to make it more robust.
Fix the test so it works with multiple concurrent instances running. BUG=#56955 TEST=standalone/io/socket_udp_readwrite_test" Change-Id: I312c7a846e7ca7288dd6dae3c35abedaf9a50939 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391305 Reviewed-by: Siva Annamalai <[email protected]> Commit-Queue: Alexander Aprelev <[email protected]>
1 parent 2f89caf commit 5eaefe7

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

tests/standalone/io/socket_udp_readwrite_test.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,36 @@
44

55
// Test writing to unreachable udp socket doesn't cause problems.
66

7+
import 'dart:async';
78
import 'dart:typed_data';
89
import 'dart:io';
910

1011
import "package:expect/expect.dart";
1112

1213
main() async {
13-
var _socket = await RawDatagramSocket.bind(InternetAddress.anyIPv4, 9099);
14+
final _socket = await RawDatagramSocket.bind(InternetAddress.anyIPv4, 0);
15+
final port = _socket.port;
16+
final allDone = Completer<bool>()
17+
..future.whenComplete(() { _socket.close(); });
1418
_socket.listen((RawSocketEvent event) {
1519
print("event: $event");
1620
switch (event) {
1721
case RawSocketEvent.read:
18-
Datagram? d = _socket.receive();
19-
if (d != null) {
20-
print("recv: $d, all done");
21-
_socket.close();
22-
}
22+
_socket.receive();
2323
break;
2424
case RawSocketEvent.write:
2525
print('received write event $event');
26+
allDone.complete(true);
2627
break;
2728
}
2829
}, onError: (e) {
2930
Expect.fail('Should be no exceptions, but got $e');
3031
});
3132

3233
for (int i = 0; i < 100; i++) {
33-
_socket.send(Uint8List(10), InternetAddress("127.0.0.1"), 9100);
34+
// Sending data to some non-existent reserved port to trigger
35+
// the condition.
36+
_socket.send(Uint8List(10), InternetAddress("127.0.0.1"), 1024);
3437
}
35-
_socket.send(Uint8List(10), InternetAddress("127.0.0.1"), 9099);
38+
_socket.send(Uint8List(10), InternetAddress("127.0.0.1"), port);
3639
}

0 commit comments

Comments
 (0)