summaryrefslogtreecommitdiff
path: root/jstests/replsets/quiesce_mode_fails_elections.js
blob: be80af8017cbcc653823605c9ae9deb115dde817 (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
52
53
54
55
56
57
58
59
60
61
62
63
/**
 * Test that once a node enters quiesce mode, any concurrent or new elections cannot succeed.
 */
(function() {
"use strict";

load("jstests/libs/fail_point_util.js");
load("jstests/libs/parallel_shell_helpers.js");

const rst = new ReplSetTest({
    name: jsTestName(),
    nodes: 3,
    // Override the quiesce period.
    nodeOptions: {setParameter: "shutdownTimeoutMillisForSignaledShutdown=5000"}
});

rst.startSet();
rst.initiateWithHighElectionTimeout();

const dbName = "test";
const primary = rst.getPrimary();
const secondary = rst.getSecondaries()[0];
const primaryDB = primary.getDB(dbName);

assert.commandWorked(
    primaryDB.coll.insert([{_id: 0, data: "initial data"}], {writeConcern: {w: "majority"}}));
rst.awaitReplication();

jsTestLog("Make the secondary hang before processing real election vote result.");
let voteRequestCompleteFailPoint =
    configureFailPoint(secondary, "hangBeforeOnVoteRequestCompleteCallback");

jsTestLog("Stepping up the secondary.");
const awaitStepUp = startParallelShell(() => {
    assert.commandFailedWithCode(db.adminCommand({replSetStepUp: 1}), ErrorCodes.CommandFailed);
}, secondary.port);

// Wait for secondary to hit the failpoint. Even though the election on secondary has not finished,
// the primary should step down due to seeing a higher term.
voteRequestCompleteFailPoint.wait();
rst.waitForState(primary, ReplSetTest.State.SECONDARY);

jsTestLog("Make the secondary hang after entering quiesce mode.");
let quiesceModeFailPoint = configureFailPoint(secondary, "hangDuringQuiesceMode");
rst.stop(secondary, null /*signal*/, {skipValidation: true}, {forRestart: true, waitpid: false});
quiesceModeFailPoint.wait();

jsTestLog("Unblock secondary election, the in-progress step up attempt should be cancelled");
voteRequestCompleteFailPoint.off();
awaitStepUp();
// Check log line with id 214480: "Not becoming primary, election has been cancelled".
checkLog.checkContainsOnceJson(secondary, 214480);

jsTestLog("Attempting another stepup should fail immediately due to being in quiesce mode");
assert.commandFailedWithCode(secondary.adminCommand({replSetStepUp: 1}), ErrorCodes.CommandFailed);
// Check log line with id 4615654: "Not starting an election, since we are shutting down".
checkLog.checkContainsOnceJson(secondary, 4615654);

jsTestLog("Unblock the secondary from quiesce mode");
quiesceModeFailPoint.off();

rst.stopSet();
})();