summaryrefslogtreecommitdiff
path: root/jstests/replsets/replset5.js
blob: fe1761e129fb0c51cdaa2f6dcf371fc22d932d4f (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
// rs test getlasterrordefaults

doTest = function (signal) {

    // Test getLastError defaults
    var replTest = new ReplSetTest({ name: 'testSet', nodes: 3 });

    var nodes = replTest.startSet();

    // Initiate set with default for getLastError
    var config = replTest.getReplSetConfig();
    config.settings = {};
    config.settings.getLastErrorDefaults = { 'w': 3, 'wtimeout': 20000 };

    replTest.initiate(config);

    //
    var master = replTest.getMaster();
    replTest.awaitSecondaryNodes();
    var testDB = "foo";

    // Initial replication
    master.getDB("barDB").bar.save({ a: 1 });
    replTest.awaitReplication();

    // These writes should be replicated immediately
    master.getDB(testDB).foo.insert({ n: 1 });
    master.getDB(testDB).foo.insert({ n: 2 });
    master.getDB(testDB).foo.insert({ n: 3 });

    // *** NOTE ***: The default doesn't seem to be propogating.
    // When I run getlasterror with no defaults, the slaves don't have the data:
    // These getlasterror commands can be run individually to verify this.
    //master.getDB("admin").runCommand({ getlasterror: 1, w: 3, wtimeout: 20000 });
    master.getDB("admin").runCommand({getlasterror: 1});

    var slaves = replTest.liveNodes.slaves;
    slaves[0].setSlaveOk();
    slaves[1].setSlaveOk();

    print("Testing slave counts");

    // These should all have 3 documents, but they don't always.
    var master1count = master.getDB(testDB).foo.count();
    assert( master1count == 3, "Master has " + master1count + " of 3 documents!");

    var slave0count = slaves[0].getDB(testDB).foo.count();
    assert( slave0count == 3, "Slave 0 has " + slave0count + " of 3 documents!");

    var slave1count = slaves[1].getDB(testDB).foo.count();
    assert( slave1count == 3, "Slave 1 has " + slave1count + " of 3 documents!");

    print("Testing slave 0");

    var s0 = slaves[0].getDB(testDB).foo.find();
    assert(s0.next()['n']);
    assert(s0.next()['n']);
    assert(s0.next()['n']);

    print("Testing slave 1");

    var s1 = slaves[1].getDB(testDB).foo.find();
    assert(s1.next()['n']);
    assert(s1.next()['n']);
    assert(s1.next()['n']);

    // End test
    replTest.stopSet(signal);
}

doTest( 15 );
print("replset5.js success");