summaryrefslogtreecommitdiff
path: root/jstests/replsets/stepup.js
blob: 65751b67c41b143a7383f6d1e7415a64dc39184d (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
// Tests the replSetStepUp command.

load("jstests/replsets/rslib.js");

(function() {

    "use strict";
    var name = "stepup";
    var rst = new ReplSetTest({name: name, nodes: 2});

    rst.startSet();
    rst.initiate();
    rst.awaitReplication();

    var primary = rst.getPrimary();
    var secondary = rst.getSecondary();

    // Step up the primary. Return OK because it's already the primary.
    var res = primary.adminCommand({replSetStepUp: 1});
    assert.commandWorked(res);
    assert.eq(primary, rst.getPrimary());

    // Step up the secondary, but it's not eligible to be primary.
    // Enable fail point on secondary.
    assert.commandWorked(secondary.getDB('admin').runCommand(
        {configureFailPoint: 'rsSyncApplyStop', mode: 'alwaysOn'}));

    assert.writeOK(primary.getDB("test").bar.insert({x: 2}, {writeConcern: {w: 1}}));
    res = secondary.adminCommand({replSetStepUp: 1});
    assert.commandFailedWithCode(res, ErrorCodes.CommandFailed);
    assert.commandWorked(
        secondary.getDB('admin').runCommand({configureFailPoint: 'rsSyncApplyStop', mode: 'off'}));

    // Wait for the secondary to catch up by replicating a doc to both nodes.
    assert.writeOK(primary.getDB("test").bar.insert({x: 3}, {writeConcern: {w: "majority"}}));

    // Step up the secondary. Retry since the old primary may step down when we try to ask for its
    // vote.
    assert.soonNoExcept(function() {
        return secondary.adminCommand({replSetStepUp: 1}).ok;
    });

    // Make sure the step up succeeded.
    assert.eq(secondary, rst.getPrimary());

    rst.stopSet();
})();