summaryrefslogtreecommitdiff
path: root/jstests/replsets/sessions_collection_auto_healing.js
blob: ed3322419216a7a41db664e1a7863dacef0a7ae1 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
load('jstests/libs/sessions_collection.js');

(function() {
    "use strict";

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

    var replTest = new ReplSetTest({
        name: 'refresh',
        nodes: [{rsConfig: {votes: 1, priority: 1}}, {rsConfig: {votes: 0, priority: 0}}]
    });
    var nodes = replTest.startSet();

    replTest.initiate();
    var primary = replTest.getPrimary();
    var primaryAdmin = primary.getDB("admin");

    replTest.awaitSecondaryNodes();
    var secondary = replTest.getSecondary();
    var secondaryAdmin = secondary.getDB("admin");

    // Test that we can use sessions on the primary before the sessions collection exists.
    {
        validateSessionsCollection(primary, false, false);

        assert.commandWorked(primaryAdmin.runCommand({startSession: 1}));

        validateSessionsCollection(primary, false, false);
    }

    // Test that we can use sessions on secondaries before the sessions collection exists.
    {
        validateSessionsCollection(primary, false, false);

        replTest.awaitReplication();
        validateSessionsCollection(secondary, false, false);

        assert.commandWorked(secondaryAdmin.runCommand({startSession: 1}));

        validateSessionsCollection(primary, false, false);

        replTest.awaitReplication();
        validateSessionsCollection(secondary, false, false);
    }

    // Test that a refresh on a secondary does not create the sessions collection.
    {
        validateSessionsCollection(primary, false, false);

        replTest.awaitReplication();
        validateSessionsCollection(secondary, false, false);

        assert.commandWorked(secondaryAdmin.runCommand({refreshLogicalSessionCacheNow: 1}));

        validateSessionsCollection(primary, false, false);

        replTest.awaitReplication();
        validateSessionsCollection(secondary, false, false);
    }
    // Test that a refresh on the primary creates the sessions collection.
    {
        validateSessionsCollection(primary, false, false);

        replTest.awaitReplication();
        validateSessionsCollection(secondary, false, false);

        assert.commandWorked(primaryAdmin.runCommand({refreshLogicalSessionCacheNow: 1}));

        validateSessionsCollection(primary, true, true);
    }

    // Test that a refresh on a secondary will not create the TTL index on the sessions collection.
    {
        assert.commandWorked(primary.getDB("config").system.sessions.dropIndex({lastUse: 1}));

        validateSessionsCollection(primary, true, false);

        assert.commandWorked(secondaryAdmin.runCommand({refreshLogicalSessionCacheNow: 1}));

        validateSessionsCollection(primary, true, false);
    }

    // Test that a refresh on the primary will create the TTL index on the sessions collection.
    {
        validateSessionsCollection(primary, true, false);

        assert.commandWorked(primaryAdmin.runCommand({refreshLogicalSessionCacheNow: 1}));

        validateSessionsCollection(primary, true, true);
    }

    replTest.stopSet();
})();