From b4c6ce8ffbd4cf82c46bbc43fbf592d9cd41709d Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Sat, 18 Apr 2020 11:31:47 -0700 Subject: [PATCH 1/2] Add retries to fuchsia paving. Bug: https://github.com/flutter/flutter/issues/50246 https://github.com/flutter/flutter/issues/54256 --- packages/fuchsia_ctl/bin/main.dart | 36 ++++++++++++++++++++++++++---- packages/fuchsia_ctl/pubspec.yaml | 1 + 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/packages/fuchsia_ctl/bin/main.dart b/packages/fuchsia_ctl/bin/main.dart index b76ac1e8ed85..9cf87441288f 100644 --- a/packages/fuchsia_ctl/bin/main.dart +++ b/packages/fuchsia_ctl/bin/main.dart @@ -13,6 +13,7 @@ import 'package:fuchsia_ctl/src/operation_result.dart'; import 'package:fuchsia_ctl/src/tar.dart'; import 'package:meta/meta.dart'; import 'package:path/path.dart' as path; +import 'package:retry/retry.dart'; import 'package:uuid/uuid.dart'; typedef AsyncResult = Future Function( @@ -163,11 +164,21 @@ Future pave( ArgResults args, ) async { const ImagePaver paver = ImagePaver(); - return await paver.pave( - args['image'], - deviceName, - publicKeyPath: args['public-key'], + const RetryOptions r = RetryOptions( + maxDelay: Duration(seconds: 30), + maxAttempts: 3, ); + return await r.retry(() async { + final OperationResult result = await paver.pave( + args['image'], + deviceName, + publicKeyPath: args['public-key'], + ); + if (!result.success) { + throw RetryException('Exit code different from 0', result); + } + return result; + }, retryIf: (Exception e) => e is RetryException); } @visibleForTesting @@ -309,3 +320,20 @@ Future test( } } } + +/// The exception thrown when an operation needs a retry. +class RetryException implements Exception { + /// Creates a new [RetryException] using the specified [cause] and [result] + /// to force a retry. + const RetryException(this.cause, this.result); + + /// The user-facing message to display. + final String cause; + + /// Contains the result of the executed target command. + final OperationResult result; + + @override + String toString() => + '$runtimeType, cause: "$cause", underlying exception: $result.'; +} diff --git a/packages/fuchsia_ctl/pubspec.yaml b/packages/fuchsia_ctl/pubspec.yaml index 86fff0c00854..570a381dd3df 100644 --- a/packages/fuchsia_ctl/pubspec.yaml +++ b/packages/fuchsia_ctl/pubspec.yaml @@ -15,6 +15,7 @@ dependencies: meta: ^1.1.7 path: ^1.6.4 process: ^3.0.12 + retry: ^3.0.0+1 uuid: ^2.0.2 dev_dependencies: From 22e482c7b5826a0af3f098f2d9129dd955d6e4d2 Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Sat, 18 Apr 2020 12:01:41 -0700 Subject: [PATCH 2/2] Update version and changelog. --- packages/fuchsia_ctl/CHANGELOG.md | 10 ++++++++++ packages/fuchsia_ctl/pubspec.yaml | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/fuchsia_ctl/CHANGELOG.md b/packages/fuchsia_ctl/CHANGELOG.md index cd2183527ed2..e8153d2f5da9 100644 --- a/packages/fuchsia_ctl/CHANGELOG.md +++ b/packages/fuchsia_ctl/CHANGELOG.md @@ -1,5 +1,15 @@ # CHANGELOG + + +## 0.0.18 - 0.0.21 + +- Add retries to paving operations. +- Add timeouts to paving and ssh operations. +- Add arguments parameter to test command. + + + ## 0.0.17 - Add "push-packages" option. diff --git a/packages/fuchsia_ctl/pubspec.yaml b/packages/fuchsia_ctl/pubspec.yaml index 570a381dd3df..78b30fb90748 100644 --- a/packages/fuchsia_ctl/pubspec.yaml +++ b/packages/fuchsia_ctl/pubspec.yaml @@ -4,7 +4,7 @@ description: > Fuchsia Device. This package is primarily intended for use in Flutter's continuous integration/testing infrastructure. homepage: https://github.com/flutter/packags/tree/master/packages/fuchsia_ctl -version: 0.0.17 +version: 0.0.21 environment: sdk: ">=2.4.0 <3.0.0"