Fix race condition in readJsonResults (#100243)
This commit is contained in:
parent
3c6b760e4c
commit
9072a09958
@ -152,6 +152,14 @@ abstract class Device {
|
||||
/// with some prefix.
|
||||
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]
|
||||
/// and [stopLoggingToSink].
|
||||
bool get canStreamLogs => false;
|
||||
@ -667,6 +675,11 @@ class AndroidDevice extends Device {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> clearLogs() {
|
||||
return adb(<String>['logcat', '-c']);
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<String> get logcat {
|
||||
final Completer<void> stdoutDone = Completer<void>();
|
||||
@ -677,7 +690,7 @@ class AndroidDevice extends Device {
|
||||
late final StreamController<String> stream;
|
||||
stream = StreamController<String>(
|
||||
onListen: () async {
|
||||
await adb(<String>['logcat', '-c']);
|
||||
await clearLogs();
|
||||
final Process process = await startProcess(
|
||||
adbPath,
|
||||
// Make logcat less chatty by filtering down to just ActivityManager
|
||||
@ -971,6 +984,9 @@ class IosDevice extends Device {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> clearLogs() async {}
|
||||
|
||||
@override
|
||||
Future<void> stop(String packageName) async {}
|
||||
|
||||
@ -1007,6 +1023,9 @@ class WindowsDevice extends Device {
|
||||
@override
|
||||
Stream<String> get logcat => const Stream<String>.empty();
|
||||
|
||||
@override
|
||||
Future<void> clearLogs() async {}
|
||||
|
||||
@override
|
||||
Future<void> reboot() async { }
|
||||
|
||||
@ -1074,6 +1093,9 @@ class FuchsiaDevice extends Device {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> clearLogs() async {}
|
||||
|
||||
@override
|
||||
Future<void> reboot() async {
|
||||
// Unsupported.
|
||||
@ -1142,6 +1164,9 @@ class FakeDevice extends Device {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> clearLogs() async {}
|
||||
|
||||
@override
|
||||
Future<void> stop(String packageName) async {}
|
||||
|
||||
|
@ -31,14 +31,14 @@ Future<Map<String, double>> readJsonResults(Process process) {
|
||||
.transform<String>(const Utf8Decoder())
|
||||
.transform<String>(const LineSplitter())
|
||||
.listen((String line) async {
|
||||
print(line);
|
||||
print('[STDOUT] $line');
|
||||
|
||||
if (line.contains(jsonStart)) {
|
||||
jsonStarted = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (line.contains(jsonEnd)) {
|
||||
if (jsonStarted && line.contains(jsonEnd)) {
|
||||
final String jsonOutput = jsonBuf.toString();
|
||||
|
||||
// If we end up here and have already parsed the results, it suggests that
|
||||
|
@ -19,6 +19,7 @@ TaskFunction createMicrobenchmarkTask() {
|
||||
return () async {
|
||||
final Device device = await devices.workingDevice;
|
||||
await device.unlock();
|
||||
await device.clearLogs();
|
||||
|
||||
Future<Map<String, double>> _runMicrobench(String benchmarkPath) async {
|
||||
Future<Map<String, double>> _run() async {
|
||||
|
Loading…
x
Reference in New Issue
Block a user