summaryrefslogtreecommitdiff
path: root/jstests/libs/sessions_collection.js
blob: c25c72c8193eda5e8c2ac29a0c8539e5e4ab33d2 (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
// 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) {
    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["ns"], "config.system.sessions");
            assert.eq(entry["key"], {"lastUse": 1});
            assert(entry.hasOwnProperty("expireAfterSeconds"));
        }
    }

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