From 79f377dabeaec96fdaec7d1aac6cc9e45704a76d Mon Sep 17 00:00:00 2001 From: Casey Hillers Date: Tue, 27 Jul 2021 12:49:05 -0700 Subject: [PATCH] [devicelab] Only upload results on master (#87125) --- dev/devicelab/lib/framework/cocoon.dart | 5 ++++- dev/devicelab/test/cocoon_test.dart | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/dev/devicelab/lib/framework/cocoon.dart b/dev/devicelab/lib/framework/cocoon.dart index 7f5089bcde..3f6357a61a 100644 --- a/dev/devicelab/lib/framework/cocoon.dart +++ b/dev/devicelab/lib/framework/cocoon.dart @@ -98,7 +98,10 @@ class Cocoon { resultsJson['NewStatus'] = testStatus; } resultsJson['TestFlaky'] = isTestFlaky ?? false; - await _sendUpdateTaskRequest(resultsJson); + const List supportedBranches = ['master']; + if(supportedBranches.contains(resultsJson['CommitBranch'])) { + await _sendUpdateTaskRequest(resultsJson); + } } /// Write the given parameters into an update task request and store the JSON in [resultsPath]. diff --git a/dev/devicelab/test/cocoon_test.dart b/dev/devicelab/test/cocoon_test.dart index c0f6db6c62..5ee64b8527 100644 --- a/dev/devicelab/test/cocoon_test.dart +++ b/dev/devicelab/test/cocoon_test.dart @@ -178,6 +178,31 @@ void main() { expect(() => cocoon.sendResultsPath(resultsPath: resultsPath), throwsA(isA())); }); + + test('does not upload results on non-supported branches', () async { + // Any network failure would cause the upoad to fail + mockClient = MockClient((Request request) async => Response('', 500)); + + cocoon = Cocoon( + serviceAccountTokenPath: serviceAccountTokenPath, + fs: fs, + httpClient: mockClient, + requestRetryLimit: 0, + ); + + const String resultsPath = 'results.json'; + const String updateTaskJson = '{' + '"CommitBranch":"stable",' + '"CommitSha":"$commitSha",' + '"BuilderName":"builderAbc",' + '"NewStatus":"Succeeded",' + '"ResultData":{"i":0.0,"j":0.0,"not_a_metric":"something"},' + '"BenchmarkScoreKeys":["i","j"]}'; + fs.file(resultsPath).writeAsStringSync(updateTaskJson); + + // This will fail if it decided to upload results + await cocoon.sendResultsPath(resultsPath: resultsPath); + }); }); group('AuthenticatedCocoonClient', () {