Do not retry if pub get is run in offline mode (#90394)
This commit is contained in:
parent
48e6758fb5
commit
cd19bc6007
@ -27,6 +27,10 @@ const String _kPubEnvironmentKey = 'PUB_ENVIRONMENT';
|
|||||||
/// The console environment key used by the pub tool to find the cache directory.
|
/// The console environment key used by the pub tool to find the cache directory.
|
||||||
const String _kPubCacheEnvironmentKey = 'PUB_CACHE';
|
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);
|
typedef MessageFilter = String Function(String message);
|
||||||
|
|
||||||
/// Represents Flutter-specific data that is added to the `PUB_ENVIRONMENT`
|
/// Represents Flutter-specific data that is added to the `PUB_ENVIRONMENT`
|
||||||
@ -250,7 +254,7 @@ class _DefaultPub implements Pub {
|
|||||||
context: context,
|
context: context,
|
||||||
directory: directory,
|
directory: directory,
|
||||||
failureMessage: 'pub $command failed',
|
failureMessage: 'pub $command failed',
|
||||||
retry: true,
|
retry: !offline,
|
||||||
flutterRootOverride: flutterRootOverride,
|
flutterRootOverride: flutterRootOverride,
|
||||||
);
|
);
|
||||||
status.stop();
|
status.stop();
|
||||||
@ -303,7 +307,7 @@ class _DefaultPub implements Pub {
|
|||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
int duration = 1;
|
int duration = 1;
|
||||||
int code;
|
int code;
|
||||||
loop: while (true) {
|
while (true) {
|
||||||
attempts += 1;
|
attempts += 1;
|
||||||
code = await _processUtils.stream(
|
code = await _processUtils.stream(
|
||||||
_pubCommand(arguments),
|
_pubCommand(arguments),
|
||||||
@ -311,15 +315,15 @@ class _DefaultPub implements Pub {
|
|||||||
mapFunction: filterWrapper, // may set versionSolvingFailed, lastPubMessage
|
mapFunction: filterWrapper, // may set versionSolvingFailed, lastPubMessage
|
||||||
environment: await _createPubEnvironment(context, flutterRootOverride),
|
environment: await _createPubEnvironment(context, flutterRootOverride),
|
||||||
);
|
);
|
||||||
String message;
|
String? message;
|
||||||
switch (code) {
|
if (retry) {
|
||||||
case 69: // UNAVAILABLE in https://github.com/dart-lang/pub/blob/master/lib/src/exit_codes.dart
|
if (code == _kPubExitCodeUnavailable) {
|
||||||
message = 'server unavailable';
|
message = 'server unavailable';
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break loop;
|
|
||||||
}
|
}
|
||||||
assert(message != null);
|
}
|
||||||
|
if (message == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
versionSolvingFailed = false;
|
versionSolvingFailed = false;
|
||||||
_logger.printStatus(
|
_logger.printStatus(
|
||||||
'$failureMessage ($message) -- attempting retry $attempts in $duration '
|
'$failureMessage ($message) -- attempting retry $attempts in $duration '
|
||||||
|
@ -594,6 +594,54 @@ void main() {
|
|||||||
expect(processManager, hasNoRemainingExpectations);
|
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 {
|
testWithoutContext('pub get 66 shows message from pub', () async {
|
||||||
final BufferLogger logger = BufferLogger.test();
|
final BufferLogger logger = BufferLogger.test();
|
||||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user