diff --git a/dev/devicelab/lib/framework/runner.dart b/dev/devicelab/lib/framework/runner.dart index fde70ea599..8e511eefde 100644 --- a/dev/devicelab/lib/framework/runner.dart +++ b/dev/devicelab/lib/framework/runner.dart @@ -40,20 +40,12 @@ Future> runTask( bool runnerFinished = false; - final Completer uri = Completer(); - runner.exitCode.whenComplete(() { - if (!uri.isCompleted) { - // The runner process exited prematurely. - uri.completeError(Exception( - 'The task runner process exited before opening a VM service connection. ' - 'A common cause for this is when a task script does not actually create ' - 'a task.', - )); - } runnerFinished = true; }); + final Completer uri = Completer(); + final StreamSubscription stdoutSub = runner.stdout .transform(const Utf8Decoder()) .transform(const LineSplitter()) @@ -76,7 +68,7 @@ Future> runTask( }); try { - final VMIsolateRef isolate = await _connectToRunnerIsolate(await uri.future, () => !runnerFinished); + final VMIsolateRef isolate = await _connectToRunnerIsolate(await uri.future); final Map taskResult = await isolate.invokeExtension('ext.cocoonRunTask') as Map; await runner.exitCode; return taskResult; @@ -89,7 +81,7 @@ Future> runTask( } } -Future _connectToRunnerIsolate(Uri vmServiceUri, bool Function() keepTrying) async { +Future _connectToRunnerIsolate(Uri vmServiceUri) async { final List pathSegments = [ // Add authentication code. if (vmServiceUri.pathSegments.isNotEmpty) vmServiceUri.pathSegments[0], @@ -99,7 +91,7 @@ Future _connectToRunnerIsolate(Uri vmServiceUri, bool Function() k pathSegments).toString(); final Stopwatch stopwatch = Stopwatch()..start(); - while (keepTrying()) { + while (true) { try { // Make sure VM server is up by successfully opening and closing a socket. await (await WebSocket.connect(url)).close(); @@ -118,8 +110,6 @@ Future _connectToRunnerIsolate(Uri vmServiceUri, bool Function() k await Future.delayed(const Duration(milliseconds: 50)); } } - - throw Exception('Failed to connect to Dart VM service.'); } Future cleanupSystem() async { diff --git a/dev/devicelab/test/run_test.dart b/dev/devicelab/test/run_test.dart index c212ee51c6..00c5cbd6c9 100644 --- a/dev/devicelab/test/run_test.dart +++ b/dev/devicelab/test/run_test.dart @@ -24,43 +24,43 @@ void main() { return scriptProcess; } - Future expectScriptResult(List testNames, { bool expectSuccess }) async { + Future expectScriptResult(List testNames, int expectedExitCode) async { final ProcessResult result = await runScript(testNames); - expect(result.exitCode, expectSuccess ? 0 : isNot(equals(0)), + expect(result.exitCode, expectedExitCode, reason: '[ stderr from test process ]\n\n${result.stderr}\n\n[ end of stderr ]' '\n\n[ stdout from test process ]\n\n${result.stdout}\n\n[ end of stdout ]'); } test('exits with code 0 when succeeds', () async { - await expectScriptResult(['smoke_test_success'], expectSuccess: true); + await expectScriptResult(['smoke_test_success'], 0); }); test('accepts file paths', () async { - await expectScriptResult(['bin/tasks/smoke_test_success.dart'], expectSuccess: true); + await expectScriptResult(['bin/tasks/smoke_test_success.dart'], 0); }); test('rejects invalid file paths', () async { - await expectScriptResult(['lib/framework/adb.dart'], expectSuccess: false); + await expectScriptResult(['lib/framework/adb.dart'], 1); }); test('exits with code 1 when task throws', () async { - await expectScriptResult(['smoke_test_throws'], expectSuccess: false); + await expectScriptResult(['smoke_test_throws'], 1); }); test('exits with code 1 when fails', () async { - await expectScriptResult(['smoke_test_failure'], expectSuccess: false); + await expectScriptResult(['smoke_test_failure'], 1); }); test('exits with code 1 when fails to connect', () async { - await expectScriptResult(['smoke_test_setup_failure'], expectSuccess: false); - }); + await expectScriptResult(['smoke_test_setup_failure'], 1); + }, skip: true); // https://github.com/flutter/flutter/issues/53707 test('exits with code 1 when results are mixed', () async { await expectScriptResult([ 'smoke_test_failure', 'smoke_test_success', ], - expectSuccess: false, + 1, ); }); });