summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/refresh_logical_session_cache_now.js
blob: ac11c138c6f6fc1b000a955fd8f71a3d0fea1a46 (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
(function() {
"use script";

// This test makes assertions about the number of sessions, which are not compatible with
// implicit sessions.
TestData.disableImplicitSessions = true;

var res;
var refresh = {refreshLogicalSessionCacheNow: 1};
var startSession = {startSession: 1};

// Start up a standalone server.
var conn = MongoRunner.runMongod();
var admin = conn.getDB("admin");
var config = conn.getDB("config");

// 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(config.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(config.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(config.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(config.system.sessions.count(), numSessions + 1, "should have written session records");
MongoRunner.stopMongod(conn);
}());