diff --git a/packages/flutter_tools/lib/src/base/terminal.dart b/packages/flutter_tools/lib/src/base/terminal.dart index e0e2b4b796..4d329af3ba 100644 --- a/packages/flutter_tools/lib/src/base/terminal.dart +++ b/packages/flutter_tools/lib/src/base/terminal.dart @@ -81,7 +81,10 @@ class OutputPreferences { /// The command line terminal, if available. abstract class Terminal { - factory Terminal.test() = _TestTerminal; + /// Create a new test [Terminal]. + /// + /// If not specified, [supportsColor] defaults to `false`. + factory Terminal.test({bool supportsColor}) = _TestTerminal; /// Whether the current terminal supports color escape codes. bool get supportsColor; @@ -300,6 +303,8 @@ class AnsiTerminal implements Terminal { } class _TestTerminal implements Terminal { + _TestTerminal({this.supportsColor = false}); + @override bool usesTerminalUi; @@ -329,7 +334,7 @@ class _TestTerminal implements Terminal { set singleCharMode(bool value) { } @override - bool get supportsColor => false; + final bool supportsColor; @override bool get supportsEmoji => false; diff --git a/packages/flutter_tools/lib/src/cache.dart b/packages/flutter_tools/lib/src/cache.dart index db3f6f9026..a35d8f87d0 100644 --- a/packages/flutter_tools/lib/src/cache.dart +++ b/packages/flutter_tools/lib/src/cache.dart @@ -1466,13 +1466,14 @@ class ArtifactUpdater { ) async { final String downloadPath = flattenNameSubdirs(url, _fileSystem); final File tempFile = _createDownloadFile(downloadPath); - final Status status = _logger.startProgress( - message, - timeout: null, // This will take a variable amount of time based on network connectivity. - ); + Status status; int retries = _kRetryCount; while (retries > 0) { + status = _logger.startProgress( + message, + timeout: null, // This will take a variable amount of time based on network connectivity. + ); try { _ensureExists(tempFile.parent); final IOSink ioSink = tempFile.openWrite(); diff --git a/packages/flutter_tools/test/general.shard/artifact_updater_test.dart b/packages/flutter_tools/test/general.shard/artifact_updater_test.dart index a86cdbd3d4..b6f7c49e4e 100644 --- a/packages/flutter_tools/test/general.shard/artifact_updater_test.dart +++ b/packages/flutter_tools/test/general.shard/artifact_updater_test.dart @@ -10,10 +10,12 @@ import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/os.dart'; import 'package:flutter_tools/src/base/platform.dart'; +import 'package:flutter_tools/src/base/terminal.dart'; import 'package:flutter_tools/src/cache.dart'; import 'package:mockito/mockito.dart'; import '../src/common.dart'; +import '../src/mocks.dart'; final Platform testPlatform = FakePlatform(environment: {}); @@ -41,6 +43,34 @@ void main() { expect(fileSystem.file('out/test'), exists); }); + testWithoutContext('ArtifactUpdater will restart the status ticker if it needs to retry the download', () async { + final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(); + final MemoryFileSystem fileSystem = MemoryFileSystem.test(); + final Logger logger = StdoutLogger( + terminal: Terminal.test(supportsColor: true), + stdio: MockStdio(), + outputPreferences: OutputPreferences.test(), + timeoutConfiguration: const TimeoutConfiguration(), + ); + final ArtifactUpdater artifactUpdater = ArtifactUpdater( + fileSystem: fileSystem, + logger: logger, + operatingSystemUtils: operatingSystemUtils, + platform: testPlatform, + httpClient: MockHttpClient()..exceptionOnFirstRun = true, + tempStorage: fileSystem.currentDirectory.childDirectory('temp') + ..createSync(), + ); + + await artifactUpdater.downloadZipArchive( + 'test message', + Uri.parse('http:///test.zip'), + fileSystem.currentDirectory.childDirectory('out'), + ); + + expect(fileSystem.file('out/test'), exists); + }); + testWithoutContext('ArtifactUpdater will re-attempt on a non-200 response', () async { final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(); final MemoryFileSystem fileSystem = MemoryFileSystem.test(); @@ -249,10 +279,15 @@ class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils { class MockHttpClient extends Mock implements HttpClient { int attempts = 0; bool argumentError = false; + bool exceptionOnFirstRun = false; final MockHttpClientRequest testRequest = MockHttpClientRequest(); @override Future getUrl(Uri url) async { + if (exceptionOnFirstRun && attempts == 0) { + attempts += 1; + throw Exception(); + } attempts += 1; if (argumentError) { throw ArgumentError();