summaryrefslogtreecommitdiff
path: root/jstests/replsets/initial_sync_decimal.js
blob: 2d4e22db3a1ce7a4ed4f92c9d668afa6bc542384 (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
/**
 * Tests that we can initial sync decimal128 data to secondaries, even when the cluster is in 3.2
 * feature compatibility mode.
 */
(function() {
    "use strict";

    var replTest = new ReplSetTest({name: 'testSet', nodes: 2});

    var nodes = replTest.startSet();
    replTest.initiate();

    var primary = replTest.getPrimary();
    var primaryDB = primary.getDB("test");
    var primaryColl = primaryDB.initial_sync_decimal;

    var secondary = replTest.getSecondary();

    // Since we started a fresh replica set, we should be in 3.4 feature compatibility mode.
    var fcv = assert.commandWorked(
        primaryDB.adminCommand({getParameter: 1, featureCompatibilityVersion: 1}));
    assert.eq(fcv.featureCompatibilityVersion, "3.4");

    // Make sure we can insert decimal data in 3.4 mode.
    assert.writeOK(primaryColl.insert({a: 1, b: NumberDecimal(1)}));

    // Set 3.2 feature compatibility mode.
    assert.commandWorked(primaryDB.adminCommand({setFeatureCompatibilityVersion: "3.2"}));
    fcv = assert.commandWorked(
        primaryDB.adminCommand({getParameter: 1, featureCompatibilityVersion: 1}));
    assert.eq(fcv.featureCompatibilityVersion, "3.2");

    // Ensure 3.2 feature compatibility version has synced to admin.system.version.
    fcv = secondary.getDB("admin")
              .system.version.find({_id: "featureCompatibilityVersion"})
              .toArray();
    assert.eq(1, fcv.length);
    assert.eq("3.2", fcv[0].version);

    // We shouldn't be able to insert decimal data in 3.2 mode.
    assert.writeError(primaryColl.insert({a: 1, b: NumberDecimal(1)}));

    // We should, however, be able to initial sync decimal data.
    assert.commandWorked(secondary.getDB("admin").runCommand({resync: 1}));
    replTest.awaitSecondaryNodes();

    // Ensure that secondary is still up and has the data.
    var secondaryColl = secondary.getDB("test").initial_sync_decimal;
    assert.eq(1, secondaryColl.find({b: NumberDecimal(1)}).itcount());

    replTest.stopSet();
})();