summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/mongobridge_testcommands.js
blob: 577ab152873a9032bcc28afd3b2d5e67980d969d (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
/**
 * Test that mongobridge's *From commands succeed when test commands are
 * enabled, and fail when disabled.
 *
 * @tags: [
 *   live_record_incompatible,
 *   requires_replication,
 *   requires_sharding,
 *   sbe_incompatible,
 * ]
 */

// 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();