Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: tests/standalone/io/socket_bind_test.dart

Issue 2546733002: Attempt to reduce flakiness rate of io test (Closed)
Patch Set: add retrying of tests Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/standalone/io/socket_source_address_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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, retry;
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
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 {
124 for (int i = 0; i < maxCount; i++) {
125 try {
126 // If there is no exception this will simply return, otherwise we keep
127 // trying.
128 return await fun();
129 } catch (_) {}
130 print("Failed to execute test closure in attempt $i "
131 "(${maxCount - i} retries left).");
132 }
133 return await fun();
134 }
135
136 main() async { 116 main() async {
137 asyncStart(); 117 asyncStart();
138 118
139 await retry(() async { 119 await retry(() async {
140 await testBindDifferentAddresses(InternetAddress.ANY_IP_V6, 120 await testBindDifferentAddresses(InternetAddress.ANY_IP_V6,
141 InternetAddress.ANY_IP_V4, 121 InternetAddress.ANY_IP_V4,
142 true, 122 true,
143 false); 123 false);
144 }); 124 });
145 await retry(() async { 125 await retry(() async {
(...skipping 10 matching lines...) Expand all
156 negTestBindSharedMismatch(host, false); 136 negTestBindSharedMismatch(host, false);
157 negTestBindSharedMismatch(host, true); 137 negTestBindSharedMismatch(host, true);
158 138
159 negTestBindV6OnlyMismatch(host, true); 139 negTestBindV6OnlyMismatch(host, true);
160 negTestBindV6OnlyMismatch(host, false); 140 negTestBindV6OnlyMismatch(host, false);
161 141
162 testListenCloseListenClose(host); 142 testListenCloseListenClose(host);
163 } 143 }
164 asyncEnd(); 144 asyncEnd();
165 } 145 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/socket_source_address_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698