| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 | 7 |
| 8 Future<int> freeIPv4AndIPv6Port() async { | 8 Future<int> freeIPv4AndIPv6Port() async { |
| 9 var socket = | 9 var socket = |
| 10 await ServerSocket.bind(InternetAddress.ANY_IP_V6, 0, v6Only: false); | 10 await ServerSocket.bind(InternetAddress.ANY_IP_V6, 0, v6Only: false); |
| 11 int port = socket.port; | 11 int port = socket.port; |
| 12 await socket.close(); | 12 await socket.close(); |
| 13 return port; | 13 return port; |
| 14 } | 14 } |
| 15 | 15 |
| 16 int lastRetryId = 0; | 16 int lastRetryId = 0; |
| 17 | 17 |
| 18 Future retry(Future fun(), {int maxCount: 10}) async { | 18 Future retry(Future fun(), {int maxCount: 10}) async { |
| 19 final int id = lastRetryId++; | 19 final int id = lastRetryId++; |
| 20 for (int i = 0; i < maxCount; i++) { | 20 for (int i = 0; i < maxCount; i++) { |
| 21 try { | 21 try { |
| 22 // If there is no exception this will simply return, otherwise we keep | 22 // If there is no exception this will simply return, otherwise we keep |
| 23 // trying. | 23 // trying. |
| 24 return await fun(); | 24 return await fun(); |
| 25 } catch (e, stack) { | 25 } catch (e, stack) { |
| 26 print("Failed to execute test closure (retry id: ${id}) in attempt $i " | 26 print("Failed to execute test closure (retry id: ${id}) in attempt $i " |
| 27 "(${maxCount - i} retries left)."); | 27 "(${maxCount - i} retries left)."); |
| 28 print("Exception: ${e}"); | 28 print("Exception: ${e}"); |
| 29 print("Stacktrace: ${stack}"); | 29 print("Stacktrace: ${stack}"); |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 return await fun(); | 32 return await fun(); |
| 33 } | 33 } |
| OLD | NEW |