[devicelab] Only upload results on master (#87125)

This commit is contained in:
Casey Hillers 2021-07-27 12:49:05 -07:00 committed by GitHub
parent 889ab8381e
commit 79f377dabe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -98,8 +98,11 @@ class Cocoon {
resultsJson['NewStatus'] = testStatus;
}
resultsJson['TestFlaky'] = isTestFlaky ?? false;
const List<String> supportedBranches = <String>['master'];
if(supportedBranches.contains(resultsJson['CommitBranch'])) {
await _sendUpdateTaskRequest(resultsJson);
}
}
/// Write the given parameters into an update task request and store the JSON in [resultsPath].
Future<void> writeTaskResultToFile({

View File

@ -178,6 +178,31 @@ void main() {
expect(() => cocoon.sendResultsPath(resultsPath: resultsPath),
throwsA(isA<ClientException>()));
});
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', () {