Adding a timeout and retry to upload results step. (#87306)
* Adding a timeout and retry to upload results step. * Adding tests for retries and timeout. * Adding async to call * Fixing sleep to trigger the timeout, and adding addition timeout test. * Fixing minor typo. * Fixing some minor flutter style issues. Co-authored-by: yusufm <mohsinally@google.com>
This commit is contained in:
@@ -37,6 +37,7 @@ class Cocoon {
|
||||
@visibleForTesting this.fs = const LocalFileSystem(),
|
||||
@visibleForTesting this.processRunSync = Process.runSync,
|
||||
@visibleForTesting this.requestRetryLimit = 5,
|
||||
@visibleForTesting this.requestTimeoutLimit = 30,
|
||||
}) : _httpClient = AuthenticatedCocoonClient(serviceAccountTokenPath, httpClient: httpClient, filesystem: fs);
|
||||
|
||||
/// Client to make http requests to Cocoon.
|
||||
@@ -58,6 +59,9 @@ class Cocoon {
|
||||
@visibleForTesting
|
||||
final int requestRetryLimit;
|
||||
|
||||
@visibleForTesting
|
||||
final int requestTimeoutLimit;
|
||||
|
||||
String get commitSha => _commitSha ?? _readCommitSha();
|
||||
String? _commitSha;
|
||||
|
||||
@@ -99,8 +103,12 @@ class Cocoon {
|
||||
}
|
||||
resultsJson['TestFlaky'] = isTestFlaky ?? false;
|
||||
const List<String> supportedBranches = <String>['master'];
|
||||
if(supportedBranches.contains(resultsJson['CommitBranch'])) {
|
||||
await _sendUpdateTaskRequest(resultsJson);
|
||||
if (supportedBranches.contains(resultsJson['CommitBranch'])) {
|
||||
await retry(
|
||||
() async => _sendUpdateTaskRequest(resultsJson).timeout(Duration(seconds: requestTimeoutLimit)),
|
||||
retryIf: (Exception e) => e is SocketException || e is TimeoutException || e is ClientException,
|
||||
maxAttempts: requestRetryLimit,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,6 +167,7 @@ class Cocoon {
|
||||
}
|
||||
|
||||
Future<void> _sendUpdateTaskRequest(Map<String, dynamic> postBody) async {
|
||||
logger.info('Attempting to send update task request to Cocoon.');
|
||||
final Map<String, dynamic> response = await _sendCocoonRequest('update-task-status', postBody);
|
||||
if (response['Name'] != null) {
|
||||
logger.info('Updated Cocoon with results from this task');
|
||||
|
||||
Reference in New Issue
Block a user