From 4c8b0a3873b52613b99c079587eb85f7bde9a3e1 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Sun, 22 Dec 2024 02:32:02 +0000 Subject: [PATCH] [flutter_tool] Change the startup message for the "flutter daemon" command (#160444) There have been some reports of the Flutter daemon not starting up properly (for ex. https://github.com/flutter/flutter/issues/143625), but it turns out that when starting successfully, it just prints "Starting device daemon..." and then nothing more. This is confusing and can lead users to think other issues are because the daemon hasn't started properly. There's not a great hook to print that this "finished" starting up (because it does async polling in the background), so I just updated the message of the text and moved it to after the creation of the daemon. Fixes https://github.com/flutter/flutter/issues/143625 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [N/A] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Andrew Kolos --- .../lib/src/commands/daemon.dart | 2 +- .../integration.shard/daemon_mode_test.dart | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index d10597b0d5..a39ae6b5ba 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart @@ -86,7 +86,6 @@ class DaemonCommand extends FlutterCommand { ).run(); return FlutterCommandResult.success(); } - globals.printStatus('Starting device daemon...'); final Daemon daemon = Daemon( DaemonConnection( daemonStreams: DaemonStreams.fromStdio(globals.stdio, logger: globals.logger), @@ -94,6 +93,7 @@ class DaemonCommand extends FlutterCommand { ), notifyingLogger: asLogger(globals.logger), ); + globals.printStatus('Device daemon started.'); final int code = await daemon.onExit; if (code != 0) { throwToolExit('Daemon exited with non-zero exit code: $code', exitCode: code); diff --git a/packages/flutter_tools/test/integration.shard/daemon_mode_test.dart b/packages/flutter_tools/test/integration.shard/daemon_mode_test.dart index 533c63f467..b587154528 100644 --- a/packages/flutter_tools/test/integration.shard/daemon_mode_test.dart +++ b/packages/flutter_tools/test/integration.shard/daemon_mode_test.dart @@ -27,6 +27,42 @@ void main() { daemonProcess.kill(); }); + testWithoutContext('startup events', () async { + final BasicProject project = BasicProject(); + await project.setUpIn(tempDir); + + const ProcessManager processManager = LocalProcessManager(); + daemonProcess = await processManager.start( + [flutterBin, ...getLocalEngineArguments(), '--show-test-device', 'daemon'], + workingDirectory: tempDir.path, + ); + + final StreamController stdout = StreamController.broadcast(); + transformToLines(daemonProcess.stdout).listen((String line) => stdout.add(line)); + final Stream> stream = + stdout.stream + .map?>(parseFlutterResponse) + .where((Map? value) => value != null) + .cast>(); + + final [ + Map connectedEvent, + Map logMessage, + ] = await Future.wait(>>[ + stream.firstWhere((Map e) => e['event'] == 'daemon.connected'), + stream.firstWhere((Map e) => e['event'] == 'daemon.logMessage'), + ]); + + // Check the connected message has a version. + final Map connectedParams = connectedEvent['params']! as Map; + expect(connectedParams['version'], isNotNull); + + // Check we got the startup message. + final Map logParams = logMessage['params']! as Map; + expect(logParams['level'], 'status'); + expect(logParams['message'], 'Device daemon started.'); + }); + testWithoutContext('device.getDevices', () async { final BasicProject project = BasicProject(); await project.setUpIn(tempDir);