summaryrefslogtreecommitdiff
path: root/jstests/core/dbadmin.js
blob: b41771d513edfab2fe30be0136ee13f80c5dca1a (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
// @tags: [
//    # Assert on the isWritablePrimary field of a hello response. If a primary steps down after
//    # accepting a hello command and returns before its connection is closed, the response can
//    # contain isWritablePrimary: false.
//    does_not_support_stepdowns,
// ]

(function() {
'use strict';

var t = db.dbadmin;
t.save({x: 1});
t.save({x: 1});

var res = db.adminCommand("listDatabases");
assert(res.databases && res.databases.length > 0, "listDatabases: " + tojson(res));

var res = db.adminCommand({listDatabases: 1, nameOnly: true});
assert(res.databases && res.databases.length > 0 && res.totalSize === undefined,
       "listDatabases nameOnly: " + tojson(res));

var now = new Date();
var x = db._adminCommand("hello");
assert(x.isWritablePrimary, "hello failed: " + tojson(x));
assert(x.localTime, "hello didn't include time: " + tojson(x));

var localTimeSkew = x.localTime - now;
if (localTimeSkew >= 50) {
    print("Warning: localTimeSkew " + localTimeSkew + " > 50ms.");
}
assert.lt(localTimeSkew, 60 * 60 * 1000 /* one minute */, "hello.localTime");

var before = db.runCommand("serverStatus");
print(before.uptimeMillis);
sleep(100);

var after = db.runCommand("serverStatus");
print(after.uptimeMillis);
assert.gte(after.uptimeMillis, before.uptimeMillis, "uptime estimate should be non-decreasing");
})();