Ensure dart_plugin_registry shows stderr and exits when process exits (#99936)
This commit is contained in:
parent
f2646b1589
commit
cd725e3640
@ -142,36 +142,69 @@ class ApluginPlatformInterfaceMacOS {
|
|||||||
|
|
||||||
section('Flutter run for macos');
|
section('Flutter run for macos');
|
||||||
|
|
||||||
|
late Process run;
|
||||||
await inDirectory(path.join(tempDir.path, 'app'), () async {
|
await inDirectory(path.join(tempDir.path, 'app'), () async {
|
||||||
final Process run = await startProcess(
|
run = await startProcess(
|
||||||
path.join(flutterDirectory.path, 'bin', 'flutter'),
|
path.join(flutterDirectory.path, 'bin', 'flutter'),
|
||||||
flutterCommandArgs('run', <String>['-d', 'macos', '-v']),
|
flutterCommandArgs('run', <String>['-d', 'macos', '-v']),
|
||||||
);
|
);
|
||||||
Completer<void> registryExecutedCompleter = Completer<void>();
|
});
|
||||||
final StreamSubscription<void> subscription = run.stdout
|
|
||||||
.transform<String>(utf8.decoder)
|
Completer<void> registryExecutedCompleter = Completer<void>();
|
||||||
.transform<String>(const LineSplitter())
|
final StreamSubscription<void> stdoutSub = run.stdout
|
||||||
.listen((String line) {
|
.transform<String>(utf8.decoder)
|
||||||
if (line.contains(
|
.transform<String>(const LineSplitter())
|
||||||
'ApluginPlatformInterfaceMacOS.registerWith() was called')) {
|
.listen((String line) {
|
||||||
|
if (line.contains('ApluginPlatformInterfaceMacOS.registerWith() was called')) {
|
||||||
registryExecutedCompleter.complete();
|
registryExecutedCompleter.complete();
|
||||||
}
|
}
|
||||||
print('stdout: $line');
|
print('stdout: $line');
|
||||||
});
|
});
|
||||||
|
|
||||||
section('Wait for registry execution');
|
final StreamSubscription<void> stderrSub = run.stderr
|
||||||
await registryExecutedCompleter.future;
|
.transform<String>(utf8.decoder)
|
||||||
|
.transform<String>(const LineSplitter())
|
||||||
|
.listen((String line) {
|
||||||
|
print('stderr: $line');
|
||||||
|
});
|
||||||
|
|
||||||
// Hot restart.
|
final Future<void> stdoutDone = stdoutSub.asFuture<void>();
|
||||||
run.stdin.write('R');
|
final Future<void> stderrDone = stderrSub.asFuture<void>();
|
||||||
registryExecutedCompleter = Completer<void>();
|
|
||||||
|
|
||||||
section('Wait for registry execution after hot restart');
|
Future<void> waitForStreams() {
|
||||||
await registryExecutedCompleter.future;
|
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);
|
return TaskResult.success(null);
|
||||||
} finally {
|
} finally {
|
||||||
rmTree(tempDir);
|
rmTree(tempDir);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user