-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
Copy pathmax_conns_override_runtime.js
54 lines (46 loc) · 1.94 KB
/
max_conns_override_runtime.js
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
// Tests using a server parameter to set `maxIncomingConnectionsOverride` at runtime.
function runTest(args, testFunc) {
// Run tests in isolation to make sure we always start with a clean slate.
var mongo = MongoRunner.runMongod(args);
testFunc(mongo);
MongoRunner.stopMongod(mongo);
}
function setMaxIncomingConnectionsOverride(conn, newValue) {
conn.adminCommand({setParameter: 1, maxIncomingConnectionsOverride: newValue});
}
function getMaxIncomingConnectionsOverride(conn) {
const res = conn.adminCommand({getParameter: 1, maxIncomingConnectionsOverride: 1});
return res.maxIncomingConnectionsOverride;
}
function setMaxIncomingConnectionsOverrideAndVerify(conn, newValue) {
setMaxIncomingConnectionsOverride(conn, newValue);
assert.eq(getMaxIncomingConnectionsOverride(conn), newValue);
}
/**
* Verify that there are no exemptions set by default, and retrieving that works.
*/
runTest({}, function(conn) {
assert.eq(getMaxIncomingConnectionsOverride(conn).ranges, []);
});
/**
* Reset the list of exemptions and then clear it out -- verify that both operations succeed.
*/
runTest({}, function(conn) {
setMaxIncomingConnectionsOverrideAndVerify(conn, {ranges: ["localhost"]});
setMaxIncomingConnectionsOverrideAndVerify(conn, {ranges: []});
});
/**
* Verify that passing a mix of CIDR and HostAndPort ranges work.
*/
runTest({}, function(conn) {
const ranges = {ranges: ["127.0.0.1/8", "/tmp/mongodb.sock", "8.8.8.8/8", "localhost"]};
setMaxIncomingConnectionsOverrideAndVerify(conn, ranges);
});
/**
* Verify the behavior of the server parameter when `net.maxIncomingConnectionsOverride` is set at
* startup, and then can be modified at runtime.
*/
runTest({config: "jstests/noPassthrough/libs/max_conns_override_config.yaml"}, function(conn) {
assert.eq(getMaxIncomingConnectionsOverride(conn).ranges, ["127.0.0.1/32"]);
setMaxIncomingConnectionsOverrideAndVerify(conn, {ranges: ["localhost"]});
});