summaryrefslogtreecommitdiff
path: root/jstests/replsets/reconfig_during_election.js
blob: b73303bd60dbb80f86382a261c92c8a7f3a207eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
 * SERVER-37255: replSetReconfig runs on a node that is concurrently processing an election win.
 */

(function() {
"use strict";
load("jstests/replsets/libs/election_handoff.js");

const rst = 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");

assert.commandWorked(candidate.adminCommand({
    configureFailPoint: "electionHangsBeforeUpdateMemberState",
    mode: "alwaysOn",
    data: {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");

checkLog.contains(candidate,
                  "election succeeded - electionHangsBeforeUpdateMemberState fail point enabled");

jsTestLog("Try to interrupt it with a reconfig");

config.members[nodes.indexOf(candidate)].priority = 2;
config.version++;
assert.commandWorked(candidate.adminCommand({replSetReconfig: config, force: true}));

assert.commandWorked(candidate.adminCommand(
    {configureFailPoint: "electionHangsBeforeUpdateMemberState", mode: "off"}));

rst.stopSet();
})();