Skip to content

Commit dc0f8ea

Browse files
authored
Fix hang after multiple precompiled browser tests (#2422)
Fixes #2294 Avoid creating extra unexpected BrowserManager instances by caching the future in the `_browserManagers` map without any async delay. Previously it was possible for two managers to be created if the second suite is loaded before the first suite's `compilerSupport` was resolved. This was not a problem for tests that get compiled by the test runner because the compilation would delay the second suite load until after the first suite's `compilerSupport` has resolved. It is not a problem when running without concurrency because that delays the second suite load. Add a concurrency argument to the regression test, otherwise the default is to run with concurrency 1 which works around the bug.
1 parent 2096773 commit dc0f8ea

File tree

6 files changed

+25
-13
lines changed

6 files changed

+25
-13
lines changed

pkgs/test/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.25.12
2+
3+
* Fix hang when running multiple precompiled browser tests.
4+
15
## 1.25.11
26

37
* Update to be forward compatible with `package:shelf_web_socket` version `3.x`.

pkgs/test/lib/src/runner/browser/platform.dart

+13-9
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,21 @@ class BrowserPlatform extends PlatformPlugin
211211
///
212212
/// If no browser manager is running yet, starts one.
213213
Future<BrowserManager?> _browserManagerFor(
214-
Runtime browser, Compiler compiler) async {
214+
Runtime browser, Compiler compiler) {
215215
var managerFuture = _browserManagers[(browser, compiler)];
216216
if (managerFuture != null) return managerFuture;
217217

218+
var future = _createBrowserManager(browser, compiler);
219+
// Store null values for browsers that error out so we know not to load them
220+
// again.
221+
_browserManagers[(browser, compiler)] =
222+
future.then<BrowserManager?>((value) => value).onError((_, __) => null);
223+
224+
return future;
225+
}
226+
227+
Future<BrowserManager> _createBrowserManager(
228+
Runtime browser, Compiler compiler) async {
218229
var support = await compilerSupport(compiler);
219230
var (webSocketUrl, socketFuture) = support.webSocket;
220231
var hostUrl = support.serverUrl
@@ -224,15 +235,8 @@ class BrowserPlatform extends PlatformPlugin
224235
'debug': _config.debug.toString()
225236
});
226237

227-
var future = BrowserManager.start(
238+
return BrowserManager.start(
228239
browser, hostUrl, socketFuture, _browserSettings[browser]!, _config);
229-
230-
// Store null values for browsers that error out so we know not to load them
231-
// again.
232-
_browserManagers[(browser, compiler)] =
233-
future.then<BrowserManager?>((value) => value).onError((_, __) => null);
234-
235-
return future;
236240
}
237241

238242
/// Close all the browsers that the server currently has open.

pkgs/test/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: test
2-
version: 1.25.11
2+
version: 1.25.12
33
description: >-
44
A full featured library for writing and running Dart tests across platforms.
55
repository: https://github.com/dart-lang/test/tree/master/pkgs/test
@@ -36,7 +36,7 @@ dependencies:
3636

3737
# Use an exact version until the test_api and test_core package are stable.
3838
test_api: 0.7.4
39-
test_core: 0.6.7
39+
test_core: 0.6.8
4040

4141
typed_data: ^1.3.0
4242
web_socket_channel: '>=2.0.0 <4.0.0'

pkgs/test/test/runner/precompiled_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void main() {
4242

4343
test('run two precompiled tests', () async {
4444
await _precompileBrowserTest('test_2.dart');
45-
var test = await runTest([
45+
var test = await runTest(concurrency: 2, [
4646
'-p',
4747
'chrome',
4848
'--precompiled=precompiled/',

pkgs/test_core/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.6.8
2+
3+
* Fix hang when running multiple precompiled browser tests.
4+
15
## 0.6.7
26

37
* Update the `package:vm_service` constraint to allow version `15.x`.

pkgs/test_core/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: test_core
2-
version: 0.6.7
2+
version: 0.6.8
33
description: A basic library for writing tests and running them on the VM.
44
repository: https://github.com/dart-lang/test/tree/master/pkgs/test_core
55
resolution: workspace

0 commit comments

Comments
 (0)