Skip to content

Commit

Permalink
Update android_device.dart to have clearLogs not print to standard er…
Browse files Browse the repository at this point in the history
…ror (#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 flutter/flutter#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.
  • Loading branch information
reidbaker authored Jun 24, 2024
1 parent fd3f769 commit 7292c94
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/flutter_tools/lib/src/android/android_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,12 @@ class AndroidDevice extends Device {

@override
void clearLogs() {
_processUtils.runSync(adbCommandForDevice(<String>['logcat', '-c']));
final RunResult result = _processUtils.runSync(adbCommandForDevice(<String>['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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,18 @@ flutter:
expect(await device.emulatorId, isNull);
});

testWithoutContext('AndroidDevice clearLogs does not crash', () async {
final AndroidDevice device = setUpAndroidDevice(
processManager: FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['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(<FakeCommand>[
Expand Down

0 comments on commit 7292c94

Please sign in to comment.