summaryrefslogtreecommitdiff
path: root/jstests/replsets/stepup_increments_config_term.js
blob: 35beea67f47d90e030e92aca8bbe8521205f5e59 (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
/**
 * Test that step-up increments the config term via reconfig.
 */
(function() {
'use strict';

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

var name = 'stepup_increments_config_term';
var replTest = new ReplSetTest({name: name, nodes: 3, settings: {chainingAllowed: false}});

replTest.startSet();
replTest.initiate();

var primary = replTest.getPrimary();

// The original config should have the valid "version" and "term" fields.
const originalConfig = replTest.getReplSetConfigFromNode();
assert.gt(originalConfig.version, 0);
assert.gt(originalConfig.term, -1);

replTest.awaitReplication();
jsTestLog("Trying to step down primary.");
assert.commandWorked(primary.adminCommand({replSetStepDown: 60, secondaryCatchUpPeriodSecs: 60}));

jsTestLog("Waiting for PRIMARY(" + primary.host + ") to step down & become SECONDARY.");
replTest.waitForState(primary, ReplSetTest.State.SECONDARY);

// Wait until the config has propagated to the secondary and the primary has learned of it, so that
// the config replication check is satisfied.
assert.soon(() => isConfigCommitted(replTest.getPrimary()));

const config = replTest.getReplSetConfigFromNode();
const msg = "Original config: " + tojson(originalConfig) + " current config: " + tojson(config);

// Stepup runs a reconfig with the same config version but higher config term.
assert.eq(originalConfig.version, config.version, msg);
assert.eq(originalConfig.term + 1, config.term, msg);

replTest.stopSet();
}());