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

Unified Diff: tools/testing/dart/test_suite.dart

Issue 9834070: Shard tests run by test.dart, so they can be distributed to multiple machines. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 9 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
Index: tools/testing/dart/test_suite.dart
diff --git a/tools/testing/dart/test_suite.dart b/tools/testing/dart/test_suite.dart
index da9cf11dc32fed1174b597f7f898487c59593f6a..61558e4ef9463641000b254910432811ef217049 100644
--- a/tools/testing/dart/test_suite.dart
+++ b/tools/testing/dart/test_suite.dart
@@ -245,6 +245,22 @@ class StandardTestSuite implements TestSuite {
// this suite.
if (!testCache.containsKey(suiteName)) {
cachedTests = testCache[suiteName] = [];
+ if (configuration['shards'] > 1) {
+ // If we are sharding tests, we do not enqueue them as they are
+ // found in the directory listing. We add all the tests to the
+ // testCache, then delete all but this shard's tests from the
+ // cache. The doDone function then enqueues the tests from the
+ // cache, and other configurations also use the shard from the
+ // cache.
+ Function oldDone = doDone;
+ doDone = () {
+ testCache[suiteName] = shardTests();
+ for (var info in testCache[suiteName]) {
+ enqueueTestCaseFromTestInformation(info);
+ }
+ oldDone();
+ };
+ }
processDirectory();
} else {
// We rely on enqueueing completing asynchronously so use a
@@ -389,7 +405,10 @@ class StandardTestSuite implements TestSuite {
hasRuntimeErrors,
multitestOutcome);
cachedTests.add(info);
- enqueueTestCaseFromTestInformation(info);
+ if (configuration['shards'] == 1) {
+ // If we are not sharding, we queue the tests as we find them.
+ enqueueTestCaseFromTestInformation(info);
+ }
};
}
@@ -872,6 +891,24 @@ class StandardTestSuite implements TestSuite {
"numStaticTypeAnnotations": numStaticTypeAnnotations,
"numCompileTimeAnnotations": numCompileTimeAnnotations};
}
+
+ /**
+ * shardTests takes the list of tests, stored as the List<TestInformation>
+ * cachedTests, and selects only the tests belonging to this shard.
+ * The tests are sorted by filename, and if there are n shards and we are
+ * shard number i, only the tests at indices equal to i-1 modulo n are kept.
+ */
+ List<TestInformation> shardTests() {
+ cachedTests.sort((TestInformation a, TestInformation b) => a.filename.compareTo(b.filename));
+ int n = configuration['shards'];
+ int i = configuration['shard'];
+ if (n >= 2) {
+ int current = 0;
+ // The test function given to cachedTests.filter uses the entry's index.
+ cachedTests = cachedTests.filter((t) => ((++current % n) == i - 1));
+ }
+ return cachedTests;
+ }
}
« tools/testing/dart/test_options.dart ('K') | « tools/testing/dart/test_options.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698