[flutter_tools] Fix hang in DesktopLogReader (#88178)

This commit is contained in:
Zachary Anderson
2021-08-13 17:12:04 -07:00
committed by GitHub
parent 325cfb0f4c
commit c5d5463c30
2 changed files with 11 additions and 16 deletions

View File

@@ -314,15 +314,15 @@ class DesktopLogReader extends DeviceLogReader {
final StreamSubscription<List<int>> stderrSub = process.stderr.listen(
_inputController.add,
);
final Future<void> stdioFuture = Future.wait<void>(<Future<void>>[
stdoutSub.asFuture<void>(),
stderrSub.asFuture<void>(),
]);
process.exitCode.whenComplete(() async {
// Wait for output to be fully processed.
await Future.wait<void>(<Future<void>>[
stdoutSub.asFuture<void>(),
stderrSub.asFuture<void>(),
]);
// The streams as futures have already completed, so waiting for the
// potentially async stream cancellation to complete likely has no
// benefit.
await stdioFuture;
// The streams have already completed, so waiting for the stream
// cancellation to complete is not needed.
unawaited(stdoutSub.cancel());
unawaited(stderrSub.cancel());
await _inputController.close();

View File

@@ -289,17 +289,13 @@ void main() {
final FakeDesktopDevice device = setUpDesktopDevice(
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>(() {
exitCompleter.complete();
}));
// Start looking for 'Oops' in the stream before starting the app.
expect(device.getLogReader().logLines, emits('Oops'));
final FakeApplicationPackage package = FakeApplicationPackage();
await device.startApp(
package,
@@ -309,7 +305,6 @@ void main() {
dartEntrypointArgs: <String>['arg1', 'arg2'],
),
);
await testCompleter.future;
});
}