summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/read_write_concern_defaults_startup.js
blob: 1e58517ed1fdc3aa12f94fa4c93915460162b74d (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
53
54
55
56
57
58
59
60
61
62
63
64
65
// Verifies read/write concern defaults are loaded at startup by a mongos and non-sharded replica
// set node.
//
// This test restarts a replica set node, which requires persistence and journaling.
// @tags: [requires_sharding, requires_persistence, requires_journaling]
(function() {
"use strict";

function runTest(conn, failPointConn, restartFn) {
    // Set a default rwc.
    assert.commandWorked(
        conn.adminCommand({setDefaultRWConcern: 1, defaultReadConcern: {level: "majority"}}));
    let res = assert.commandWorked(conn.adminCommand({getDefaultRWConcern: 1}));
    assert.eq(res.defaultReadConcern, {level: "majority"});

    // Restart the node with disabled rwc refreshes.
    restartFn();
    reconnect(conn);
    reconnect(failPointConn);

    // Verify the server attempted to load the defaults at startup.
    checkLog.contains(conn, "Failed to load read and write concern defaults at startup");
    checkLog.contains(conn,
                      "Failing read/write concern persisted defaults lookup because of fail point");

    // Disable the fail point and verify the defaults can be returned.
    assert.commandWorked(
        failPointConn.adminCommand({configureFailPoint: "failRWCDefaultsLookup", mode: "off"}));
    res = assert.commandWorked(conn.adminCommand({getDefaultRWConcern: 1}));
    assert.eq(res.defaultReadConcern, {level: "majority"});

    // Unset the default read concern so it won't interfere with testing hooks.
    assert.commandWorked(conn.adminCommand({setDefaultRWConcern: 1, defaultReadConcern: {}}));
}

jsTestLog("Testing mongos...");
{
    // Use 1 node CSRS so the failpoint to disable rwc lookup only needs to be set on one node.
    const st = new ShardingTest({shards: 1, config: 1});

    runTest(st.s, st.configRS.getPrimary(), () => {
        assert.commandWorked(st.configRS.getPrimary().adminCommand(
            {configureFailPoint: "failRWCDefaultsLookup", mode: "alwaysOn"}));
        st.restartMongos(0);
    });

    st.stop();
}

jsTestLog("Testing plain replica set node...");
{
    const rst = new ReplSetTest({nodes: 1});
    rst.startSet();
    rst.initiate();

    const primary = rst.getPrimary();
    runTest(primary, primary, () => {
        rst.restart(
            primary,
            {setParameter: "failpoint.failRWCDefaultsLookup=" + tojson({mode: "alwaysOn"})});
    });

    rst.stopSet();
}
})();