summaryrefslogtreecommitdiff
path: root/jstests/replsets/startup_without_fcv_document_succeeds_if_initial_sync_flag_set.js
blob: 0dca4e5efd68a4c7a4f60b3fdc85fa5262cf8b4f (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
/**
 * Tests that when a node restarts during initial sync before it can clone the FCV document, it is
 * still able to start up successfully and restart initial sync.
 */

(function() {
    load("jstests/libs/check_log.js");
    load("jstests/libs/feature_compatibility_version.js");

    rst = new ReplSetTest({nodes: 1});
    rst.startSet();
    rst.initiate();

    jsTestLog("Adding a second node to the replica set.");

    const adminDbName = "admin";
    const versionCollName = "system.version";
    const nss = adminDbName + "." + versionCollName;

    // Hang initial sync before cloning the FCV document.
    let secondary = rst.add({rsConfig: {priority: 0}});
    assert.commandWorked(secondary.getDB('admin').runCommand({
        configureFailPoint: 'initialSyncHangBeforeCollectionClone',
        mode: 'alwaysOn',
        data: {namespace: nss}
    }));
    rst.reInitiate();
    checkLog.contains(secondary, "initialSyncHangBeforeCollectionClone fail point enabled.");

    jsTestLog("Restarting secondary in the early stages of initial sync.");
    rst.restart(secondary);

    rst.awaitSecondaryNodes();

    // Get the new secondary connection.
    secondary = rst.getSecondary();
    secondary.setSlaveOk(true);

    const secondaryAdminDb = secondary.getDB("admin");
    // Assert that the FCV document was cloned through initial sync on the secondary.
    checkFCV(secondaryAdminDb, latestFCV);
    rst.stopSet();
}());