Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some retry around browser launching #1676

Merged
merged 5 commits into from Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pkgs/test/CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@

* Drop `dart2js-path` command line argument.
* Allow loading tests under a path with the directory named `packages`.
* Add retry for launching browsers. Reduce timeout back to 30 seconds.

## 1.20.1

Expand Down
23 changes: 18 additions & 5 deletions pkgs/test/lib/src/runner/browser/browser_manager.dart
Expand Up @@ -98,11 +98,21 @@ class BrowserManager {
/// Returns the browser manager, or throws an [ApplicationException] if a
/// connection fails to be established.
static Future<BrowserManager> start(
Runtime runtime,
Uri url,
Future<WebSocketChannel> future,
ExecutableSettings settings,
Configuration configuration) =>
_start(runtime, url, future, settings, configuration, 1);

static const _maxRetries = 3;
static Future<BrowserManager> _start(
Runtime runtime,
Uri url,
Future<WebSocketChannel> future,
ExecutableSettings settings,
Configuration configuration) {
Configuration configuration,
int attempt) {
var browser = _newBrowser(url, runtime, settings, configuration);

var completer = Completer<BrowserManager>();
Expand All @@ -127,11 +137,14 @@ class BrowserManager {
completer.completeError(error, stackTrace);
});

return completer.future.timeout(Duration(seconds: 45), onTimeout: () {
return completer.future.timeout(Duration(seconds: 30), onTimeout: () {
browser.close();
throw ApplicationException(
'Timed out waiting for ${runtime.name} to connect.\n'
'Browser output: ${utf8.decode(browser.output)}');
if (attempt >= _maxRetries) {
throw ApplicationException(
'Timed out waiting for ${runtime.name} to connect.\n'
'Browser output: ${utf8.decode(browser.output)}');
}
return _start(runtime, url, future, settings, configuration, attempt++);
natebosch marked this conversation as resolved.
Show resolved Hide resolved
});
}

Expand Down