diff options
author | XueruiFa <xuerui.fa@mongodb.com> | 2021-05-28 15:42:32 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-11-17 21:18:28 +0000 |
commit | 7528b1505150fc213f1ea684a5366facb1ffb177 (patch) | |
tree | 37df6aa08890da0b0f43ebb94f97cd4887e05ba6 /jstests | |
parent | 78925b6e570e2df349fe52c04d2f062c58bc7ba8 (diff) | |
download | mongo-7528b1505150fc213f1ea684a5366facb1ffb177.tar.gz |
SERVER-57284: Wait for config commitment in reconfig_for_psa_set_shell.js
(cherry picked from commit 8210bff0c499fb76e6c6149b21ab33df98097d7c)
(cherry picked from commit f9e071ac7fb975daf38d12dee1f25d1655041867)
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/noPassthrough/reconfig_for_psa_set_shell.js | 62 |
1 files changed, 58 insertions, 4 deletions
diff --git a/jstests/noPassthrough/reconfig_for_psa_set_shell.js b/jstests/noPassthrough/reconfig_for_psa_set_shell.js index 2b0ba125432..a40704ffdaf 100644 --- a/jstests/noPassthrough/reconfig_for_psa_set_shell.js +++ b/jstests/noPassthrough/reconfig_for_psa_set_shell.js @@ -8,6 +8,8 @@ (function() { 'use strict'; +load("jstests/replsets/rslib.js"); + // Start up a PSA set with the secondary having 'votes: 0' and 'priority: 0'. const rst = new ReplSetTest({ name: jsTestName(), @@ -29,10 +31,62 @@ let reconfigScript = `assert.commandFailedWithCode(rs.reconfig(${ let result = runMongoProgram('mongo', '--port', primary.port, '--eval', reconfigScript); assert.eq(0, result, `reconfig did not fail with expected error code`); -// Verify that calling 'reconfigForPSASet()' will succeed. -reconfigScript = `assert.commandWorked(rs.reconfigForPSASet(1, ${tojson(config)}))`; -result = runMongoProgram('mongo', '--port', primary.port, '--eval', reconfigScript); -assert.eq(0, result, `reconfig did not succeed as expected`); +const runReconfigForPSASet = (memberIndex, config, shouldSucceed, endPriority = 1) => { + jsTestLog(`Testing with memberIndex ${memberIndex} and config ${tojson(config)}`); + + const reconfigScript = + `assert.commandWorked(rs.reconfigForPSASet(${memberIndex}, ${tojson(config)}))`; + const result = runMongoProgram('mongo', '--port', primary.port, '--eval', reconfigScript); + if (shouldSucceed) { + assert.eq(0, result, 'expected reconfigToPSASet to succeed, but it failed'); + + // Wait for the new config to be committed. + assert.soonNoExcept(() => isConfigCommitted(primary)); + + const replSetGetConfig = + assert.commandWorked(primary.adminCommand({replSetGetConfig: 1})).config; + assert.eq(1, replSetGetConfig.members[1].votes); + assert.eq(endPriority, replSetGetConfig.members[1].priority); + + // Reset the config back to the original config. + originalConfig.members[memberIndex].votes = 0; + originalConfig.members[memberIndex].priority = 0; + const reconfigToOriginalConfig = + `assert.commandWorked(rs.reconfig(${tojson(originalConfig)}))`; + assert.eq( + 0, + runMongoProgram('mongo', '--port', primary.port, '--eval', reconfigToOriginalConfig)); + assert.soonNoExcept(() => isConfigCommitted(primary)); + } else { + assert.neq(0, result, 'expected reconfigToPSASet to fail, but it succeeded'); + } +}; + +// Succeed with a reconfig to a standard PSA set, where the secondary has 'votes: 1' and 'priority: +// 1'. +jsTestLog("Testing reconfigForPSASet() succeeded: standard PSA set"); +runReconfigForPSASet(1, config, true /* shouldSucceed */); + +// Fail when 'memberIndex' does not refer to a node in the new config. +jsTestLog("Testing reconfigForPSASet() failed: memberIndex out of bounds"); +runReconfigForPSASet(3, config, false /* shouldSucceed */); + +// Fail when the node in the new config at 'memberIndex' is not a voter. +jsTestLog("Testing reconfigForPSASet() failed: node at memberIndex is not a voter"); +config.members[1].votes = 0; +config.members[1].priority = 0; +runReconfigForPSASet(1, config, false /* shouldSucceed */); + +// Test that reconfigToPSASet() will succeed when we are adding a new node at a specific +// 'memberIndex'. +jsTestLog("Testing reconfigForPSASet() succeeded: adding new node"); + +// First remove the node at index 1 to simulate a two-node replica set. +config = rst.getReplSetConfigFromNode(); +const filteredMembers = config.members.filter(member => member._id !== 1); +config.members = filteredMembers; +config.version += 1; +assert.commandWorked(primary.adminCommand({replSetReconfig: config})); const replSetGetConfig = assert.commandWorked(primary.adminCommand({replSetGetConfig: 1})).config; assert.eq(1, replSetGetConfig.members[1].votes); |