summaryrefslogtreecommitdiff
path: root/jstests/core/ismaster.js
blob: a29be88331c50636052401cf4297498ee8636a1e (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
"use strict";
var res = db.isMaster();
// check that the fields that should be there are there and have proper values
assert(res.maxBsonObjectSize && isNumber(res.maxBsonObjectSize) && res.maxBsonObjectSize > 0,
       "maxBsonObjectSize possibly missing:" + tojson(res));
assert(res.maxMessageSizeBytes && isNumber(res.maxMessageSizeBytes) && res.maxBsonObjectSize > 0,
       "maxMessageSizeBytes possibly missing:" + tojson(res));
assert(res.maxWriteBatchSize && isNumber(res.maxWriteBatchSize) && res.maxWriteBatchSize > 0,
       "maxWriteBatchSize possibly missing:" + tojson(res));
assert.eq("boolean", typeof res.ismaster, "ismaster field is not a boolean" + tojson(res));
assert(res.ismaster === true, "ismaster field is false" + tojson(res));
assert(res.localTime, "localTime possibly missing:" + tojson(res));
assert(res.connectionId, "connectionId missing or false" + tojson(res));

if (!testingReplication) {
    var badFields = [];
    var unwantedReplSetFields = [
        "setName",
        "setVersion",
        "secondary",
        "hosts",
        "passives",
        "arbiters",
        "primary",
        "aribterOnly",
        "passive",
        "slaveDelay",
        "hidden",
        "tags",
        "buildIndexes",
        "me"
    ];
    var field;
    // check that the fields that shouldn't be there are not there
    for (field in res) {
        if (!res.hasOwnProperty(field)) {
            continue;
        }
        if (Array.contains(unwantedReplSetFields, field)) {
            badFields.push(field);
        }
    }
    assert(badFields.length === 0,
           "\nthe result:\n" + tojson(res) + "\ncontained fields it shouldn't have: " + badFields);
}