summaryrefslogtreecommitdiff
path: root/jstests/multiVersion/genericSetFCVUsage/rsm_topology_change_fcv.js
blob: 02b8345400018ac15c263cdaa8cce2fde8601ecd (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 minWireVersion and maxWireVersion in StreamableReplicaSetMonitor's
 * TopologyDescription are correct before and after FCV changes.
 */
(function() {
'use strict';

/*
 * Returns a regex for the topology change log message for the given replica set where
 * all nodes have the given minWireVersion and maxWireVersion.
 */
function makeTopologyChangeLogMsgRegex(rs, minWireVersion, maxWireVersion) {
    return new RegExp(
        `Topology Change.*${rs.name}` +
        `.*minWireVersion: ${minWireVersion}.*maxWireVersion: ${maxWireVersion}`.repeat(
            rs.nodes.length));
}

function runTest(downgradeFCV) {
    jsTestLog("Running test with downgradeFCV: " + downgradeFCV);
    const st = new ShardingTest(
        {mongos: [{setParameter: {replicaSetMonitorProtocol: "sdam"}}], config: 1, shards: 0});

    const latestWireVersion = st.configRS.getPrimary().getMaxWireVersion();
    const downgradedWireVersion = downgradeFCV === lastContinuousFCV
        ? latestWireVersion - 1
        : latestWireVersion - numVersionsSinceLastLTS;
    const downgradeRegex =
        makeTopologyChangeLogMsgRegex(st.configRS, downgradedWireVersion, latestWireVersion);
    const latestRegex =
        makeTopologyChangeLogMsgRegex(st.configRS, latestWireVersion, latestWireVersion);

    jsTest.log(
        "Verify that the RSM on the mongos sees that the config server node has the latest wire version");
    checkLog.contains(st.s, latestRegex);

    jsTest.log("Downgrade FCV and verify that the RSM on the mongos detects the topology change");
    assert.commandWorked(st.s.adminCommand({clearLog: 'global'}));
    assert.commandWorked(st.s.adminCommand({setFeatureCompatibilityVersion: downgradeFCV}));
    checkLog.contains(st.s, downgradeRegex);

    jsTest.log("Upgrade FCV and verify that the RSM on the mongos detects the topology change");
    assert.commandWorked(st.s.adminCommand({clearLog: 'global'}));
    assert.commandWorked(st.s.adminCommand({setFeatureCompatibilityVersion: latestFCV}));
    checkLog.contains(st.s, latestRegex);

    st.stop();
}

runTest(lastContinuousFCV);
runTest(lastLTSFCV);
})();