diff options
-rw-r--r-- | jstests/noPassthrough/index_downgrade_fcv.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/jstests/noPassthrough/index_downgrade_fcv.js b/jstests/noPassthrough/index_downgrade_fcv.js new file mode 100644 index 00000000000..bbc29a5664b --- /dev/null +++ b/jstests/noPassthrough/index_downgrade_fcv.js @@ -0,0 +1,55 @@ +/** + * If a user attempts to downgrade the server while there is an index build in progress, we should + * reject the downgrade request. + * @tags: [requires_replication] + */ +(function() { +"use strict"; + +load('jstests/noPassthrough/libs/index_build.js'); + +const rst = new ReplSetTest({ + nodes: [ + {}, + { + // Disallow elections on secondary. + rsConfig: { + priority: 0, + votes: 0, + }, + }, + ] +}); +const nodes = rst.startSet(); +rst.initiate(); + +const primary = rst.getPrimary(); +const testDB = primary.getDB('test'); +const coll = testDB.getCollection('test'); + +assert.commandWorked(coll.insert({a: 1})); + +IndexBuildTest.pauseIndexBuilds(primary); + +const createIdx = IndexBuildTest.startIndexBuild(primary, coll.getFullName(), {a: 1}); +IndexBuildTest.waitForIndexBuildToScanCollection(testDB, coll.getName(), 'a_1'); + +// Downgrade the primary using the setFeatureCompatibilityVersion command. +try { + assert.commandWorked(primary.adminCommand({setFeatureCompatibilityVersion: lastStableFCV})); +} finally { + IndexBuildTest.resumeIndexBuilds(primary); +} + +IndexBuildTest.waitForIndexBuildToStop(testDB); + +createIdx(); + +IndexBuildTest.assertIndexes(coll, 2, ['_id_', 'a_1']); + +// This confirms that the downgrade command will complete successfully after the index build has +// completed. +assert.commandWorked(primary.adminCommand({setFeatureCompatibilityVersion: lastStableFCV})); + +rst.stopSet(); +})(); |