summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/mongobridge_testcommands.js
blob: a76a89e8486be7699f357c317c409bd2d0d8e5ab (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
/**
 * Test that mongobridge's *From commands succeed when test commands are
 * enabled, and fail when disabled.
 *
 * @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}},
});

// changing enableTestcommands should have no impact on the existing mongod/s/bridge instances,
TestData.enableTestCommands = false;
st.rs0.getSecondary().delayMessagesFrom(st.rs0.getPrimary(), 13000);
st.rs0.getSecondary().discardMessagesFrom(st.rs0.getPrimary(), 1.0);
st.rs0.getSecondary().acceptConnectionsFrom(st.rs0.getPrimary());
st.rs0.getSecondary().rejectConnectionsFrom(st.rs0.getPrimary());
st.stop();

// Start another test, this time with enableTestCommands as false.
// Repeating the above, we expect the commands to fail
st = new ShardingTest({
    shards: {rs0: {nodes: 2}},
    mongos: 1,
    config: 1,
    useBridge: true,
    rsOptions: {settings: {electionTimeoutMillis: 60000}},
});
assert.throws(() => {
    st.rs0.getSecondary().delayMessagesFrom(st.rs0.getPrimary(), 13000);
}, [], "testing commands have not been enabled. delayMessagesFrom will not work as expected");
assert.throws(() => {
    st.rs0.getSecondary().discardMessagesFrom(st.rs0.getPrimary(), 1.0);
}, [], "testing commands have not been enabled. discardMessagesFrom will not work as expected");
assert.throws(() => {
    st.rs0.getSecondary().acceptConnectionsFrom(st.rs0.getPrimary());
}, [], "testing commands have not been enabled. acceptConnectionsFrom will not work as expected");
assert.throws(() => {
    st.rs0.getSecondary().rejectConnectionsFrom(st.rs0.getPrimary());
}, [], "testing commands have not been enabled. rejectConnectionsFrom will not work as expected");
st.stop();