summaryrefslogtreecommitdiff
path: root/jstests/core/txns/no_reads_from_system_dot_views_in_txn.js
blob: 280b4f0f1bf514591b25b429815bba2544295290 (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
// Tests that it is illegal to read from system.views within a transaction.
// @tags: [uses_transactions, uses_snapshot_read_concern]
(function() {
    "use strict";

    load("jstests/libs/fixture_helpers.js");  // For 'FixtureHelpers'.

    const session = db.getMongo().startSession({causalConsistency: false});

    // Use a custom database to avoid conflict with other tests that use system.views.
    const testDB = session.getDatabase("no_reads_from_system_dot_views_in_txn");
    assert.commandWorked(testDB.dropDatabase());

    testDB.runCommand({create: "foo", viewOn: "bar", pipeline: []});

    session.startTransaction({readConcern: {level: "snapshot"}});
    assert.commandFailedWithCode(testDB.runCommand({find: "system.views", filter: {}}), 51071);
    assert.commandFailedWithCode(session.abortTransaction_forTesting(),
                                 ErrorCodes.NoSuchTransaction);

    if (FixtureHelpers.isMongos(testDB)) {
        // The rest of the test is concerned with a find by UUID which is not supported against
        // mongos.
        return;
    }

    const collectionInfos =
        new DBCommandCursor(testDB, assert.commandWorked(testDB.runCommand({listCollections: 1})));
    let systemViewsUUID = null;
    while (collectionInfos.hasNext()) {
        const next = collectionInfos.next();
        if (next.name === "system.views") {
            systemViewsUUID = next.info.uuid;
        }
    }
    assert.neq(null, systemViewsUUID, "did not find UUID for system.views");

    session.startTransaction({readConcern: {level: "snapshot"}});
    assert.commandFailedWithCode(testDB.runCommand({find: systemViewsUUID, filter: {}}), 51070);
    assert.commandFailedWithCode(session.abortTransaction_forTesting(),
                                 ErrorCodes.NoSuchTransaction);

}());