From 7f6685658cc269dc37ad394cc29192a0e152a6c8 Mon Sep 17 00:00:00 2001 From: godofredoc Date: Fri, 29 Mar 2024 15:18:20 -0700 Subject: [PATCH] Generate test metrics consistently. (#145943) Starts creating metric files consistently for web, dart and flutter runners. It also starts creating the files in the temp folder instead of the checkout one. Bug: https://github.com/flutter/flutter/issues/145793 --- dev/bots/test.dart | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/dev/bots/test.dart b/dev/bots/test.dart index 19f8bfd773..dfd9d0e5c4 100644 --- a/dev/bots/test.dart +++ b/dev/bots/test.dart @@ -1665,11 +1665,15 @@ Future runFlutterWebTest( List tests, bool useWasm, ) async { + const LocalFileSystem fileSystem = LocalFileSystem(); + final String suffix = DateTime.now().microsecondsSinceEpoch.toString(); + final File metricFile = fileSystem.systemTempDirectory.childFile('metrics_$suffix.json'); await runCommand( flutter, [ 'test', '--reporter=expanded', + '--file-reporter=json:${metricFile.path}', '-v', '--platform=chrome', if (useWasm) '--wasm', @@ -1683,6 +1687,10 @@ Future runFlutterWebTest( 'FLUTTER_WEB': 'true', }, ); + // metriciFile is a transitional file that needs to be deleted once it is parsed. + // TODO(godofredoc): Ensure metricFile is parsed and aggregated before deleting. + // https://github.com/flutter/flutter/issues/146003 + metricFile.deleteSync(); } @@ -1724,7 +1732,8 @@ Future _runDartTest(String workingDirectory, { } const LocalFileSystem fileSystem = LocalFileSystem(); - final File metricFile = fileSystem.file(path.join(flutterRoot, 'metrics.json')); + final String suffix = DateTime.now().microsecondsSinceEpoch.toString(); + final File metricFile = fileSystem.systemTempDirectory.childFile('metrics_$suffix.json'); final List args = [ 'run', 'test', @@ -1787,6 +1796,11 @@ Future _runDartTest(String workingDirectory, { print('Failed to generate metrics: $e'); } } + + // metriciFile is a transitional file that needs to be deleted once it is parsed. + // TODO(godofredoc): Ensure metricFile is parsed and aggregated before deleting. + // https://github.com/flutter/flutter/issues/146003 + metricFile.deleteSync(); } Future _runFlutterTest(String workingDirectory, { @@ -1809,9 +1823,13 @@ Future _runFlutterTest(String workingDirectory, { tags.addAll(['-t', 'reduced-test-set']); } + const LocalFileSystem fileSystem = LocalFileSystem(); + final String suffix = DateTime.now().microsecondsSinceEpoch.toString(); + final File metricFile = fileSystem.systemTempDirectory.childFile('metrics_$suffix.json'); final List args = [ 'test', '--reporter=expanded', + '--file-reporter=json:${metricFile.path}', if (shuffleTests && !_isRandomizationOff) '--test-randomize-ordering-seed=$shuffleSeed', if (fatalWarnings) '--fatal-warnings', ...options, @@ -1849,6 +1867,11 @@ Future _runFlutterTest(String workingDirectory, { environment: environment, ); + // metriciFile is a transitional file that needs to be deleted once it is parsed. + // TODO(godofredoc): Ensure metricFile is parsed and aggregated before deleting. + // https://github.com/flutter/flutter/issues/146003 + metricFile.deleteSync(); + if (outputChecker != null) { final String? message = outputChecker(result); if (message != null) {