summaryrefslogtreecommitdiff
path: root/jstests/replsets/freeze_timeout.js
blob: 498d190b1ec014ea441d9d060e0fe6057bfcd1a0 (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
/**
 * Tests that the freezeTimeout election reason counter in serverStatus is incremented in a single
 * node replica set both after a freeze timeout and after a stepdown timeout expires.
 */
(function() {
    "use strict";
    load('jstests/replsets/libs/election_metrics.js');

    jsTestLog('1: initialize single node replica set');
    const replSet = new ReplSetTest({name: 'freeze_timeout', nodes: 1});
    const nodes = replSet.startSet();
    const config = replSet.getReplSetConfig();
    replSet.initiate(config);
    replSet.awaitReplication();
    let primary = replSet.getPrimary();
    const initialPrimaryStatus = assert.commandWorked(primary.adminCommand({serverStatus: 1}));

    jsTestLog('2: step down primary');
    assert.commandWorked(primary.getDB("admin").runCommand({replSetStepDown: 10, force: 1}));

    jsTestLog('3: wait for stepped down node to become primary again');
    primary = replSet.getPrimary();

    // Check that both the 'called' and 'successful' fields of the 'freezeTimeout' election reason
    // counter have been incremented in serverStatus. When a stepdown timeout expires in a single
    // node replica set, an election is called for the same reason as is used when a freeze timeout
    // expires.
    let newPrimaryStatus = assert.commandWorked(primary.adminCommand({serverStatus: 1}));
    verifyServerStatusElectionReasonCounterChange(
        initialPrimaryStatus.electionMetrics, newPrimaryStatus.electionMetrics, "freezeTimeout", 1);

    jsTestLog('4: step down primary again');
    assert.commandWorked(primary.getDB("admin").runCommand({replSetStepDown: 10, force: 1}));

    jsTestLog('5: freeze stepped down primary for 30 seconds');
    primary.getDB("admin").runCommand({replSetFreeze: 30});
    sleep(1000);

    jsTestLog('6: unfreeze stepped down primary after waiting for 1 second');
    primary.getDB("admin").runCommand({replSetFreeze: 0});

    jsTestLog('7: wait for unfrozen node to become primary again');
    primary = replSet.getPrimary();

    // Check that both the 'called' and 'successful' fields of the 'freezeTimeout' election reason
    // counter have been incremented again in serverStatus.
    newPrimaryStatus = assert.commandWorked(primary.adminCommand({serverStatus: 1}));
    verifyServerStatusElectionReasonCounterChange(
        initialPrimaryStatus.electionMetrics, newPrimaryStatus.electionMetrics, "freezeTimeout", 2);

    replSet.stopSet();
})();