mongo/jstests/replsets/election_handoff_skips_unelectable_nodes.js
Zac 591928c619 SERVER-108478 JS formatted by prettier and remove clang-format (#39656)
GitOrigin-RevId: 6c8f6aded47f260aa4f7c231b17dae3302cb1e04
2025-08-21 17:27:09 +00:00

23 lines
869 B
JavaScript

/*
* Tests that election handoff will not attempt to step up a node that is unelectable.
*/
import {ReplSetTest} from "jstests/libs/replsettest.js";
import {ElectionHandoffTest} from "jstests/replsets/libs/election_handoff.js";
const rst = new ReplSetTest({name: jsTestName(), nodes: 3});
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();
// Freeze one of the secondaries so that it cannot be elected. As a result, the other secondary
// should always be chosen to run for primary via election handoff.
const frozenSecondary = rst.getSecondaries()[0];
assert.commandWorked(frozenSecondary.adminCommand({replSetFreeze: ReplSetTest.kForeverSecs}));
ElectionHandoffTest.testElectionHandoff(rst, 0, 2);
rst.stopSet();