summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/after_cluster_time.js
blob: 78485d10a31e992260f6b1b2bf87746bde8049f4 (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
66
67
68
69
70
71
// This test verifies readConcern:afterClusterTime behavior on a standalone mongod.
// @tags: [requires_replication, requires_majority_read_concern]
(function() {
"use strict";
var standalone =
    MongoRunner.runMongod({enableMajorityReadConcern: "", storageEngine: "wiredTiger"});

var testDB = standalone.getDB("test");

assert.commandWorked(testDB.runCommand({insert: "after_cluster_time", documents: [{x: 1}]}));

// Majority reads without afterClusterTime succeed.
assert.commandWorked(
    testDB.runCommand({find: "after_cluster_time", readConcern: {level: "majority"}}),
    "expected majority read without afterClusterTime to succeed on standalone mongod");

// afterClusterTime reads without a level fail.
assert.commandFailedWithCode(
    testDB.runCommand(
        {find: "after_cluster_time", readConcern: {afterClusterTime: Timestamp(0, 0)}}),
    ErrorCodes.InvalidOptions,
    "expected non-majority afterClusterTime read to fail on standalone mongod");

// afterClusterTime reads with null timestamps are rejected.
assert.commandFailedWithCode(
    testDB.runCommand({
        find: "after_cluster_time",
        readConcern: {level: "majority", afterClusterTime: Timestamp(0, 0)}
    }),
    ErrorCodes.InvalidOptions,
    "expected afterClusterTime read with null timestamp to fail on standalone mongod");

// Standalones don't support any operations with clusterTime.
assert.commandFailedWithCode(testDB.runCommand({
    find: "after_cluster_time",
    readConcern: {level: "majority", afterClusterTime: Timestamp(0, 1)}
}),
                             ErrorCodes.IllegalOperation,
                             "expected afterClusterTime read to fail on standalone mongod");
MongoRunner.stopMongod(standalone);

var rst = new ReplSetTest({nodes: 1});
rst.startSet();
rst.initiate();
var adminDBRS = rst.getPrimary().getDB("admin");

var res = adminDBRS.runCommand({ping: 1});
assert.commandWorked(res);
assert(res.hasOwnProperty("$clusterTime"), tojson(res));
assert(res.$clusterTime.hasOwnProperty("clusterTime"), tojson(res));
var clusterTime = res.$clusterTime.clusterTime;
// afterClusterTime is not allowed in  ping command.
assert.commandFailedWithCode(
    adminDBRS.runCommand({ping: 1, readConcern: {afterClusterTime: clusterTime}}),
    ErrorCodes.InvalidOptions,
    "expected afterClusterTime fail in ping");

// afterClusterTime is not allowed in serverStatus command.
assert.commandFailedWithCode(
    adminDBRS.runCommand({serverStatus: 1, readConcern: {afterClusterTime: clusterTime}}),
    ErrorCodes.InvalidOptions,
    "expected afterClusterTime fail in serverStatus");

// afterClusterTime is not allowed in currentOp command.
assert.commandFailedWithCode(
    adminDBRS.runCommand({currentOp: 1, readConcern: {afterClusterTime: clusterTime}}),
    ErrorCodes.InvalidOptions,
    "expected afterClusterTime fail in serverStatus");

rst.stopSet();
}());