summaryrefslogtreecommitdiff
path: root/jstests/sharding/cannot_unset_cluster_wide_write_concern_once_set.js
blob: 3f5f12db913707e24fec6f824755987061b73889 (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
/**
 * Tests that CWWC cannot be unset once it is set.
 * @tags: [
 * ]
 */
(function() {
"use strict";

function runTest(conn) {
    let expectedDefaultWC = {w: "majority", wtimeout: 0};
    let res = conn.adminCommand({getDefaultRWConcern: 1});
    assert(res.hasOwnProperty("defaultWriteConcern"));
    assert.eq(expectedDefaultWC, res.defaultWriteConcern, tojson(res));

    jsTestLog("Setting the default write concern to empty initially works.");
    assert.commandWorked(conn.adminCommand({
        setDefaultRWConcern: 1,
        defaultWriteConcern: {},
    }));

    res = conn.adminCommand({getDefaultRWConcern: 1});
    assert(res.hasOwnProperty("defaultWriteConcern"));
    assert.eq(expectedDefaultWC, res.defaultWriteConcern, tojson(res));

    jsTestLog("Setting the default write concern.");
    const newDefaultWriteConcern = {w: 2, wtimeout: 60};
    assert.commandWorked(conn.adminCommand({
        setDefaultRWConcern: 1,
        defaultWriteConcern: newDefaultWriteConcern,
    }));
    res = conn.adminCommand({getDefaultRWConcern: 1});
    assert.eq(res.defaultWriteConcern, newDefaultWriteConcern);

    jsTestLog("Attempting to unset the default write concern should fail.");
    assert.commandFailedWithCode(conn.adminCommand({
        setDefaultRWConcern: 1,
        defaultWriteConcern: {},
    }),
                                 ErrorCodes.IllegalOperation);

    res = conn.adminCommand({getDefaultRWConcern: 1});
    assert.eq(res.defaultWriteConcern, newDefaultWriteConcern);
}

const name = jsTestName();
const rst = new ReplSetTest({name: name, nodes: 2});
rst.startSet();
rst.initiate();
const primary = rst.getPrimary();
runTest(primary);
rst.stopSet();

const st = new ShardingTest({name: name});
const mongos = st.s;
runTest(mongos);
st.stop();
})();