File: no_chaining.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (73 lines) | stat: -rw-r--r-- 1,934 bytes parent folder | download | duplicates (3)
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

function myprint( x ) {
    print( "chaining output: " + x );
}

var replTest = new ReplSetTest({name: 'testSet', nodes: 3});
var nodes = replTest.startSet();
var hostnames = replTest.nodeList();
replTest.initiate(
    {
        "_id" : "testSet",
        "members" : [
            {"_id" : 0, "host" : hostnames[0], "priority" : 2},
            {"_id" : 1, "host" : hostnames[1]},
            {"_id" : 2, "host" : hostnames[2]}
        ],
        "settings" : {
            "chainingAllowed" : false
        }
    }
);

var master = replTest.getMaster();
replTest.awaitReplication();


var breakNetwork = function() {
    replTest.bridge();
    replTest.partition(0, 2);
    master = replTest.getMaster();
};

var checkNoChaining = function() {
    master.getDB("test").foo.insert({x:1});

    assert.soon(
        function() {
            return nodes[1].getDB("test").foo.findOne() != null;
        }
    );

    var endTime = (new Date()).getTime()+10000;
    while ((new Date()).getTime() < endTime) {
        assert(nodes[2].getDB("test").foo.findOne() == null,
               'Check that 2 does not catch up');
    }
};

var forceSync = function() {
    assert.soon(
        function() {
            var config = nodes[2].getDB("local").system.replset.findOne();
            var targetHost = config.members[1].host;
            printjson(nodes[2].getDB("admin").runCommand({replSetSyncFrom : targetHost}));
            return nodes[2].getDB("test").foo.findOne() != null;
        },
        'Check force sync still works'
    );
};

if (!_isWindows()) {
    print("break the network so that node 2 cannot replicate");
    breakNetwork();

    print("make sure chaining is not happening");
    checkNoChaining();

    print("check that forcing sync target still works");
    forceSync();

    var config = master.getDB("local").system.replset.findOne();
    assert.eq(false, config.settings.chainingAllowed, tojson(config));
}