diff --git a/packages/flutter_tools/lib/src/desktop_device.dart b/packages/flutter_tools/lib/src/desktop_device.dart index 960b14122e..544fb28180 100644 --- a/packages/flutter_tools/lib/src/desktop_device.dart +++ b/packages/flutter_tools/lib/src/desktop_device.dart @@ -314,15 +314,15 @@ class DesktopLogReader extends DeviceLogReader { final StreamSubscription> stderrSub = process.stderr.listen( _inputController.add, ); + final Future stdioFuture = Future.wait(>[ + stdoutSub.asFuture(), + stderrSub.asFuture(), + ]); process.exitCode.whenComplete(() async { // Wait for output to be fully processed. - await Future.wait(>[ - stdoutSub.asFuture(), - stderrSub.asFuture(), - ]); - // 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(); diff --git a/packages/flutter_tools/test/general.shard/desktop_device_test.dart b/packages/flutter_tools/test/general.shard/desktop_device_test.dart index 96ae339a2e..33418bde28 100644 --- a/packages/flutter_tools/test/general.shard/desktop_device_test.dart +++ b/packages/flutter_tools/test/general.shard/desktop_device_test.dart @@ -289,17 +289,13 @@ void main() { final FakeDesktopDevice device = setUpDesktopDevice( processManager: processManager, ); - final Completer testCompleter = Completer(); - final List logOutput = []; - device.getLogReader().logLines.listen((String line) { - logOutput.add(line); - }, onDone: () { - expect(logOutput, contains('Oops')); - testCompleter.complete(); - }); unawaited(Future(() { 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: ['arg1', 'arg2'], ), ); - await testCompleter.future; }); }