diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2016-09-02 18:09:55 -0400 |
---|---|---|
committer | Tess Avitabile <tess.avitabile@mongodb.com> | 2016-09-07 13:48:14 -0400 |
commit | ebb07d13b13beeefa589a9daf2db2b655b7e71ca (patch) | |
tree | 1c754c75be6e58a1ce0b1ef77c468484379c1c35 /jstests/hooks | |
parent | b5277068ff66e7fe2b2a98144aa6993ca6e17f5c (diff) | |
download | mongo-ebb07d13b13beeefa589a9daf2db2b655b7e71ca.tar.gz |
SERVER-25889 Collection validation should fail if featureCompatibilityVersion is 3.2 and the collection contains NumberDecimal values
Diffstat (limited to 'jstests/hooks')
-rw-r--r-- | jstests/hooks/validate_collections.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/jstests/hooks/validate_collections.js b/jstests/hooks/validate_collections.js index eac734b4d61..89c7f73e798 100644 --- a/jstests/hooks/validate_collections.js +++ b/jstests/hooks/validate_collections.js @@ -13,6 +13,19 @@ function validateCollections(db, obj) { } } + function getFeatureCompatibilityVersion(adminDB) { + var res = adminDB.system.version.findOne({_id: "featureCompatibilityVersion"}); + if (res === null) { + return "3.2"; + } + return res.version; + } + + function setFeatureCompatibilityVersion(adminDB, version) { + assert.commandWorked(adminDB.runCommand({setFeatureCompatibilityVersion: version})); + assert.eq(version, getFeatureCompatibilityVersion(adminDB)); + } + assert.eq(typeof db, 'object', 'Invalid `db` object, is the shell connected to a mongod?'); assert.eq(typeof obj, 'object', 'The `obj` argument must be an object'); assert(obj.hasOwnProperty('full'), 'Please specify whether to use full validation'); @@ -21,6 +34,17 @@ function validateCollections(db, obj) { var success = true; + var adminDB = db.getSiblingDB("admin"); + + // Set the featureCompatibilityVersion to its required value for performing validation. Save the + // original value. + var originalFeatureCompatibilityVersion; + if (jsTest.options().forceValidationWithFeatureCompatibilityVersion) { + originalFeatureCompatibilityVersion = getFeatureCompatibilityVersion(adminDB); + setFeatureCompatibilityVersion( + adminDB, jsTest.options().forceValidationWithFeatureCompatibilityVersion); + } + // Don't run validate on view namespaces. let listCollectionsRes = db.runCommand({listCollections: 1, filter: {"type": "collection"}}); if (jsTest.options().skipValidationOnInvalidViewDefinitions && listCollectionsRes.ok === 0) { @@ -42,5 +66,11 @@ function validateCollections(db, obj) { success = false; } } + + // Restore the original value for featureCompatibilityVersion. + if (jsTest.options().forceValidationWithFeatureCompatibilityVersion) { + setFeatureCompatibilityVersion(adminDB, originalFeatureCompatibilityVersion); + } + return success; } |