summaryrefslogtreecommitdiff
path: root/jstests/core/getmore_cmd_maxtimems.js
blob: a0c82667756b10db384a477a5f9f1e927b94124e (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
// Test attaching maxTimeMS to a getMore command.
(function() {
    'use strict';

    var cmdRes;
    var collName = 'getmore_cmd_maxtimems';
    var coll = db[collName];
    coll.drop();

    for (var i = 0; i < 10; i++) {
        assert.writeOK(coll.insert({a: i}));
    }

    // Can't attach maxTimeMS to a getMore command for a non-tailable cursor over a non-capped
    // collection.
    cmdRes = db.runCommand({find: collName, batchSize: 2});
    assert.commandWorked(cmdRes);
    cmdRes = db.runCommand({getMore: cmdRes.cursor.id, collection: collName, maxTimeMS: 60000});
    assert.commandFailed(cmdRes);

    coll.drop();
    assert.commandWorked(db.createCollection(collName, {capped: true, size: 1024}));
    for (var i = 0; i < 10; i++) {
        assert.writeOK(coll.insert({a: i}));
    }

    // Can't attach maxTimeMS to a getMore command for a non-tailable cursor over a capped
    // collection.
    cmdRes = db.runCommand({find: collName, batchSize: 2});
    assert.commandWorked(cmdRes);
    cmdRes = db.runCommand({getMore: cmdRes.cursor.id, collection: collName, maxTimeMS: 60000});
    assert.commandFailed(cmdRes);

    // Can't attach maxTimeMS to a getMore command for a non-awaitData tailable cursor.
    cmdRes = db.runCommand({find: collName, batchSize: 2, tailable: true});
    assert.commandWorked(cmdRes);
    cmdRes = db.runCommand({getMore: cmdRes.cursor.id, collection: collName, maxTimeMS: 60000});
    assert.commandFailed(cmdRes);

    // Can attach maxTimeMS to a getMore command for an awaitData cursor.
    cmdRes = db.runCommand({find: collName, batchSize: 2, tailable: true, awaitData: true});
    assert.commandWorked(cmdRes);
    cmdRes = db.runCommand({getMore: cmdRes.cursor.id, collection: collName, maxTimeMS: 60000});
    assert.commandWorked(cmdRes);
})();