Add sharding options to test command line (#76382)
This commit is contained in:
@@ -140,6 +140,16 @@ class TestCommand extends FlutterCommand {
|
||||
'which indicates that a seed should be selected randomly. '
|
||||
'By default, tests run in the order they are declared.',
|
||||
)
|
||||
..addOption('total-shards',
|
||||
help: 'Tests can be sharded with the "--total-shards" and "--shard-index" '
|
||||
'arguments, allowing you to split up your test suites and run '
|
||||
'them separately.'
|
||||
)
|
||||
..addOption('shard-index',
|
||||
help: 'Tests can be sharded with the "--total-shards" and "--shard-index" '
|
||||
'arguments, allowing you to split up your test suites and run '
|
||||
'them separately.'
|
||||
)
|
||||
..addFlag('enable-vmservice',
|
||||
defaultsTo: false,
|
||||
hide: !verboseHelp,
|
||||
@@ -265,6 +275,27 @@ class TestCommand extends FlutterCommand {
|
||||
];
|
||||
}
|
||||
|
||||
final int shardIndex = int.tryParse(stringArg('shard-index') ?? '');
|
||||
if (shardIndex != null && (shardIndex < 0 || !shardIndex.isFinite)) {
|
||||
throwToolExit(
|
||||
'Could not parse --shard-index=$shardIndex argument. It must be an integer greater than -1.');
|
||||
}
|
||||
|
||||
final int totalShards = int.tryParse(stringArg('total-shards') ?? '');
|
||||
if (totalShards != null && (totalShards <= 0 || !totalShards.isFinite)) {
|
||||
throwToolExit(
|
||||
'Could not parse --total-shards=$totalShards argument. It must be an integer greater than zero.');
|
||||
}
|
||||
|
||||
if (totalShards != null && shardIndex == null) {
|
||||
throwToolExit(
|
||||
'If you set --total-shards you need to also set --shard-index.');
|
||||
}
|
||||
if (shardIndex != null && totalShards == null) {
|
||||
throwToolExit(
|
||||
'If you set --shard-index you need to also set --total-shards.');
|
||||
}
|
||||
|
||||
final bool machine = boolArg('machine');
|
||||
CoverageCollector collector;
|
||||
if (boolArg('coverage') || boolArg('merge-coverage')) {
|
||||
@@ -314,6 +345,8 @@ class TestCommand extends FlutterCommand {
|
||||
reporter: stringArg('reporter'),
|
||||
timeout: stringArg('timeout'),
|
||||
runSkipped: boolArg('run-skipped'),
|
||||
shardIndex: shardIndex,
|
||||
totalShards: totalShards,
|
||||
);
|
||||
|
||||
if (collector != null) {
|
||||
|
||||
@@ -51,6 +51,8 @@ abstract class FlutterTestRunner {
|
||||
String reporter,
|
||||
String timeout,
|
||||
bool runSkipped = false,
|
||||
int shardIndex,
|
||||
int totalShards,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -83,6 +85,8 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
|
||||
String reporter,
|
||||
String timeout,
|
||||
bool runSkipped = false,
|
||||
int shardIndex,
|
||||
int totalShards,
|
||||
}) async {
|
||||
// Configure package:test to use the Flutter engine for child processes.
|
||||
final String shellPath = globals.artifacts.getArtifactPath(Artifact.flutterTester);
|
||||
@@ -112,6 +116,10 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
|
||||
...<String>['--exclude-tags', excludeTags],
|
||||
if (runSkipped)
|
||||
'--run-skipped',
|
||||
if (totalShards != null)
|
||||
'--total-shards=$totalShards',
|
||||
if (shardIndex != null)
|
||||
'--shard-index=$shardIndex',
|
||||
];
|
||||
if (web) {
|
||||
final String tempBuildDir = globals.fs.systemTempDirectory
|
||||
|
||||
@@ -59,6 +59,52 @@ void main() {
|
||||
Cache: () => FakeCache(),
|
||||
});
|
||||
|
||||
group('shard-index and total-shards', () {
|
||||
testUsingContext('with the params they are Piped to package:test',
|
||||
() async {
|
||||
final FakePackageTest fakePackageTest = FakePackageTest();
|
||||
|
||||
final TestCommand testCommand = TestCommand(testWrapper: fakePackageTest);
|
||||
final CommandRunner<void> commandRunner =
|
||||
createTestCommandRunner(testCommand);
|
||||
|
||||
await commandRunner.run(const <String>[
|
||||
'test',
|
||||
'--total-shards=1',
|
||||
'--shard-index=2',
|
||||
'--no-pub',
|
||||
]);
|
||||
|
||||
expect(fakePackageTest.lastArgs, contains('--total-shards=1'));
|
||||
expect(fakePackageTest.lastArgs, contains('--shard-index=2'));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
Cache: () => FakeCache(),
|
||||
});
|
||||
|
||||
testUsingContext('without the params they not Piped to package:test',
|
||||
() async {
|
||||
final FakePackageTest fakePackageTest = FakePackageTest();
|
||||
|
||||
final TestCommand testCommand = TestCommand(testWrapper: fakePackageTest);
|
||||
final CommandRunner<void> commandRunner =
|
||||
createTestCommandRunner(testCommand);
|
||||
|
||||
await commandRunner.run(const <String>[
|
||||
'test',
|
||||
'--no-pub',
|
||||
]);
|
||||
|
||||
expect(fakePackageTest.lastArgs, isNot(contains('--total-shards')));
|
||||
expect(fakePackageTest.lastArgs, isNot(contains('--shard-index')));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
Cache: () => FakeCache(),
|
||||
});
|
||||
});
|
||||
|
||||
testUsingContext('Supports coverage and machine', () async {
|
||||
final FakePackageTest fakePackageTest = FakePackageTest();
|
||||
|
||||
@@ -216,6 +262,8 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
|
||||
String reporter,
|
||||
String timeout,
|
||||
bool runSkipped = false,
|
||||
int shardIndex,
|
||||
int totalShards,
|
||||
}) async {
|
||||
lastEnableObservatoryValue = enableObservatory;
|
||||
return exitCode;
|
||||
|
||||
Reference in New Issue
Block a user