summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/loglong.js
blob: db60b5f17451ce0f25c934ef4dd3049282c99279 (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
// test for SERVER-5013
// make sure very long long lines get truncated

(function() {
"use strict";

const options = {
    setParameter: "maxLogSizeKB=9"
};
const conn = MongoRunner.runMongod(options);

var db = conn.getDB('db');
var res = db.adminCommand({getParameter: 1, maxLogSizeKB: 1});
assert.eq(9, res.maxLogSizeKB);

var t = db.loglong;
t.drop();

t.insert({x: 1});

var n = 0;
var query = {x: []};
while (Object.bsonsize(query) < 30000) {
    query.x.push(n++);
}

assertLogTruncated(db, t, 9);

var res = db.adminCommand({setParameter: 1, maxLogSizeKB: 8});
assert.eq(res.ok, 1);

assertLogTruncated(db, t, 8);

function assertLogTruncated(db, t, maxLogSize) {
    var before = db.adminCommand({setParameter: 1, logLevel: 1});

    t.findOne(query);

    var x = db.adminCommand({setParameter: 1, logLevel: before.was});
    assert.eq(1, x.was, tojson(x));

    var log = db.adminCommand({getLog: "global"}).log;

    var found = false;
    var toFind = "warning: log line attempted (16kB) over max size (" + maxLogSize + "kB)";
    for (var i = log.length - 1; i >= 0; i--) {
        if (log[i].indexOf(toFind) >= 0) {
            found = true;
            break;
        }
    }

    assert(found, tojson(log));
}
MongoRunner.stopMongod(conn);
})();