[flutter_tools] Fix hang in DesktopLogReader (#88178)
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user