Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Unified Diff: lib/src/runner.dart

Issue 1890853003: Add support for sharding test runs. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/src/runner/configuration.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/runner.dart
diff --git a/lib/src/runner.dart b/lib/src/runner.dart
index 3a5ce38c3f3e676ff762839027522054401c1d52..f6a66d44380b6acb1fded72b4da28842d1c2a7c2 100644
--- a/lib/src/runner.dart
+++ b/lib/src/runner.dart
@@ -244,7 +244,7 @@ class Runner {
return loadSuite.changeSuite((suite) {
_warnForUnknownTags(suite);
- return suite.filter((test) {
+ return _shardSuite(suite.filter((test) {
// Skip any tests that don't match all the given patterns.
if (!_config.patterns.every(test.name.contains)) {
return false;
@@ -257,7 +257,7 @@ class Runner {
if (_config.excludeTags.evaluate(test.metadata.tags)) return false;
return true;
- });
+ }));
});
});
}
@@ -337,6 +337,29 @@ class Runner {
return 'the suite itself';
}
+ /// If sharding is enabled, filters [suite] to only include the tests that
+ /// should be run in this shard.
+ ///
+ /// We just take a slice of the tests in each suite corresponding to the shard
+ /// index. This makes the tests pretty tests across shards, and since the
+ /// tests are continuous, makes us more likely to be able to re-use
+ /// `setUpAll()` logic.
+ Suite _shardSuite(Suite suite) {
+ if (_config.totalShards == null) return suite;
+
+ var shardSize = suite.group.testCount / _config.totalShards;
+ var shardStart = (shardSize * _config.shardIndex).round();
+ var shardEnd = (shardSize * (_config.shardIndex + 1)).round();
+
+ var count = -1;
+ var filtered = suite.filter((test) {
+ count++;
+ return count >= shardStart && count < shardEnd;
+ });
+
+ return filtered;
+ }
+
/// Loads each suite in [suites] in order, pausing after load for platforms
/// that support debugging.
Future<bool> _loadThenPause(Stream<LoadSuite> suites) async {
« no previous file with comments | « no previous file | lib/src/runner/configuration.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698