summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEddie Louie <eddie.louie@mongodb.com>2017-10-25 16:54:29 -0400
committerEddie Louie <eddie.louie@mongodb.com>2017-11-06 21:21:50 -0500
commitb7b606259d712fcb7248f1c2f45b952ecb529654 (patch)
tree870c8408ded675584ba0f10233df3e622cc426f5
parente7837911c89af144fe012e5063f8ca88c4c66956 (diff)
downloadmongo-r3.6.0-rc3.tar.gz
SERVER-31441 Run validateCollections on each server in parallelr3.6.0-rc3
-rw-r--r--jstests/hooks/run_validate_collections.js56
1 files changed, 45 insertions, 11 deletions
diff --git a/jstests/hooks/run_validate_collections.js b/jstests/hooks/run_validate_collections.js
index 49131c9ebe9..d95c9eb5c9f 100644
--- a/jstests/hooks/run_validate_collections.js
+++ b/jstests/hooks/run_validate_collections.js
@@ -4,7 +4,7 @@
(function() {
assert.eq(typeof db, 'object', 'Invalid `db` object, is the shell connected to a mongod?');
- load('jstests/hooks/validate_collections.js'); // For validateCollections.
+ load('jstests/libs/parallelTester.js');
function getDirectConnections(conn) {
// If conn does not point to a repl set, then this function returns [conn].
@@ -70,17 +70,51 @@
return serverList;
}
- const serverList = getServerList();
- for (let server of serverList) {
- print('Running validate() on ' + server.host);
- server.setSlaveOk();
- jsTest.authenticate(server);
-
- const dbNames = server.getDBNames();
- for (let dbName of dbNames) {
- if (!validateCollections(server.getDB(dbName), {full: true})) {
- throw new Error('Collection validation failed');
+ // Run a separate thread to validate collections on each server in parallel.
+ var validateCollectionsThread = function(host, testData) {
+ load('jstests/hooks/validate_collections.js'); // For validateCollections.
+ TestData = testData; // Pass the TestData object from main thread.
+
+ try {
+ print('Running validate() on ' + host);
+ const conn = new Mongo(host);
+ conn.setSlaveOk();
+ jsTest.authenticate(conn);
+
+ const dbNames = conn.getDBNames();
+ for (let dbName of dbNames) {
+ if (!validateCollections(conn.getDB(dbName), {full: true})) {
+ return {ok: 0};
+ }
}
+ return {ok: 1};
+ } catch (e) {
+ print('Exception caught in scoped thread running validationCollections on server: ' +
+ host);
+ return {ok: 0, error: e.toString(), stack: e.stack};
}
+ };
+
+ // We run the scoped threads in a try/finally block in case any thread throws an exception, in
+ // which case we want to still join all the threads.
+ let threads = [];
+ const serverList = getServerList();
+
+ try {
+ serverList.forEach(server => {
+ const thread = new ScopedThread(validateCollectionsThread, server.host, TestData);
+ threads.push(thread);
+ thread.start();
+ });
+ } finally {
+ // Wait for each thread to finish. Throw an error if any thread fails.
+ const returnData = threads.map(thread => {
+ thread.join();
+ return thread.returnData();
+ });
+
+ returnData.forEach(res => {
+ assert.commandWorked(res, 'Collection validation failed');
+ });
}
})();