summaryrefslogtreecommitdiff
path: root/jstests/hooks
diff options
context:
space:
mode:
authorRobert Guo <robertguo@me.com>2016-06-22 17:49:36 -0400
committerRobert Guo <robertguo@me.com>2016-06-28 18:24:19 -0400
commit16862a19349be0956b2c093f691b0cd2dc7f20fd (patch)
treeafc96343589d5de80128e8b9da2fc1a7fe472f95 /jstests/hooks
parentc162f4ba10643f21a88536d1b01dff8dc94349df (diff)
downloadmongo-16862a19349be0956b2c093f691b0cd2dc7f20fd.tar.gz
SERVER-22105 run the validation hook on secondary nodes
Diffstat (limited to 'jstests/hooks')
-rw-r--r--jstests/hooks/run_validate_collections.js31
1 files changed, 26 insertions, 5 deletions
diff --git a/jstests/hooks/run_validate_collections.js b/jstests/hooks/run_validate_collections.js
index 1e910b3e6cf..28198136774 100644
--- a/jstests/hooks/run_validate_collections.js
+++ b/jstests/hooks/run_validate_collections.js
@@ -6,11 +6,32 @@
assert.eq(typeof db, 'object', 'Invalid `db` object, is the shell connected to a mongod?');
load('jstests/hooks/validate_collections.js'); // For validateCollections
- var dbNames = db.getMongo().getDBNames();
+ var serverList = [];
+ serverList.push(db.getMongo());
- for (var dbName of dbNames) {
- if (!validateCollections(db.getSiblingDB(dbName), {full: true})) {
- throw new Error('Collection validation failed');
+ var addSecondaryNodes = function() {
+ var cmdLineOpts = db.adminCommand('getCmdLineOpts');
+ assert.commandWorked(cmdLineOpts);
+
+ if (cmdLineOpts.parsed.hasOwnProperty('replication') &&
+ cmdLineOpts.parsed.replication.hasOwnProperty('replSet')) {
+ var rst = new ReplSetTest(db.getMongo().host);
+ // Call getPrimary to populate rst with information about the nodes.
+ var primary = rst.getPrimary();
+ assert(primary, 'calling getPrimary() failed');
+ serverList.push(...rst.getSecondaries());
+ }
+ };
+
+ addSecondaryNodes();
+
+ for (var server of serverList) {
+ print('Running validate() on ' + server.host);
+ var dbNames = server.getDBNames();
+ for (var dbName of dbNames) {
+ if (!validateCollections(db.getSiblingDB(dbName), {full: true})) {
+ throw new Error('Collection validation failed');
+ }
}
}
-})(); \ No newline at end of file
+})();