0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-24 16:46:00 +01:00
mongodb/jstests/replsets/reconfig_during_election.js
Matt Broadstone 771dabd098 SERVER-81339 Convert ReplSetTest and ShardingTest to modules (#26332)
GitOrigin-RevId: 744aa110a53786b23c62ff53f87a1418b5991e8d
2024-08-20 22:00:49 +00:00

53 lines
1.9 KiB
JavaScript

/**
* SERVER-37255: replSetReconfig runs on a node that is concurrently processing an election win and
* does not result in an invariant.
*/
import {configureFailPoint} from "jstests/libs/fail_point_util.js";
import {ReplSetTest} from "jstests/libs/replsettest.js";
import {ElectionHandoffTest} from "jstests/replsets/libs/election_handoff.js";
const rst = new ReplSetTest({nodes: 2});
const nodes = rst.startSet();
const config = rst.getReplSetConfig();
// Prevent elections and set heartbeat timeout >> electionHangsBeforeUpdateMemberState.
config.settings = {
electionTimeoutMillis: 12 * 60 * 60 * 1000,
heartbeatTimeoutSecs: 60 * 1000
};
rst.initiate(config);
const incumbent = rst.getPrimary();
const candidate = rst.getSecondary();
jsTestLog("Step down");
const failPoint = configureFailPoint(
candidate, "electionHangsBeforeUpdateMemberState", {waitForMillis: 10 * 1000});
// The incumbent sends replSetStepUp to the candidate for election handoff.
assert.commandWorked(incumbent.adminCommand({
replSetStepDown: ElectionHandoffTest.stepDownPeriodSecs,
secondaryCatchUpPeriodSecs: ElectionHandoffTest.stepDownPeriodSecs / 2
}));
jsTestLog("Wait for candidate to win the election");
failPoint.wait();
jsTestLog("Try to interrupt it with a reconfig");
config.members[nodes.indexOf(candidate)].priority = 2;
config.version++;
// While the candidate is stepping up, it it possible for the RstlKillOpThread to kill this reconfig
// command before it succeeds. Failing due to interruption on stepup or the automatic reconfig on
// stepup is acceptable here because we are testing that the reconfig command does not cause the
// server to invariant.
assert.commandWorkedOrFailedWithCode(
candidate.adminCommand({replSetReconfig: config, force: true}),
[ErrorCodes.InterruptedDueToReplStateChange, ErrorCodes.ConfigurationInProgress]);
failPoint.off();
rst.stopSet();