Skip to content
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
6d4361c
Add support for the --shard-by flag along with documentation and comp…
sigurdm May 26, 2026
123f404
dartfmt
sigurdm May 26, 2026
f5d7f19
revert formatting changes
sigurdm May 26, 2026
bf785f1
revert formatting changes2
sigurdm May 26, 2026
fa12902
CHANGELOGS
sigurdm May 26, 2026
7de7f39
Update test expectation
sigurdm May 26, 2026
2be2362
Add --shard-by-file flag, update docs and tests
sigurdm Jun 9, 2026
2783cf9
Merge branch 'master' into shard-by-file-docs-and-tests
sigurdm Jun 9, 2026
5b20f67
Make 'invalid option' test robust to package:args error format changes
sigurdm Jun 9, 2026
73b577f
Merge branch 'shard-by-file-docs-and-tests' of https://github.com/dar…
sigurdm Jun 9, 2026
12ad62a
Address PR feedback: rename to --shard-by-suite, round-robin distribu…
sigurdm Jun 29, 2026
7f86040
Revert invalid option test flexibility to strict expectStderrEquals e…
sigurdm Jun 29, 2026
081d9db
Revert formatting-only changes in expanded_reporter_test.dart, platfo…
sigurdm Jun 29, 2026
e55d3d7
Update --shard-by-suite help text description
sigurdm Jun 29, 2026
d51bd10
Format pkgs/test for dart format CI compliance
sigurdm Jun 30, 2026
86d3aee
Apply dev SDK formatter rules for CI compliance
sigurdm Jun 30, 2026
dbdbf82
Remove extra newline in pkgs/test/CHANGELOG.md
sigurdm Jun 30, 2026
57e8225
Rephrase README description to 'projects with many small test suites'
sigurdm Jun 30, 2026
ac341e5
Adopt Nate's suggested phrasing for test filter interactions in READM…
sigurdm Jun 30, 2026
46ced91
Merge remote-tracking branch 'origin/master' into shard-by-file-docs-…
sigurdm Jun 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkgs/test/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
all tests with OS `'windows'` would previously still run browser tests on
windows, but will now skip all tests including browser tests.
* Use a DevTools URL instead of a defunct observatory URL.
* Add flag `--shard-by-suite` to control sharding strategy.
* Disable throttling in chrome launch arguments.
* Allow package_config `3.x.x`.


## 1.31.1

* Ignore an error locating the SDK directory on platforms where the
Expand Down
38 changes: 32 additions & 6 deletions pkgs/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,38 @@ dart test --total-shards 3 --shard-index 0 path/to/test.dart
dart test --total-shards 3 --shard-index 1 path/to/test.dart
dart test --total-shards 3 --shard-index 2 path/to/test.dart
```
Sharding: This refers to the process of splitting up a large test suite into
smaller subsets (called shards) that can be run independently. Sharding is
particularly useful for distributed testing, where multiple machines are used
to run tests simultaneously. By dividing the test suite into smaller subsets,
you can run tests in parallel across multiple machines, which can significantly
reduce the overall testing time.

By default, sharding is done by individual tests within each suite.
You can shard by entire test suites (files) using the `--shard-by-suite` flag.

* When sharding by test (default): Distribute individual test cases across
shards. This balances the test load at the test case level. Test cases from
each suite are sliced continuously, which minimizes how often a suite is
split across shards and helps maximize the re-use of suite `setUpAll` and
`tearDownAll` setups.
* When sharding by suite (using `--shard-by-suite`): Distribute entire test suites
across shards. This can be faster for suites with many small suites as it
avoids loading every suite in every shard. Because test suites are not split,
any `setUpAll` and `tearDownAll` setups within a suite (including shared helper setups imported across suites) run only on the shard executing that suite.

Sharding is particularly useful for distributed testing, where multiple
machines are used to run tests simultaneously. By dividing the test suite into
smaller subsets, you can run tests in parallel across multiple machines, which
can significantly reduce the overall testing time.

### Interaction with Test Filters

The sharding modes interact differently with filters like `--name` or `--tags`:

* When sharding by test (default), the sharding partition is calculated *after*
applying filters. This guarantees that the matching tests are distributed
as evenly as possible across all shards.
* When sharding by suite (using `--shard-by-suite`), suite-level annotations
(such as `@TestOn` platform selectors and suite-level `@Tags`) are evaluated
before suite sharding, filtering out non-matching suites so shards do not receive
empty workloads. In contrast, test-case/group filters (such as `--name` or test-level tags)
operate on test cases within loaded suites after sharding. If a test-case filter only matches tests in a
few suites, some shards might run no tests because those suites were allocated to other shards.

### Test concurrency

Expand Down
1 change: 1 addition & 0 deletions pkgs/test/test/runner/runner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ $_runtimeCompilers
(defaults to "$_defaultConcurrency")
--total-shards The total number of invocations of the test runner being run.
--shard-index The index of this test runner invocation (of --total-shards).
--shard-by-suite Distribute entire test suites (_test.dart files) across shards instead of individual tests.
--timeout The default test timeout. For example: 15s, 2x, none
(defaults to "30s")
--suite-load-timeout The timeout for loading a test suite. Loading the test suite includes compiling the test suite. For example: 15s, 2m, none
Expand Down
Loading
Loading