summaryrefslogtreecommitdiff
path: root/jstests/gle/create_index_gle.js
blob: b8b63182924bf3c7f47b29e8f821747ad78a1e74 (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
load('jstests/replsets/rslib.js');
(function() {
"use strict";

var st = new ShardingTest({
    name: "zzz",
    shards: {
        rs0: {
            nodes: {n0: {}, n1: {rsConfig: {priority: 0}}},
            oplogSize: 10,
        }
    },
    verbose: 3,
    other: {rsOptions: {verbose: 1}}
});
var replTest = st.rs0;

var config = replTest.getReplSetConfig();
// Add a delay long enough so getLastError would actually 'wait' for write concern.
config.members[1].slaveDelay = 3;
config.version = replTest.getReplSetConfigFromNode().version + 1;

reconfig(replTest, config, true);

assert.soon(function() {
    var secConn = replTest.getSecondary();
    var config = secConn.getDB('local').system.replset.findOne();
    return config.members[1].slaveDelay == 3;
});

replTest.awaitSecondaryNodes();

var testDB = st.s.getDB('test');
testDB.adminCommand({connPoolSync: 1});

var secConn = replTest.getSecondary();
var testDB2 = secConn.getDB('test');

testDB.user.insert({x: 1});

testDB.user.ensureIndex({x: 1});
assert.gleOK(testDB.runCommand({getLastError: 1, w: 2}));

replTest.waitForAllIndexBuildsToFinish('test', 'user');

var priIdx = testDB.user.getIndexes();
var secIdx = testDB2.user.getIndexes();

assert.eq(priIdx.length, secIdx.length, 'pri: ' + tojson(priIdx) + ', sec: ' + tojson(secIdx));

st.stop();
}());