From 7292c94bac6875e6e178fcdefd8313998746e745 Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Mon, 24 Jun 2024 14:38:27 -0400 Subject: [PATCH] Update android_device.dart to have clearLogs not print to standard error (#150197) Even though this does not fix the below issue lets land this anyway as not logging to stderr when clearing logs makes sense to me. related https://github.com/flutter/flutter/issues/150093 The test added is bad. It does not verify the behavior changed. To verify the behavior changed correctly I would need to modify the generic device class to have clearLogs be an async function like many of the other calls. That would mean modifying every other device type and their implementations and their tests. Then I would need to update android_device to expose its logger. That is more than I have time for to validate a 2% flake error. Feel free to disagree in the comments on this pr. --- .../lib/src/android/android_device.dart | 7 ++++++- .../general.shard/android/android_device_test.dart | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/android/android_device.dart b/packages/flutter_tools/lib/src/android/android_device.dart index 1715f655a9..51ae79a348 100644 --- a/packages/flutter_tools/lib/src/android/android_device.dart +++ b/packages/flutter_tools/lib/src/android/android_device.dart @@ -778,7 +778,12 @@ class AndroidDevice extends Device { @override void clearLogs() { - _processUtils.runSync(adbCommandForDevice(['logcat', '-c'])); + final RunResult result = _processUtils.runSync(adbCommandForDevice(['logcat', '-c'])); + // Do not log to standard error because that causes test to fail. + if (result.exitCode != 0) { + _logger.printTrace('"adb logcat -c" failed: exitCode: ${result.exitCode}' + ' stdout: ${result.stdout} stderr: ${result.stderr}'); + } } @override diff --git a/packages/flutter_tools/test/general.shard/android/android_device_test.dart b/packages/flutter_tools/test/general.shard/android/android_device_test.dart index 6746dde009..65ee261afb 100644 --- a/packages/flutter_tools/test/general.shard/android/android_device_test.dart +++ b/packages/flutter_tools/test/general.shard/android/android_device_test.dart @@ -331,6 +331,18 @@ flutter: expect(await device.emulatorId, isNull); }); + testWithoutContext('AndroidDevice clearLogs does not crash', () async { + final AndroidDevice device = setUpAndroidDevice( + processManager: FakeProcessManager.list([ + const FakeCommand( + command: ['adb', '-s', '1234', 'logcat', '-c'], + exitCode: 1, + ), + ]) + ); + device.clearLogs(); + }); + testWithoutContext('AndroidDevice lastLogcatTimestamp returns null if shell command failed', () async { final AndroidDevice device = setUpAndroidDevice( processManager: FakeProcessManager.list([