summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/server54064.js
blob: e4bbad6e7fdb6a2df47350c8d2149c784ea8a74b (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
57
/**
 * Assert that arbiters periodically clear out their logical session cache. Inability to do so
 * prohibits new clients from connecting.
 *
 * @tags: [requires_replication]
 */
(function() {
const name = "server54064";
const replSet = new ReplSetTest({
    name: name,
    nodes: 2,
    // `disableLogicalSessionCacheRefresh` is true by default, but is disabled for testing purposes
    // in servers spawned from the shell.
    nodeOptions: {
        setParameter: {
            // Each refresh on an arbiter will empty the cache.
            logicalSessionRefreshMillis: 10000,
            // The number of connections/sessions before the cache is full, prohibiting new clients
            // from connecting.
            maxSessions: 3,
            disableLogicalSessionCacheRefresh: false
        }
    }
});
const nodes = replSet.nodeList();

replSet.startSet();
replSet.initiate({
    _id: name,
    members: [{_id: 0, host: nodes[0]}, {_id: 1, host: nodes[1], arbiterOnly: true}],
});

let arbConn = replSet.getArbiter();
assert.soon(() => {
    // Connect to mongo in a tight loop to exhaust the number of available logical sessions in the
    // cache.
    const result = new Mongo(arbConn.host).adminCommand({hello: 1});
    if (result['ok'] === 0) {
        assert.commandFailedWithCode(result, ErrorCodes.TooManyLogicalSessions);
        return true;
    }
    return false;
});

assert.soon(() => {
    // Once we observe that the number of sessions is maxed out, loop again to confirm that the
    // cache eventually does get cleared.
    const result = new Mongo(arbConn.host).adminCommand({hello: 1});
    if (result['ok'] === 0) {
        assert.commandFailedWithCode(result, ErrorCodes.TooManyLogicalSessions);
        return false;
    }
    return true;
});

replSet.stopSet();
})();