Unverified Commit c5d5463c authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[flutter_tools] Fix hang in DesktopLogReader (#88178)

parent 325cfb0f
...@@ -314,15 +314,15 @@ class DesktopLogReader extends DeviceLogReader { ...@@ -314,15 +314,15 @@ class DesktopLogReader extends DeviceLogReader {
final StreamSubscription<List<int>> stderrSub = process.stderr.listen( final StreamSubscription<List<int>> stderrSub = process.stderr.listen(
_inputController.add, _inputController.add,
); );
process.exitCode.whenComplete(() async { final Future<void> stdioFuture = Future.wait<void>(<Future<void>>[
// Wait for output to be fully processed.
await Future.wait<void>(<Future<void>>[
stdoutSub.asFuture<void>(), stdoutSub.asFuture<void>(),
stderrSub.asFuture<void>(), stderrSub.asFuture<void>(),
]); ]);
// The streams as futures have already completed, so waiting for the process.exitCode.whenComplete(() async {
// potentially async stream cancellation to complete likely has no // Wait for output to be fully processed.
// benefit. await stdioFuture;
// The streams have already completed, so waiting for the stream
// cancellation to complete is not needed.
unawaited(stdoutSub.cancel()); unawaited(stdoutSub.cancel());
unawaited(stderrSub.cancel()); unawaited(stderrSub.cancel());
await _inputController.close(); await _inputController.close();
......
...@@ -289,17 +289,13 @@ void main() { ...@@ -289,17 +289,13 @@ void main() {
final FakeDesktopDevice device = setUpDesktopDevice( final FakeDesktopDevice device = setUpDesktopDevice(
processManager: processManager, processManager: processManager,
); );
final Completer<void> testCompleter = Completer<void>();
final List<String> logOutput = <String>[];
device.getLogReader().logLines.listen((String line) {
logOutput.add(line);
}, onDone: () {
expect(logOutput, contains('Oops'));
testCompleter.complete();
});
unawaited(Future<void>(() { unawaited(Future<void>(() {
exitCompleter.complete(); exitCompleter.complete();
})); }));
// Start looking for 'Oops' in the stream before starting the app.
expect(device.getLogReader().logLines, emits('Oops'));
final FakeApplicationPackage package = FakeApplicationPackage(); final FakeApplicationPackage package = FakeApplicationPackage();
await device.startApp( await device.startApp(
package, package,
...@@ -309,7 +305,6 @@ void main() { ...@@ -309,7 +305,6 @@ void main() {
dartEntrypointArgs: <String>['arg1', 'arg2'], dartEntrypointArgs: <String>['arg1', 'arg2'],
), ),
); );
await testCompleter.future;
}); });
} }
......
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