summaryrefslogtreecommitdiff
path: root/jstests/replsets/read_concern_uninitated_set.js
blob: 52a12a16def64ebb6edd68b2ca1f534bcfe4e3f3 (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
/**
 * Test to ensure that specifying non-local read concern with an uninitiated set does not crash
 * node.
 *
 * @tags: [requires_persistence, requires_majority_read_concern]
 */
(function() {
    "use strict";
    // For supportsMajorityReadConcern().
    load("jstests/multiVersion/libs/causal_consistency_helpers.js");

    if (!supportsMajorityReadConcern()) {
        jsTestLog("Skipping test since storage engine doesn't support majority read concern.");
        return;
    }

    const rst = new ReplSetTest({nodes: 1});
    rst.startSet();
    const localDB = rst.nodes[0].getDB('local');
    assert.commandWorked(localDB.test.insert({_id: 0}));
    assert.commandWorked(localDB.runCommand({
        isMaster: 1,
        "$clusterTime": {
            "clusterTime": Timestamp(1, 1),
            "signature":
                {"hash": BinData(0, "AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId": NumberLong(0)}
        }
    }));
    jsTestLog("Local readConcern on local database should work.");
    const res = assert.commandWorked(localDB.runCommand(
        {find: "test", filter: {}, maxTimeMS: 60000, readConcern: {level: "local"}}));
    assert.eq([{_id: 0}], res.cursor.firstBatch);

    jsTestLog("Majority readConcern should fail with NotYetInitialized.");
    assert.commandFailedWithCode(
        localDB.runCommand(
            {find: "test", filter: {}, maxTimeMS: 60000, readConcern: {level: "majority"}}),
        ErrorCodes.NotYetInitialized);

    jsTestLog("afterClusterTime readConcern should fail with NotYetInitialized.");
    assert.commandFailedWithCode(localDB.runCommand({
        find: "test",
        filter: {},
        maxTimeMS: 60000,
        readConcern: {afterClusterTime: Timestamp(1, 1)}
    }),
                                 ErrorCodes.NotYetInitialized);

    jsTestLog("oplog query should fail with NotYetInitialized.");
    assert.commandFailedWithCode(localDB.runCommand({
        find: "oplog.rs",
        filter: {ts: {$gte: Timestamp(1520004466, 2)}},
        tailable: true,
        awaitData: true,
        maxTimeMS: 60000,
        batchSize: 13981010,
        term: 1,
        readConcern: {afterClusterTime: Timestamp(1, 1)}
    }),
                                 ErrorCodes.NotYetInitialized);
    rst.stopSet();
}());