Unverified Commit 9072a099 authored by Emmanuel Garcia's avatar Emmanuel Garcia Committed by GitHub

Fix race condition in readJsonResults (#100243)

parent 3c6b760e
...@@ -152,6 +152,14 @@ abstract class Device { ...@@ -152,6 +152,14 @@ abstract class Device {
/// with some prefix. /// with some prefix.
Stream<String> get logcat; Stream<String> get logcat;
/// Clears the device logs.
///
/// This is important because benchmarks tests rely on the logs produced by
/// the flutter run command.
///
/// On Android, those logs may contain logs from previous test.
Future<void> clearLogs();
/// Whether this device supports calls to [startLoggingToSink] /// Whether this device supports calls to [startLoggingToSink]
/// and [stopLoggingToSink]. /// and [stopLoggingToSink].
bool get canStreamLogs => false; bool get canStreamLogs => false;
...@@ -667,6 +675,11 @@ class AndroidDevice extends Device { ...@@ -667,6 +675,11 @@ class AndroidDevice extends Device {
} }
} }
@override
Future<void> clearLogs() {
return adb(<String>['logcat', '-c']);
}
@override @override
Stream<String> get logcat { Stream<String> get logcat {
final Completer<void> stdoutDone = Completer<void>(); final Completer<void> stdoutDone = Completer<void>();
...@@ -677,7 +690,7 @@ class AndroidDevice extends Device { ...@@ -677,7 +690,7 @@ class AndroidDevice extends Device {
late final StreamController<String> stream; late final StreamController<String> stream;
stream = StreamController<String>( stream = StreamController<String>(
onListen: () async { onListen: () async {
await adb(<String>['logcat', '-c']); await clearLogs();
final Process process = await startProcess( final Process process = await startProcess(
adbPath, adbPath,
// Make logcat less chatty by filtering down to just ActivityManager // Make logcat less chatty by filtering down to just ActivityManager
...@@ -971,6 +984,9 @@ class IosDevice extends Device { ...@@ -971,6 +984,9 @@ class IosDevice extends Device {
throw UnimplementedError(); throw UnimplementedError();
} }
@override
Future<void> clearLogs() async {}
@override @override
Future<void> stop(String packageName) async {} Future<void> stop(String packageName) async {}
...@@ -1007,6 +1023,9 @@ class WindowsDevice extends Device { ...@@ -1007,6 +1023,9 @@ class WindowsDevice extends Device {
@override @override
Stream<String> get logcat => const Stream<String>.empty(); Stream<String> get logcat => const Stream<String>.empty();
@override
Future<void> clearLogs() async {}
@override @override
Future<void> reboot() async { } Future<void> reboot() async { }
...@@ -1074,6 +1093,9 @@ class FuchsiaDevice extends Device { ...@@ -1074,6 +1093,9 @@ class FuchsiaDevice extends Device {
throw UnimplementedError(); throw UnimplementedError();
} }
@override
Future<void> clearLogs() async {}
@override @override
Future<void> reboot() async { Future<void> reboot() async {
// Unsupported. // Unsupported.
...@@ -1142,6 +1164,9 @@ class FakeDevice extends Device { ...@@ -1142,6 +1164,9 @@ class FakeDevice extends Device {
throw UnimplementedError(); throw UnimplementedError();
} }
@override
Future<void> clearLogs() async {}
@override @override
Future<void> stop(String packageName) async {} Future<void> stop(String packageName) async {}
......
...@@ -31,14 +31,14 @@ Future<Map<String, double>> readJsonResults(Process process) { ...@@ -31,14 +31,14 @@ Future<Map<String, double>> readJsonResults(Process process) {
.transform<String>(const Utf8Decoder()) .transform<String>(const Utf8Decoder())
.transform<String>(const LineSplitter()) .transform<String>(const LineSplitter())
.listen((String line) async { .listen((String line) async {
print(line); print('[STDOUT] $line');
if (line.contains(jsonStart)) { if (line.contains(jsonStart)) {
jsonStarted = true; jsonStarted = true;
return; return;
} }
if (line.contains(jsonEnd)) { if (jsonStarted && line.contains(jsonEnd)) {
final String jsonOutput = jsonBuf.toString(); final String jsonOutput = jsonBuf.toString();
// If we end up here and have already parsed the results, it suggests that // If we end up here and have already parsed the results, it suggests that
......
...@@ -19,6 +19,7 @@ TaskFunction createMicrobenchmarkTask() { ...@@ -19,6 +19,7 @@ TaskFunction createMicrobenchmarkTask() {
return () async { return () async {
final Device device = await devices.workingDevice; final Device device = await devices.workingDevice;
await device.unlock(); await device.unlock();
await device.clearLogs();
Future<Map<String, double>> _runMicrobench(String benchmarkPath) async { Future<Map<String, double>> _runMicrobench(String benchmarkPath) async {
Future<Map<String, double>> _run() async { Future<Map<String, double>> _run() async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment