diff options
author | Spencer T Brody <spencer@mongodb.com> | 2014-04-28 15:00:24 -0400 |
---|---|---|
committer | Dan Pasette <dan@mongodb.com> | 2014-05-16 15:35:31 -0400 |
commit | 0366e4a86262a89e329fabbadde06e14bd4a33cb (patch) | |
tree | e5d42ada1721f996698b7eba67d388cdcb0dec63 | |
parent | 0ef9bcd431976a5384324db905a155f41f9fe1dc (diff) | |
download | mongo-0366e4a86262a89e329fabbadde06e14bd4a33cb.tar.gz |
SERVER-13972 Make connections_opened.js test retry any connections that fail to connect
(cherry picked from commit b64939f3ac16843525adf6f0e893a78409ddaf16)
-rw-r--r-- | jstests/noPassthroughWithMongod/connections_opened.js | 26 | ||||
-rw-r--r-- | src/mongo/shell/servers_misc.js | 6 |
2 files changed, 22 insertions, 10 deletions
diff --git a/jstests/noPassthroughWithMongod/connections_opened.js b/jstests/noPassthroughWithMongod/connections_opened.js index 6e6247f105a..afbdd1dc84f 100644 --- a/jstests/noPassthroughWithMongod/connections_opened.js +++ b/jstests/noPassthroughWithMongod/connections_opened.js @@ -2,7 +2,7 @@ var numPerTypeToCreate = 100; -// We need to create a new mongod to ensure no one else is talking to us in the background, and +// We need to create a new mongod to ensure no one else is talking to us in the background, and // will screw up our stats. var mongo = MongoRunner.runMongod({}); var db = mongo.getDB("test"); @@ -18,21 +18,31 @@ var testDB = 'connectionsOpenedTest'; var signalCollection = 'keepRunning'; function createPersistentConnection() { - return new Mongo(db.getMongo().host); + assert.soon(function() { + try { + return new Mongo(db.getMongo().host); + } catch (x) { + return false; + }}, "Timed out waiting for persistent connection to connect", 30000, 5000); } function createTemporaryConnection() { - // Creates a connection by spawing a shell that polls the signal collection until it is told to - // terminate. - var pollString = "assert.soon(function() {" - + "return db.getSiblingDB('" + testDB + "').getCollection('" + signalCollection + "')" + // Retry connecting until you are successful + var pollString = "var conn = null;" + + "assert.soon(function() {" + + "try { conn = new Mongo(\"" + db.getMongo().host + "\"); return conn" + + "} catch (x) {return false;}}, " + + "\"Timed out waiting for temporary connection to connect\", 30000, 5000);" + // Poll the signal collection until it is told to terminate. + pollString += "assert.soon(function() {" + + "return conn.getDB('" + testDB + "').getCollection('" + signalCollection + "')" + ".findOne().stop;}, \"Parallel shell never told to terminate\", 10 * 60000);"; - return startParallelShell(pollString); + return startParallelShell(pollString, null, true); } function waitForConnections(expectedCurrentConnections, expectedTotalConnections) { assert.soon(function() { - currentConnInfo = db.serverStatus().connections; + var currentConnInfo = db.serverStatus().connections; return (expectedCurrentConnections == currentConnInfo.current) && (expectedTotalConnections, currentConnInfo.totalCreated); }, diff --git a/src/mongo/shell/servers_misc.js b/src/mongo/shell/servers_misc.js index abb4f8080bb..91db127998a 100644 --- a/src/mongo/shell/servers_misc.js +++ b/src/mongo/shell/servers_misc.js @@ -285,12 +285,14 @@ SyncCCTest.prototype.tempStart = function( num ){ } -function startParallelShell( jsCode, port ){ +function startParallelShell( jsCode, port, noConnect ){ var x; var args = ["mongo"]; - if (typeof(db) == "object") { + if (noConnect) { + args.push("--nodb"); + } else if (typeof(db) == "object") { jsCode = "db = db.getSiblingDB('" + db.getName() + "');" + jsCode; } |