diff options
author | Mathias Stearn <mathias@10gen.com> | 2014-03-27 16:15:09 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2014-03-27 17:35:16 -0400 |
commit | d0a1e84ab2fa1b6aa699721b5cb9a4f8d0bf3692 (patch) | |
tree | 7a1ffc91cb6cb176c1e367ea7641ab05032c862c /jstests/noPassthroughWithMongod/connections_opened.js | |
parent | 719134aa7985c0a697f199fc78e323d04e3a65ad (diff) | |
download | mongo-d0a1e84ab2fa1b6aa699721b5cb9a4f8d0bf3692.tar.gz |
SERVER-13391 Rename slowNightly -> noPassthroughWithMongod and slowWeekly -> noPassthrough
This better represents their purpose and the difference between them.
Diffstat (limited to 'jstests/noPassthroughWithMongod/connections_opened.js')
-rw-r--r-- | jstests/noPassthroughWithMongod/connections_opened.js | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/connections_opened.js b/jstests/noPassthroughWithMongod/connections_opened.js new file mode 100644 index 00000000000..6e6247f105a --- /dev/null +++ b/jstests/noPassthroughWithMongod/connections_opened.js @@ -0,0 +1,90 @@ +// Tests serverStatus tracking of connections opened + +var numPerTypeToCreate = 100; + +// 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"); + +var availableConnections = db.serverStatus().connections.available; +if ( availableConnections < ( numPerTypeToCreate * 10 ) ) { + numPerTypeToCreate = Math.floor( availableConnections / 10 ); +} + +print( "numPerTypeToCreate: " + numPerTypeToCreate ); + +var testDB = 'connectionsOpenedTest'; +var signalCollection = 'keepRunning'; + +function createPersistentConnection() { + return new Mongo(db.getMongo().host); +} + +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 + "')" + + ".findOne().stop;}, \"Parallel shell never told to terminate\", 10 * 60000);"; + return startParallelShell(pollString); +} + +function waitForConnections(expectedCurrentConnections, expectedTotalConnections) { + assert.soon(function() { + currentConnInfo = db.serverStatus().connections; + return (expectedCurrentConnections == currentConnInfo.current) && + (expectedTotalConnections, currentConnInfo.totalCreated); + }, + {toString: function() { + return "Incorrect connection numbers. Expected " + expectedCurrentConnections + + " current connections and " + expectedTotalConnections + " total" + + " connections. Connection info from serverStatus: " + + tojson(db.serverStatus().connections); } }, + 5 * 60000); + +} + + +var originalConnInfo = db.serverStatus().connections; +assert.gt(originalConnInfo.current, 0); +assert.gt(originalConnInfo.totalCreated, 0); + +jsTestLog("Creating persistent connections"); +var permConns = []; +for (var i = 0; i < numPerTypeToCreate; i++) { + permConns.push(createPersistentConnection()); +} + +jsTestLog("Testing that persistent connections increased the current and totalCreated counters"); +waitForConnections(originalConnInfo.current + numPerTypeToCreate, + originalConnInfo.totalCreated + numPerTypeToCreate); + +jsTestLog("Creating temporary connections"); +db.getSiblingDB(testDB).dropDatabase(); +db.getSiblingDB(testDB).getCollection(signalCollection).insert({stop:false}); + +var tempConns = []; +for (var i = 0; i < numPerTypeToCreate; i++) { + tempConns.push(createTemporaryConnection()); +} + +jsTestLog("Testing that temporary connections increased the current and totalCreated counters"); +waitForConnections(originalConnInfo.current + numPerTypeToCreate*2, + originalConnInfo.totalCreated + numPerTypeToCreate*2); + +jsTestLog("Waiting for all temporary connections to be closed"); +// Notify waiting parallel shells to terminate, causing the connection count to go back down. +db.getSiblingDB(testDB).getCollection(signalCollection).update({}, {$set : {stop:true}}); +for (var i = 0; i < tempConns.length; i++) { + tempConns[i](); // wait on parallel shell to terminate +} + +jsTestLog("Testing that current connections counter went down after temporary connections closed"); +waitForConnections(originalConnInfo.current + numPerTypeToCreate, + originalConnInfo.totalCreated + numPerTypeToCreate*2); + +persistent = null; +gc(); + +MongoRunner.stopMongod( mongo ); |