diff --git a/.cirrus.yml b/.cirrus.yml index ace33146a041c..b8a732be9e996 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -40,16 +40,9 @@ task: ninja -C out/host_release benchmark_host_script: | cd $ENGINE_PATH/src/out/host_release/ - ./txt_benchmarks --benchmark_format=json > txt_benchmarks.json - ./fml_benchmarks --benchmark_format=json > fml_benchmarks.json - ./shell_benchmarks --benchmark_format=json > shell_benchmarks.json - ./ui_benchmarks --benchmark_format=json > ui_benchmarks.json + $ENGINE_PATH/src/flutter/testing/benchmark/generate_metrics.sh cd $ENGINE_PATH/src/flutter/testing/benchmark - pub get - dart bin/parse_and_send.dart ../../../out/host_release/txt_benchmarks.json - dart bin/parse_and_send.dart ../../../out/host_release/fml_benchmarks.json - dart bin/parse_and_send.dart ../../../out/host_release/shell_benchmarks.json - dart bin/parse_and_send.dart ../../../out/host_release/ui_benchmarks.json + upload_metrics.sh # The following test depends on Flutter framework repo. It may fail if the # framework repo is currently broken. diff --git a/testing/benchmark/bin/parse_and_send.dart b/testing/benchmark/bin/parse_and_send.dart index 443280cd9ca87..da247e44c40a8 100644 --- a/testing/benchmark/bin/parse_and_send.dart +++ b/testing/benchmark/bin/parse_and_send.dart @@ -38,18 +38,33 @@ Future> _parse(String jsonFileName) async { return points; } +Future connectFlutterDestination() async { + const String kTokenPath = 'TOKEN_PATH'; + const String kGcpProject = 'GCP_PROJECT'; + final Map env = Platform.environment; + if (env.containsKey(kTokenPath) && env.containsKey(kGcpProject)) { + return FlutterDestination.makeFromAccessToken( + File(env[kTokenPath]).readAsStringSync(), + env[kGcpProject], + ); + } + return await FlutterDestination.makeFromCredentialsJson( + jsonDecode(Platform.environment['BENCHMARK_GCP_CREDENTIALS']) + as Map, + ); +} + Future main(List args) async { if (args.length != 1) { throw 'Must have one argument: '; } final List points = await _parse(args[0]); + // The data will be sent to the Datastore of the GCP project specified through - // environment variable BENCHMARK_GCP_CREDENTIALS. The engine Cirrus job has - // currently configured the GCP project to flutter-cirrus for test. We'll - // eventually migrate to flutter-infra project once the test is done. - final FlutterDestination destination = - await FlutterDestination.makeFromCredentialsJson( - jsonDecode(Platform.environment['BENCHMARK_GCP_CREDENTIALS']), - ); + // environment variable BENCHMARK_GCP_CREDENTIALS, or TOKEN_PATH/GCP_PROJECT. + // The engine Cirrus job has currently configured the GCP project to + // flutter-cirrus for test. We'll eventually migrate to flutter-infra project + // once the test is done. + final FlutterDestination destination = await connectFlutterDestination(); await destination.update(points); } diff --git a/testing/benchmark/test/parse_and_send_test.dart b/testing/benchmark/test/parse_and_send_test.dart index 43af537cf8a18..6db1aded44e8e 100644 --- a/testing/benchmark/test/parse_and_send_test.dart +++ b/testing/benchmark/test/parse_and_send_test.dart @@ -3,12 +3,16 @@ // found in the LICENSE file. // @dart = 2.6 +import 'dart:convert'; import 'dart:io'; +import 'package:gcloud/src/datastore_impl.dart'; +import 'package:googleapis_auth/auth_io.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; void main() { - // In order to run this test, one should download a service account + // In order to run these tests, one should download a service account // credentials json from a test GCP project, and put that json as // `secret/test_gcp_credentials.json`. There's a `flutter-test` project for // Flutter team members. @@ -22,4 +26,25 @@ void main() { 'BENCHMARK_GCP_CREDENTIALS': testCred, }); }); + + test('parse_and_send succeeds with access token.', () async { + final dynamic testCred = + jsonDecode(File('secret/test_gcp_credentials.json').readAsStringSync()) + as Map; + final AutoRefreshingAuthClient client = await clientViaServiceAccount( + ServiceAccountCredentials.fromJson(testCred), + DatastoreImpl.SCOPES, + ); + final String tokenPath = + path.join(Directory.systemTemp.absolute.path, 'parse_and_send_token'); + File(tokenPath).writeAsStringSync(client.credentials.accessToken.data); + final ProcessResult result = Process.runSync('dart', [ + 'bin/parse_and_send.dart', + 'example/txt_benchmarks.json', + ], environment: { + 'TOKEN_PATH': tokenPath, + 'GCP_PROJECT': testCred['project_id'] as String, + }); + expect(result.exitCode, 0); + }); }