Unverified Commit cd19bc60 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Do not retry if pub get is run in offline mode (#90394)

parent 48e6758f
......@@ -27,6 +27,10 @@ const String _kPubEnvironmentKey = 'PUB_ENVIRONMENT';
/// The console environment key used by the pub tool to find the cache directory.
const String _kPubCacheEnvironmentKey = 'PUB_CACHE';
/// The UNAVAILABLE exit code returned by the pub tool.
/// (see https://github.com/dart-lang/pub/blob/master/lib/src/exit_codes.dart)
const int _kPubExitCodeUnavailable = 69;
typedef MessageFilter = String Function(String message);
/// Represents Flutter-specific data that is added to the `PUB_ENVIRONMENT`
......@@ -250,7 +254,7 @@ class _DefaultPub implements Pub {
context: context,
directory: directory,
failureMessage: 'pub $command failed',
retry: true,
retry: !offline,
flutterRootOverride: flutterRootOverride,
);
status.stop();
......@@ -303,7 +307,7 @@ class _DefaultPub implements Pub {
int attempts = 0;
int duration = 1;
int code;
loop: while (true) {
while (true) {
attempts += 1;
code = await _processUtils.stream(
_pubCommand(arguments),
......@@ -311,15 +315,15 @@ class _DefaultPub implements Pub {
mapFunction: filterWrapper, // may set versionSolvingFailed, lastPubMessage
environment: await _createPubEnvironment(context, flutterRootOverride),
);
String message;
switch (code) {
case 69: // UNAVAILABLE in https://github.com/dart-lang/pub/blob/master/lib/src/exit_codes.dart
String? message;
if (retry) {
if (code == _kPubExitCodeUnavailable) {
message = 'server unavailable';
break;
default:
break loop;
}
}
if (message == null) {
break;
}
assert(message != null);
versionSolvingFailed = false;
_logger.printStatus(
'$failureMessage ($message) -- attempting retry $attempts in $duration '
......
......@@ -594,6 +594,54 @@ void main() {
expect(processManager, hasNoRemainingExpectations);
});
testWithoutContext('pub get offline does not retry', () async {
String? error;
const FakeCommand pubGetCommand = FakeCommand(
command: <String>[
'bin/cache/dart-sdk/bin/dart',
'__deprecated_pub',
'--verbosity=warning',
'get',
'--no-precompile',
'--offline',
],
exitCode: 69,
environment: <String, String>{'FLUTTER_ROOT': '', 'PUB_ENVIRONMENT': 'flutter_cli:flutter_tests'},
);
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
pubGetCommand,
]);
final BufferLogger logger = BufferLogger.test();
final FileSystem fileSystem = MemoryFileSystem.test();
final Pub pub = Pub(
fileSystem: fileSystem,
logger: logger,
processManager: processManager,
usage: TestUsage(),
platform: FakePlatform(
environment: const <String, String>{},
),
botDetector: const BotDetectorAlwaysNo(),
);
FakeAsync().run((FakeAsync time) {
expect(logger.statusText, '');
pub.get(context: PubContext.flutterTests, offline: true).then((void value) {
error = 'test completed unexpectedly';
}, onError: (dynamic thrownError) {
error = 'test failed unexpectedly: $thrownError';
});
time.elapse(const Duration(milliseconds: 500));
expect(logger.statusText,
'Running "flutter pub get" in /...\n'
);
});
expect(logger.errorText, isEmpty);
expect(error, 'test failed unexpectedly: Exception: pub get failed (69; no message)');
expect(processManager, hasNoRemainingExpectations);
});
testWithoutContext('pub get 66 shows message from pub', () async {
final BufferLogger logger = BufferLogger.test();
final FileSystem fileSystem = MemoryFileSystem.test();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment