Index: tests/standalone/io/socket_bind_test.dart |
diff --git a/tests/standalone/io/socket_bind_test.dart b/tests/standalone/io/socket_bind_test.dart |
index 084280db87edbc50c9e92f0b81b94ef14e7bf870..f701f0c806109cad0db7dfbdad65763f8baa8a3a 100644 |
--- a/tests/standalone/io/socket_bind_test.dart |
+++ b/tests/standalone/io/socket_bind_test.dart |
@@ -66,22 +66,22 @@ Future testBindDifferentAddresses(InternetAddress addr1, |
bool addr2V6Only) async { |
int freePort = await freeIPv4AndIPv6Port(); |
- asyncStart(); |
- return ServerSocket.bind( |
- addr1, freePort, v6Only: addr1V6Only, shared: false).then((socket) { |
+ var socket = await ServerSocket.bind( |
+ addr1, freePort, v6Only: addr1V6Only, shared: false); |
+ |
+ try { |
Expect.isTrue(socket.port > 0); |
- asyncStart(); |
- return ServerSocket.bind( |
- addr2, freePort, v6Only: addr2V6Only, shared: false).then((socket2) { |
+ var socket2 = await ServerSocket.bind( |
+ addr2, freePort, v6Only: addr2V6Only, shared: false); |
+ try { |
Expect.equals(socket.port, socket2.port); |
- |
- return Future.wait([ |
- socket.close().whenComplete(asyncEnd), |
- socket2.close().whenComplete(asyncEnd), |
- ]); |
- }); |
- }); |
+ } finally { |
+ await socket2.close(); |
+ } |
+ } finally { |
+ await socket.close(); |
+ } |
} |
testListenCloseListenClose(String host) async { |
@@ -120,16 +120,34 @@ Future<int> freeIPv4AndIPv6Port() async { |
return port; |
} |
+Future retry(Future fun(), {int maxCount: 10}) async { |
+ for (int i = 0; i < maxCount; i++) { |
+ try { |
+ // If there is no exception this will simply return, otherwise we keep |
+ // trying. |
+ return await fun(); |
+ } catch (_) {} |
+ print("Failed to execute test closure in attempt $i " |
+ "(${maxCount - i} retries left)."); |
+ } |
+ return await fun(); |
+} |
+ |
main() async { |
asyncStart(); |
- await testBindDifferentAddresses(InternetAddress.ANY_IP_V6, |
- InternetAddress.ANY_IP_V4, |
- true, |
- false); |
- await testBindDifferentAddresses(InternetAddress.ANY_IP_V4, |
- InternetAddress.ANY_IP_V6, |
- false, |
- true); |
+ |
+ await retry(() async { |
+ await testBindDifferentAddresses(InternetAddress.ANY_IP_V6, |
+ InternetAddress.ANY_IP_V4, |
+ true, |
+ false); |
+ }); |
+ await retry(() async { |
+ await testBindDifferentAddresses(InternetAddress.ANY_IP_V4, |
+ InternetAddress.ANY_IP_V6, |
+ false, |
+ true); |
+ }); |
for (var host in ['127.0.0.1', '::1']) { |
testBindShared(host, false); |