summaryrefslogtreecommitdiff
path: root/jstests/libs/sessions_collection.js
blob: cd8f4a02721333643d8a6990b8ea316d2dd47ef6 (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
// Helpers for testing the logical sessions collection.

/**
 * Validates that the sessions collection exists if we expect it to,
 * and has a TTL index on the lastUse field, if we expect it to.
 */
function validateSessionsCollection(conn, collectionExists, indexExists, timeout) {
    var config = conn.getDB("config");

    var info = config.getCollectionInfos({name: "system.sessions"});
    var size = collectionExists ? 1 : 0;
    assert.eq(info.length, size);

    var indexes = config.system.sessions.getIndexes();
    var found = false;
    for (var i = 0; i < indexes.length; i++) {
        var entry = indexes[i];
        if (entry["name"] == "lsidTTLIndex") {
            found = true;

            assert.eq(entry["key"], {"lastUse": 1});
            assert(entry.hasOwnProperty("expireAfterSeconds"));
            if (timeout) {
                assert.eq(entry["expireAfterSeconds"], timeout * 60);
            }
        }
    }

    if (indexExists) {
        assert(collectionExists);
        assert(found, "expected sessions collection TTL index to exist");
    } else {
        assert(!found, "TTL index on sessions collection exists");
    }
}