summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/port_options.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/noPassthrough/port_options.js')
-rw-r--r--jstests/noPassthrough/port_options.js96
1 files changed, 48 insertions, 48 deletions
diff --git a/jstests/noPassthrough/port_options.js b/jstests/noPassthrough/port_options.js
index 8f4d4becc3e..72fb5bf755d 100644
--- a/jstests/noPassthrough/port_options.js
+++ b/jstests/noPassthrough/port_options.js
@@ -1,55 +1,55 @@
// Check --port= edge behaviors.
(function() {
- 'use strict';
- jsTest.log("Setting port=0 is okay unless binding to multiple IP interfaces.");
-
- function runTest(bindIP, expectOk) {
- jsTest.log("".concat("Testing with bindIP=[", bindIP, "], expectOk=[", expectOk, "]"));
-
- clearRawMongoProgramOutput();
-
- let pid = startMongoProgramNoConnect(
- "mongod", "--ipv6", "--dbpath", MongoRunner.dataDir, "--bind_ip", bindIP, "--port", 0);
- jsTest.log("".concat("pid=[", pid, "]"));
-
- if (expectOk) {
- let port;
-
- // We use assert.soonNoExcept() here because the mongod may not be logging yet.
- assert.soonNoExcept(() => {
- const logContents = rawMongoProgramOutput();
- const found = logContents.match(/waiting for connections on port (\d+)/);
- if (found !== null) {
- print("Found message from mongod with port it is listening on: " + found[0]);
- port = found[1];
- return true;
- }
- });
-
- const connStr = `127.0.0.1:${port}`;
- print("Attempting to connect to " + connStr);
-
- let conn;
- assert.soonNoExcept(() => {
- conn = new Mongo(connStr);
+'use strict';
+jsTest.log("Setting port=0 is okay unless binding to multiple IP interfaces.");
+
+function runTest(bindIP, expectOk) {
+ jsTest.log("".concat("Testing with bindIP=[", bindIP, "], expectOk=[", expectOk, "]"));
+
+ clearRawMongoProgramOutput();
+
+ let pid = startMongoProgramNoConnect(
+ "mongod", "--ipv6", "--dbpath", MongoRunner.dataDir, "--bind_ip", bindIP, "--port", 0);
+ jsTest.log("".concat("pid=[", pid, "]"));
+
+ if (expectOk) {
+ let port;
+
+ // We use assert.soonNoExcept() here because the mongod may not be logging yet.
+ assert.soonNoExcept(() => {
+ const logContents = rawMongoProgramOutput();
+ const found = logContents.match(/waiting for connections on port (\d+)/);
+ if (found !== null) {
+ print("Found message from mongod with port it is listening on: " + found[0]);
+ port = found[1];
return true;
- });
- assert.commandWorked(conn.adminCommand({ping: 1}));
-
- stopMongoProgramByPid(pid);
- } else {
- const ec = waitProgram(pid);
- assert.eq(ec, MongoRunner.EXIT_NET_ERROR);
- assert.soonNoExcept(() => {
- const logContents = rawMongoProgramOutput();
- const found = logContents.match(
- /Port 0 \(ephemeral port\) is not allowed when listening on multiple IP interfaces/);
- return (found !== null);
- }, "No warning issued for invalid port=0 usage");
- }
+ }
+ });
+
+ const connStr = `127.0.0.1:${port}`;
+ print("Attempting to connect to " + connStr);
+
+ let conn;
+ assert.soonNoExcept(() => {
+ conn = new Mongo(connStr);
+ return true;
+ });
+ assert.commandWorked(conn.adminCommand({ping: 1}));
+
+ stopMongoProgramByPid(pid);
+ } else {
+ const ec = waitProgram(pid);
+ assert.eq(ec, MongoRunner.EXIT_NET_ERROR);
+ assert.soonNoExcept(() => {
+ const logContents = rawMongoProgramOutput();
+ const found = logContents.match(
+ /Port 0 \(ephemeral port\) is not allowed when listening on multiple IP interfaces/);
+ return (found !== null);
+ }, "No warning issued for invalid port=0 usage");
}
+}
- runTest("127.0.0.1", true);
- runTest("127.0.0.1,::1", false);
+runTest("127.0.0.1", true);
+runTest("127.0.0.1,::1", false);
}());