diff options
author | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2018-08-23 15:54:59 -0400 |
---|---|---|
committer | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2018-08-27 18:44:05 -0400 |
commit | bdb7951bc48accda8368f5893bdf2627fc2588bf (patch) | |
tree | eefb70e0f1a89ddf85dc992c8b5c987fc2587d66 /jstests/hooks/validate_collections.js | |
parent | 4d124b7f3634da1fc5230bf18662a1004054a8ff (diff) | |
download | mongo-bdb7951bc48accda8368f5893bdf2627fc2588bf.tar.gz |
SERVER-36718 Add forceValidationWithFeatureCompatibilityVersion to collection validation hook
Diffstat (limited to 'jstests/hooks/validate_collections.js')
-rw-r--r-- | jstests/hooks/validate_collections.js | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/jstests/hooks/validate_collections.js b/jstests/hooks/validate_collections.js index fc1ffed3ea1..dec184ce78d 100644 --- a/jstests/hooks/validate_collections.js +++ b/jstests/hooks/validate_collections.js @@ -30,7 +30,7 @@ function CollectionValidator() { let full_res = {ok: 1, failed_res: []}; // Don't run validate on view namespaces. - let filter = {type: "collection"}; + let filter = {type: 'collection'}; if (jsTest.options().skipValidationOnInvalidViewDefinitions) { // If skipValidationOnInvalidViewDefinitions=true, then we avoid resolving the view // catalog on the admin database. @@ -57,7 +57,7 @@ function CollectionValidator() { let collInfo = db.getCollectionInfos(filter); for (let collDocument of collInfo) { - const coll = db.getCollection(collDocument["name"]); + const coll = db.getCollection(collDocument['name']); const res = coll.validate(full); if (!res.ok || !res.valid) { @@ -93,6 +93,16 @@ function CollectionValidator() { conn.setSlaveOk(); jsTest.authenticate(conn); + if (jsTest.options().forceValidationWithFeatureCompatibilityVersion) { + let adminDB = conn.getDB('admin'); + // Make sure this node has the desired FCV. + assert.soon(() => { + return adminDB.system.version.findOne({_id: 'featureCompatibilityVersion'}) + .version === + jsTest.options().forceValidationWithFeatureCompatibilityVersion; + }); + } + const dbNames = conn.getDBNames(); for (let dbName of dbNames) { if (!validatorFunc(conn.getDB(dbName), {full: true})) { @@ -107,10 +117,25 @@ function CollectionValidator() { } }; - this.validateNodes = function(hostList) { + this.validateNodes = function(hostList, setFCVHost) { // 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 = []; + let adminDB; + let originalFCV; + + if (jsTest.options().forceValidationWithFeatureCompatibilityVersion) { + let conn = new Mongo(setFCVHost); + adminDB = conn.getDB('admin'); + originalFCV = + adminDB.system.version.findOne({_id: 'featureCompatibilityVersion'}).version; + if (originalFCV !== jsTest.options().forceValidationWithFeatureCompatibilityVersion) { + assert.commandWorked(adminDB.adminCommand({ + setFeatureCompatibilityVersion: + jsTest.options().forceValidationWithFeatureCompatibilityVersion + })); + } + } try { hostList.forEach(host => { @@ -130,6 +155,10 @@ function CollectionValidator() { assert.commandWorked(res, 'Collection validation failed'); }); } + + if (jsTest.options().forceValidationWithFeatureCompatibilityVersion !== originalFCV) { + assert.commandWorked(adminDB.runCommand({setFeatureCompatibilityVersion: originalFCV})); + } }; } |