Unverified Commit cd725e36 authored by Emmanuel Garcia's avatar Emmanuel Garcia Committed by GitHub

Ensure dart_plugin_registry shows stderr and exits when process exits (#99936)

parent f2646b15
......@@ -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', <String>['-d', 'macos', '-v']),
);
Completer<void> registryExecutedCompleter = Completer<void>();
final StreamSubscription<void> subscription = run.stdout
.transform<String>(utf8.decoder)
.transform<String>(const LineSplitter())
.listen((String line) {
if (line.contains(
'ApluginPlatformInterfaceMacOS.registerWith() was called')) {
});
Completer<void> registryExecutedCompleter = Completer<void>();
final StreamSubscription<void> stdoutSub = run.stdout
.transform<String>(utf8.decoder)
.transform<String>(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<void> stderrSub = run.stderr
.transform<String>(utf8.decoder)
.transform<String>(const LineSplitter())
.listen((String line) {
print('stderr: $line');
});
// Hot restart.
run.stdin.write('R');
registryExecutedCompleter = Completer<void>();
final Future<void> stdoutDone = stdoutSub.asFuture<void>();
final Future<void> stderrDone = stderrSub.asFuture<void>();
section('Wait for registry execution after hot restart');
await registryExecutedCompleter.future;
Future<void> waitForStreams() {
return Future.wait<void>(<Future<void>>[stdoutDone, stderrDone]);
}
Future<void> waitOrExit(Future<void> future) async {
final dynamic result = await Future.any<dynamic>(
<Future<dynamic>>[
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<void>();
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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment