summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/readConcern_snapshot_mongos_enable_test_commands.js
blob: 22eaa2fbf892a763af592de1356ab8813b4dcef9 (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
// Verifies that snapshot readConcern on mongos is not gated by the enableTestCommands flag.
//
// @tags: [requires_sharding]
(function() {
"use strict";

const dbName = "test";
const collName = "coll";

// Runs multiple commands with read concern level "snapshot" in a session,
// expecting success.
function expectSnapshotReadConcernIsSupported() {
    const st = new ShardingTest({shards: 1, config: 1});
    const session = st.s.startSession({causalConsistency: false});
    let txnNumber = 0;

    assert.commandWorked(session.getDatabase(dbName).runCommand({
        find: collName,
        readConcern: {level: "snapshot"},
        txnNumber: NumberLong(txnNumber++),
        startTransaction: true,
        autocommit: false
    }));

    assert.commandWorked(session.getDatabase(dbName).runCommand({
        aggregate: collName,
        pipeline: [],
        cursor: {},
        readConcern: {level: "snapshot"},
        txnNumber: NumberLong(txnNumber++),
        startTransaction: true,
        autocommit: false
    }));

    session.endSession();
    st.stop();
}

// Snapshot readConcern should succeed when 'enableTestCommands' is set to false.
jsTest.setOption("enableTestCommands", false);
expectSnapshotReadConcernIsSupported();

// Snapshot readConcern should succeed when 'enableTestCommands' is set to true.
jsTest.setOption("enableTestCommands", true);
expectSnapshotReadConcernIsSupported();
}());