| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 import 'dart:convert'; | |
| 8 | 7 |
| 9 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
| 10 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
| 11 | 10 |
| 11 import 'test_utils.dart' show freeIPv4AndIPv6Port; |
| 12 |
| 12 testBindShared(String host, bool v6Only) { | 13 testBindShared(String host, bool v6Only) { |
| 13 asyncStart(); | 14 asyncStart(); |
| 14 ServerSocket.bind( | 15 ServerSocket.bind( |
| 15 host, 0, v6Only: v6Only, shared: true).then((socket) { | 16 host, 0, v6Only: v6Only, shared: true).then((socket) { |
| 16 Expect.isTrue(socket.port > 0); | 17 Expect.isTrue(socket.port > 0); |
| 17 | 18 |
| 18 asyncStart(); | 19 asyncStart(); |
| 19 return ServerSocket.bind( | 20 return ServerSocket.bind( |
| 20 host, socket.port, v6Only: v6Only, shared: true).then((socket2) { | 21 host, socket.port, v6Only: v6Only, shared: true).then((socket2) { |
| 21 Expect.equals(socket.address.address, socket2.address.address); | 22 Expect.equals(socket.address.address, socket2.address.address); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 asyncEnd(); | 106 asyncEnd(); |
| 106 }); | 107 }); |
| 107 | 108 |
| 108 Socket client = await Socket.connect(host, socket2.port); | 109 Socket client = await Socket.connect(host, socket2.port); |
| 109 await client.close(); | 110 await client.close(); |
| 110 await client.drain(); | 111 await client.drain(); |
| 111 | 112 |
| 112 asyncEnd(); | 113 asyncEnd(); |
| 113 } | 114 } |
| 114 | 115 |
| 115 Future<int> freeIPv4AndIPv6Port() async { | |
| 116 var socket = | |
| 117 await ServerSocket.bind(InternetAddress.ANY_IP_V6, 0, v6Only: false); | |
| 118 int port = socket.port; | |
| 119 await socket.close(); | |
| 120 return port; | |
| 121 } | |
| 122 | |
| 123 Future retry(Future fun(), {int maxCount: 10}) async { | 116 Future retry(Future fun(), {int maxCount: 10}) async { |
| 124 for (int i = 0; i < maxCount; i++) { | 117 for (int i = 0; i < maxCount; i++) { |
| 125 try { | 118 try { |
| 126 // If there is no exception this will simply return, otherwise we keep | 119 // If there is no exception this will simply return, otherwise we keep |
| 127 // trying. | 120 // trying. |
| 128 return await fun(); | 121 return await fun(); |
| 129 } catch (_) {} | 122 } catch (_) {} |
| 130 print("Failed to execute test closure in attempt $i " | 123 print("Failed to execute test closure in attempt $i " |
| 131 "(${maxCount - i} retries left)."); | 124 "(${maxCount - i} retries left)."); |
| 132 } | 125 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 156 negTestBindSharedMismatch(host, false); | 149 negTestBindSharedMismatch(host, false); |
| 157 negTestBindSharedMismatch(host, true); | 150 negTestBindSharedMismatch(host, true); |
| 158 | 151 |
| 159 negTestBindV6OnlyMismatch(host, true); | 152 negTestBindV6OnlyMismatch(host, true); |
| 160 negTestBindV6OnlyMismatch(host, false); | 153 negTestBindV6OnlyMismatch(host, false); |
| 161 | 154 |
| 162 testListenCloseListenClose(host); | 155 testListenCloseListenClose(host); |
| 163 } | 156 } |
| 164 asyncEnd(); | 157 asyncEnd(); |
| 165 } | 158 } |
| OLD | NEW |