summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/mongobridge.js
blob: 1cafe1878482a8bc9a67f25955cc400b2fd64503 (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
/**
 * Test that mongobridge's *From commands work
 *
 * @tags: [
 *   requires_replication,
 *   requires_sharding,
 * ]
 */

// mongobridge depends on test commands being enabled. Also EVERY repl/sharding
// test depends on this. Think twice if you're thinking of changing the default.
assert.eq(jsTest.options().enableTestCommands, true);

// we expect this to work just fine given that enableTestCommands is true by default
var st = new ShardingTest({
    shards: {rs0: {nodes: 2}},
    mongos: 1,
    config: 1,
    useBridge: true,
    rsOptions: {settings: {electionTimeoutMillis: 60000}}
});
var wc = {writeConcern: {w: 2, wtimeout: 4000}};

// delayMessagesFrom should cause a write error on this insert
st.rs0.getPrimary().delayMessagesFrom(st.rs0.getSecondary(), 13000);
assert.commandFailed(st.s0.getCollection('testDB.cll').insert({test: 5}, wc));
st.rs0.getPrimary().delayMessagesFrom(st.rs0.getSecondary(), 0);

// discardMessages w/ a loss probabilty of 1 should also cause a write error
st.rs0.getPrimary().discardMessagesFrom(st.rs0.getSecondary(), 1.0);
assert.commandFailed(st.s0.getCollection('testDB.cll').insert({test: 5}, wc));
st.rs0.getPrimary().discardMessagesFrom(st.rs0.getSecondary(), 0.0);

// reject connections should make the write fail as well
st.rs0.getPrimary().rejectConnectionsFrom(st.rs0.getSecondary());
assert.commandFailed(st.s0.getCollection('testDB.cll').insert({test: 5}, wc));
// but if we make mongobridge accept the connections, the write should now
// succeed
st.rs0.getPrimary().acceptConnectionsFrom(st.rs0.getSecondary());
// don't use wtimeout with this command. Slower boxes can be busy catching up
assert.commandWorked(st.s0.getCollection('testDB.cll').insert({test: 5}, {writeConcern: {w: 2}}));

// None of the above commands prevent writes to the primary, so we still
// expect to find 4 documents
assert.eq(st.s0.getCollection('testDB.cll').find({test: 5}).length(), 4);
st.stop();