diff options
author | Billy Donahue <billy.donahue@mongodb.com> | 2018-04-13 01:49:31 -0400 |
---|---|---|
committer | Billy Donahue <billy.donahue@mongodb.com> | 2018-04-16 11:25:43 -0400 |
commit | c476c42f6aea9aee212d109b3fc57ace01c696fc (patch) | |
tree | 553239f54214354e4a380b2651575754ff0222a7 | |
parent | f7593edc6c1dfa32077dee85b66255086334b8f9 (diff) | |
download | mongo-c476c42f6aea9aee212d109b3fc57ace01c696fc.tar.gz |
SERVER-33917 port_options.js ping mongod host instead of killing it
-rw-r--r-- | jstests/noPassthrough/port_options.js | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/jstests/noPassthrough/port_options.js b/jstests/noPassthrough/port_options.js index 6dbab50de61..d56fb02feba 100644 --- a/jstests/noPassthrough/port_options.js +++ b/jstests/noPassthrough/port_options.js @@ -22,9 +22,30 @@ jsTest.log("".concat("pid=[", pid, "]")); if (expectOk) { - const ec = stopMongoProgramByPid(pid); - const expect = _isWindows() ? 1 : -15; // SIGTERM is 15 - assert.eq(ec, expect, "Expected mongod terminate"); + let port; + + // We use assert.soonNoExcept() here because `cat(logpath)` may fail due to the mongod + // not yet having created the log file yet. + assert.soonNoExcept(() => { + const found = cat(logpath).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); + return true; + }); + assert.commandWorked(conn.adminCommand({ping: 1})); + + stopMongoProgramByPid(pid); } else { const ec = waitProgram(pid); assert.eq(ec, MongoRunner.EXIT_NET_ERROR); |