Skip to content

Commit ce31392

Browse files
authored
Retry commands that may time out fake server or the browser starts in tests. (#8638)
1 parent a0ac028 commit ce31392

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

pkg/pub_integration/lib/src/fake_pub_server_process.dart

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'dart:io';
88
import 'dart:math';
99

1010
import 'package:path/path.dart' as p;
11+
import 'package:retry/retry.dart';
1112

1213
final _random = Random.secure();
1314

@@ -100,12 +101,22 @@ class FakePubServerProcess {
100101

101102
await lockFile.create();
102103
try {
103-
final pr1 =
104-
await Process.run('dart', ['pub', 'get'], workingDirectory: appDir);
105-
if (pr1.exitCode != 0) {
106-
throw Exception(
107-
'dart pub get failed in app\n${pr1.stdout}\n${pr1.stderr}');
108-
}
104+
await retry(
105+
maxAttempts: 2,
106+
retryIf: (e) => e is TimeoutException,
107+
() async {
108+
final pr1 = await Process.run(
109+
'dart',
110+
['pub', 'get'],
111+
workingDirectory: appDir,
112+
).timeout(Duration(seconds: 15));
113+
114+
if (pr1.exitCode != 0) {
115+
throw Exception(
116+
'dart pub get failed in app\n${pr1.stdout}\n${pr1.stderr}');
117+
}
118+
},
119+
);
109120
} finally {
110121
await lockFile.delete();
111122
}

pkg/pub_integration/lib/src/test_browser.dart

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:async';
56
import 'dart:convert';
67
import 'dart:io';
78

89
import 'package:_pub_shared/validation/html/html_validation.dart';
910
import 'package:path/path.dart' as p;
1011
import 'package:puppeteer/puppeteer.dart';
12+
import 'package:retry/retry.dart';
1113

1214
import 'screenshot_utils.dart';
1315

@@ -49,10 +51,19 @@ class TestBrowser {
4951
];
5052

5153
for (final binary in binaries) {
52-
if (File(binary).existsSync()) {
54+
if (!File(binary).existsSync()) {
55+
continue;
56+
}
57+
try {
5358
// Get the local chrome's main version
54-
final pr = await Process.run(binary, ['--version'])
55-
.timeout(Duration(seconds: 5));
59+
final pr = await retry(
60+
maxAttempts: 2,
61+
retryIf: (e) => e is TimeoutException,
62+
() async {
63+
return await Process.run(binary, ['--version'])
64+
.timeout(Duration(seconds: 5));
65+
},
66+
);
5667
final output = pr.stdout.toString();
5768
final mainVersion = output
5869
.split(' ')
@@ -67,6 +78,9 @@ class TestBrowser {
6778
if (mainVersion >= 132) continue;
6879

6980
return binary;
81+
} on TimeoutException catch (_) {
82+
print('Unable to detect chrome version with $binary');
83+
continue;
7084
}
7185
}
7286

pkg/pub_integration/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dependencies:
1313
path: ^1.8.0
1414
pub_semver: ^2.0.0
1515
puppeteer: 3.16.0
16+
retry: ^3.1.2
1617
oauth2: ^2.0.0
1718

1819
dev_dependencies:

0 commit comments

Comments
 (0)