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
|
(function() {
"use script";
var res;
var refresh = {refreshLogicalSessionCacheNow: 1};
var startSession = {startSession: 1};
// Start up a standalone server.
var conn = MongoRunner.runMongod({nojournal: ""});
var admin = conn.getDB("admin");
// Trigger an initial refresh, as a sanity check.
res = admin.runCommand(refresh);
assert.commandWorked(res, "failed to refresh");
// Start a session. Should not be in the collection yet.
res = admin.runCommand(startSession);
assert.commandWorked(res, "unable to start session");
assert.eq(admin.system.sessions.count(), 0, "should not have session records yet");
// Trigger a refresh. Session should now be in the collection.
res = admin.runCommand(refresh);
assert.commandWorked(res, "failed to refresh");
assert.eq(admin.system.sessions.count(), 1, "should have written session records");
// Start some new sessions. Should not be in the collection yet.
var numSessions = 100;
for (var i = 0; i < numSessions; i++) {
res = admin.runCommand(startSession);
assert.commandWorked(res, "unable to start session");
}
assert.eq(admin.system.sessions.count(), 1, "should not have more session records yet");
// Trigger another refresh. All sessions should now be in the collection.
res = admin.runCommand(refresh);
assert.commandWorked(res, "failed to refresh");
assert.eq(
admin.system.sessions.count(), numSessions + 1, "should have written session records");
}());
|