diff --git a/dev/devicelab/lib/tasks/dart_plugin_registry_tests.dart b/dev/devicelab/lib/tasks/dart_plugin_registry_tests.dart index 27841c6216..d955bc913b 100644 --- a/dev/devicelab/lib/tasks/dart_plugin_registry_tests.dart +++ b/dev/devicelab/lib/tasks/dart_plugin_registry_tests.dart @@ -142,36 +142,69 @@ class ApluginPlatformInterfaceMacOS { section('Flutter run for macos'); + late Process run; await inDirectory(path.join(tempDir.path, 'app'), () async { - final Process run = await startProcess( + run = await startProcess( path.join(flutterDirectory.path, 'bin', 'flutter'), flutterCommandArgs('run', ['-d', 'macos', '-v']), ); - Completer registryExecutedCompleter = Completer(); - final StreamSubscription subscription = run.stdout - .transform(utf8.decoder) - .transform(const LineSplitter()) - .listen((String line) { - if (line.contains( - 'ApluginPlatformInterfaceMacOS.registerWith() was called')) { + }); + + Completer registryExecutedCompleter = Completer(); + final StreamSubscription stdoutSub = run.stdout + .transform(utf8.decoder) + .transform(const LineSplitter()) + .listen((String line) { + if (line.contains('ApluginPlatformInterfaceMacOS.registerWith() was called')) { registryExecutedCompleter.complete(); } print('stdout: $line'); }); - section('Wait for registry execution'); - await registryExecutedCompleter.future; + final StreamSubscription stderrSub = run.stderr + .transform(utf8.decoder) + .transform(const LineSplitter()) + .listen((String line) { + print('stderr: $line'); + }); - // Hot restart. - run.stdin.write('R'); - registryExecutedCompleter = Completer(); + final Future stdoutDone = stdoutSub.asFuture(); + final Future stderrDone = stderrSub.asFuture(); - section('Wait for registry execution after hot restart'); - await registryExecutedCompleter.future; + Future waitForStreams() { + return Future.wait(>[stdoutDone, stderrDone]); + } + + Future waitOrExit(Future future) async { + final dynamic result = await Future.any( + >[ + future, + run.exitCode, + ], + ); + if (result is int) { + await waitForStreams(); + throw 'process exited with code $result'; + } + } + + section('Wait for registry execution'); + await waitOrExit(registryExecutedCompleter.future); + + // Hot restart. + run.stdin.write('R'); + registryExecutedCompleter = Completer(); + + section('Wait for registry execution after hot restart'); + await waitOrExit(registryExecutedCompleter.future); + + run.kill(); + + await waitForStreams(); + + unawaited(stdoutSub.cancel()); + unawaited(stderrSub.cancel()); - unawaited(subscription.cancel()); - run.kill(); - }); return TaskResult.success(null); } finally { rmTree(tempDir);