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

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: 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') | pubspec.yaml » ('J')
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..7449752a6e07939f9966f4074bdafae0a6205fce 100644
--- a/lib/src/runner.dart
+++ b/lib/src/runner.dart
@@ -3,9 +3,12 @@
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
+import 'dart:convert';
kevmoo 2016/04/14 22:50:36 many unused imports Do you use crypto?
import 'dart:io';
+import 'dart:typed_data';
import 'package:async/async.dart';
+import 'package:crypto/crypto.dart';
import 'backend/group.dart';
import 'backend/group_entry.dart';
@@ -244,7 +247,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 +260,7 @@ class Runner {
if (_config.excludeTags.evaluate(test.metadata.tags)) return false;
return true;
- });
+ }));
});
});
}
@@ -337,6 +340,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.
+ void _shardSuite(Suite suite) {
kevmoo 2016/04/14 22:50:36 Suppose to return a Suite, no? Not void...
nweiz 2016/04/22 21:30:53 Done.
+ 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') | pubspec.yaml » ('J')

Powered by Google App Engine
This is Rietveld 408576698