summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/getmore_awaitdata_opcounters.js
blob: e925222c3f7390546e0578fcbc22e719d2b31e64 (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
/**
 * Test that opcounters are correct for getMore operations on awaitData cursors.
 * @tags: [requires_capped]
 */
(function() {
"use strict";

const coll = db.getmore_awaitdata_opcounters;
coll.drop();
assert.commandWorked(db.createCollection(coll.getName(), {capped: true, size: 1024}));
assert.commandWorked(coll.insert({_id: 1}));
assert.commandWorked(coll.insert({_id: 2}));
assert.commandWorked(coll.insert({_id: 3}));

function getGlobalLatencyStats() {
    return db.serverStatus().opLatencies.reads;
}

function getCollectionLatencyStats() {
    return coll.latencyStats().next().latencyStats.reads;
}

function getTop() {
    const res = db.adminCommand({top: 1});
    if (!res.ok) {
        assert.commandFailedWithCode(res, [ErrorCodes.BSONObjectTooLarge, 13548]);
        return undefined;
    }

    return res.totals[coll.getFullName()];
}

// Global latency histogram from serverStatus should record two read ops, one for find and one
// for getMore.
let oldGlobalLatency = getGlobalLatencyStats();
assert.eq(3, coll.find().tailable(true).itcount());
let newGlobalLatency = getGlobalLatencyStats();
assert.eq(2, newGlobalLatency.ops - oldGlobalLatency.ops);

// Per-collection latency histogram should record three read ops, one for find, one for getMore,
// and one for the aggregation command used to retrieve the stats themselves.
let oldCollLatency = getCollectionLatencyStats();
assert.eq(3, coll.find().tailable(true).itcount());
let newCollLatency = getCollectionLatencyStats();
assert.eq(3, newCollLatency.ops - oldCollLatency.ops);

// Top separates counters for getMore and find. We should see a delta of one getMore op and one
// find op.
let oldTop = getTop();
if (oldTop === undefined) {
    return;
}

assert.eq(3, coll.find().tailable(true).itcount());

let newTop = getTop();
if (newTop === undefined) {
    return;
}

assert.eq(1, newTop.getmore.count - oldTop.getmore.count);
assert.eq(1, newTop.queries.count - oldTop.queries.count);
}());