summaryrefslogtreecommitdiff
path: root/jstests/sharding/read_after_optime.js
blob: 442e8cc8ef64657ebbf9a96d40f02cbeb5ad7a6c (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
// Test read after opTime functionality with maxTimeMS on config servers (CSRS only)`.

(function() {
    'use strict';

    var shardingTest = new ShardingTest({shards: 0});
    assert(shardingTest.configRS, 'this test requires config servers to run in CSRS mode');

    var configReplSetTest = shardingTest.configRS;
    var primaryConn = configReplSetTest.getPrimary();

    var lastOp = configReplSetTest.awaitLastOpCommitted();
    assert(lastOp, 'invalid op returned from ReplSetTest.awaitLastOpCommitted()');

    var config = configReplSetTest.getReplSetConfigFromNode();
    var term = -1;
    if (config.protocolVersion === 1) {
        term = lastOp.t;
    }

    var runFindCommand = function(ts) {
        return primaryConn.getDB('local').runCommand({
            find: 'oplog.rs',
            readConcern: {
                afterOpTime: {
                    ts: ts,
                    t: term,
                },
            },
            maxTimeMS: 5000,
        });
    };

    assert.commandWorked(runFindCommand(lastOp.ts));

    var pingIntervalSeconds = 10;
    var timeoutResult = assert.commandFailedWithCode(
        runFindCommand(new Timestamp(lastOp.ts.getTime() + pingIntervalSeconds * 5, 0)),
        ErrorCodes.ExceededTimeLimit
    );
    assert.gt(timeoutResult.waitedMS, 500);

    var msg = 'Command on database local timed out waiting for read concern to be satisfied.';
    assert.soon(
        function() {
            var logMessages =
                assert.commandWorked(primaryConn.adminCommand({getLog: 'global'})).log;
            for (var i = 0; i < logMessages.length; i++) {
                if (logMessages[i].indexOf(msg) != -1) {
                    return true;
                }
            }
            return false;
        },
        'Did not see any log entries containing the following message: ' + msg,
        60000,
        300
    );
})();