diff --git a/packages/devtools_app/integration_test/run_tests.dart b/packages/devtools_app/integration_test/run_tests.dart index 6ad9dc320b5..e316a2f3a45 100644 --- a/packages/devtools_app/integration_test/run_tests.dart +++ b/packages/devtools_app/integration_test/run_tests.dart @@ -25,13 +25,12 @@ void main(List args) async { return; } - Exception? exception; final chromedriver = ChromeDriver(); - // Start chrome driver before running the flutter integration test. - await chromedriver.start(); - try { + // Start chrome driver before running the flutter integration test. + await chromedriver.start(); + if (testRunnerArgs.testTarget != null) { // TODO(kenz): add support for specifying a directory as the target instead // of a single file. @@ -52,15 +51,9 @@ void main(List args) async { await _runTest(newArgsWithTarget); } } - } on Exception catch (e) { - exception = e; } finally { await chromedriver.stop(); } - - if (exception != null) { - throw exception; - } } Future _runTest( diff --git a/packages/devtools_app/integration_test/test_infra/run/_chrome_driver.dart b/packages/devtools_app/integration_test/test_infra/run/_chrome_driver.dart index 1cf11dcc1e3..52a7a708da1 100644 --- a/packages/devtools_app/integration_test/test_infra/run/_chrome_driver.dart +++ b/packages/devtools_app/integration_test/test_infra/run/_chrome_driver.dart @@ -8,7 +8,7 @@ import '_io_utils.dart'; import '_utils.dart'; class ChromeDriver with IOMixin { - late final Process _process; + Process? _process; // TODO(kenz): add error messaging if the chromedriver executable is not // found. We can also consider using web installers directly in this script: @@ -16,13 +16,13 @@ class ChromeDriver with IOMixin { Future start() async { try { debugLog('starting the chromedriver process'); - _process = await Process.start( + final process = _process = await Process.start( 'chromedriver', [ '--port=4444', ], ); - listenToProcessOutput(_process, printTag: 'ChromeDriver'); + listenToProcessOutput(process, printTag: 'ChromeDriver'); } catch (e) { // ignore: avoid-throw-in-catch-block, by design throw Exception('Error starting chromedriver: $e'); @@ -30,8 +30,13 @@ class ChromeDriver with IOMixin { } Future stop() async { + final process = _process; + _process = null; + + if (process == null) return; + await cancelAllStreamSubscriptions(); debugLog('killing the chromedriver process'); - await killGracefully(_process); + await killGracefully(process); } }