mongo/jstests/replsets/election_handoff_not_immedi...

29 lines
1.3 KiB
JavaScript

/**
* Test that election handoff works correctly in the case where a node is caught up with primary's
* lastApplied but is not immediately electable. (See SERVER-53612)
*/
import {ReplSetTest} from "jstests/libs/replsettest.js";
import {ElectionHandoffTest} from "jstests/replsets/libs/election_handoff.js";
const testName = jsTestName();
const rst = new ReplSetTest({name: testName, nodes: 2});
rst.startSet();
// Make sure there are no election timeouts firing for the duration of the test. This helps
// ensure that the test will only pass if the election handoff succeeds.
rst.initiate();
rst.awaitLastOpCommitted();
// ElectionHandoffTest.testElectionHandoff uses a 30s secondaryCatchUpPeriodSecs, freeze the
// secondary for 15s so that the secondary is not immediately electable during election handoff.
const secondary = rst.getSecondary();
assert.commandWorked(secondary.adminCommand({replSetFreeze: 15}));
// replSetStepUp should fail due to replSetFreeze.
assert.commandFailedWithCode(secondary.adminCommand({replSetStepUp: 1}), ErrorCodes.CommandFailed);
// Test that the election handoff works eventually when the secondary node becomes electable.
ElectionHandoffTest.testElectionHandoff(rst, 0, 1, {stepDownPeriodSecs: 30, secondaryCatchUpPeriodSecs: 30});
rst.stopSet();