From 13beab1ecccf52993ae6bfcce4150fa4d3b734f2 Mon Sep 17 00:00:00 2001 From: Andrew Kolos Date: Wed, 1 May 2024 21:03:32 -0700 Subject: [PATCH] add verbose logging to select hot reload/hot restart tests (#147673) In service of https://github.com/flutter/flutter/issues/146879 and https://github.com/flutter/flutter/issues/145812. In these issues, we see what appears to be the flutter tool getting stuck somewhere during hot reload. It may help if we knew were exactly where we are getting stuck (preparing assets, writing them to device, etc.). This PR adds a new parameter to `FlutterTestDriver::run`, `verbose`. When verbose is set, `FlutterTestDriver` will run `flutter` with `--verbose` in its tests. Keep in mind that `FlutterTestDriver` only prints logs from `flutter` when a test fails, so this shouldn't spam the logs of passing tests. This PR sets the parameter when invoking the flaky tests from https://github.com/flutter/flutter/issues/146879 and #145812, so we should see more detailed logs in future flakes. While this is a low risk PR, you can verify the change by intentionally breaking hot reload code, clearing the cached tool binaries, and then running either of these tests. --- packages/flutter_tools/lib/src/devfs.dart | 1 + packages/flutter_tools/lib/src/resident_runner.dart | 1 + .../test/integration.shard/hot_reload_test.dart | 2 +- .../test/integration.shard/test_driver.dart | 9 ++++++++- .../integration.shard/vmservice_integration_test.dart | 2 +- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/flutter_tools/lib/src/devfs.dart b/packages/flutter_tools/lib/src/devfs.dart index 4027001eee3b..a38e9824d19d 100644 --- a/packages/flutter_tools/lib/src/devfs.dart +++ b/packages/flutter_tools/lib/src/devfs.dart @@ -732,6 +732,7 @@ class DevFS { return UpdateFSReport(); } + _logger.printTrace('Pending asset builds completed. Writing dirty entries.'); if (dirtyEntries.isNotEmpty) { await (devFSWriter ?? _httpWriter).write(dirtyEntries, _baseUri!, _httpWriter); } diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart index 1eea4d9c1795..18e0ef1714e4 100644 --- a/packages/flutter_tools/lib/src/resident_runner.dart +++ b/packages/flutter_tools/lib/src/resident_runner.dart @@ -573,6 +573,7 @@ class FlutterDevice { }) async { final Status devFSStatus = globals.logger.startProgress( 'Syncing files to device ${device!.name}...', + progressId: 'devFS.update', ); UpdateFSReport report; try { diff --git a/packages/flutter_tools/test/integration.shard/hot_reload_test.dart b/packages/flutter_tools/test/integration.shard/hot_reload_test.dart index 0d5f132f486c..1108c032cf43 100644 --- a/packages/flutter_tools/test/integration.shard/hot_reload_test.dart +++ b/packages/flutter_tools/test/integration.shard/hot_reload_test.dart @@ -81,7 +81,7 @@ void main() { }); testWithoutContext('hot restart works without error', () async { - await flutter.run(); + await flutter.run(verbose: true); await flutter.hotRestart(); }); diff --git a/packages/flutter_tools/test/integration.shard/test_driver.dart b/packages/flutter_tools/test/integration.shard/test_driver.dart index 6be229d2d5e9..e9d4f665092e 100644 --- a/packages/flutter_tools/test/integration.shard/test_driver.dart +++ b/packages/flutter_tools/test/integration.shard/test_driver.dart @@ -90,12 +90,13 @@ abstract class FlutterTestDriver { List arguments, { String? script, bool withDebugger = false, + bool verbose = false, }) async { final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter'); if (withDebugger) { arguments.add('--start-paused'); } - if (_printDebugOutputToStdOut) { + if (verbose || _printDebugOutputToStdOut) { arguments.add('--verbose'); } if (script != null) { @@ -509,6 +510,7 @@ class FlutterRunTestDriver extends FlutterTestDriver { bool expressionEvaluation = true, bool structuredErrors = false, bool serveObservatory = false, + bool verbose = false, String? script, List? additionalCommandArgs, }) async { @@ -538,6 +540,7 @@ class FlutterRunTestDriver extends FlutterTestDriver { startPaused: startPaused, pauseOnExceptions: pauseOnExceptions, script: script, + verbose: verbose, ); } @@ -578,6 +581,7 @@ class FlutterRunTestDriver extends FlutterTestDriver { bool withDebugger = false, bool startPaused = false, bool pauseOnExceptions = false, + bool verbose = false, int? attachPort, }) async { assert(!startPaused || withDebugger); @@ -585,6 +589,7 @@ class FlutterRunTestDriver extends FlutterTestDriver { args, script: script, withDebugger: withDebugger, + verbose: verbose, ); final Completer prematureExitGuard = Completer(); @@ -796,12 +801,14 @@ class FlutterTestTestDriver extends FlutterTestDriver { String? script, bool withDebugger = false, bool pauseOnExceptions = false, + bool verbose = false, Future Function()? beforeStart, }) async { await super._setupProcess( args, script: script, withDebugger: withDebugger, + verbose: verbose, ); // Stash the PID so that we can terminate the VM more reliably than using diff --git a/packages/flutter_tools/test/integration.shard/vmservice_integration_test.dart b/packages/flutter_tools/test/integration.shard/vmservice_integration_test.dart index 45a0e86ebd89..ab66ed3d46ca 100644 --- a/packages/flutter_tools/test/integration.shard/vmservice_integration_test.dart +++ b/packages/flutter_tools/test/integration.shard/vmservice_integration_test.dart @@ -25,7 +25,7 @@ void main() { await project.setUpIn(tempDir); flutter = FlutterRunTestDriver(tempDir); - await flutter.run(withDebugger: true); + await flutter.run(withDebugger: true, verbose: true); final int? port = flutter.vmServicePort; expect(port != null, true); vmService = await vmServiceConnectUri('ws://localhost:$port/ws');