Skip to content

Commit 83ba471

Browse files
committed
Added test to verify connectTimeoutMS and socketTimeoutMS are passed down correctly for mongos topology
1 parent b55176b commit 83ba471

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

test/functional/sharding_connection_tests.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,94 @@ exports['Should correctly modify the server reconnectTries for all sharded proxy
207207
});
208208
}
209209
}
210+
211+
exports['Should correctly set socketTimeoutMS and connectTimeoutMS for mongos'] = {
212+
metadata: {
213+
requires: {
214+
generators: true,
215+
topology: "single"
216+
}
217+
},
218+
219+
test: function(configuration, test) {
220+
var MongoClient = configuration.require.MongoClient,
221+
ObjectId = configuration.require.ObjectId,
222+
ReadPreference = configuration.require.ReadPreference,
223+
Long = configuration.require.Long,
224+
co = require('co'),
225+
mockupdb = require('../mock');
226+
227+
// Contain mock server
228+
var mongos1 = null;
229+
var mongos2 = null;
230+
var running = true;
231+
232+
// Extend the object
233+
var extend = function(template, fields) {
234+
for(var name in template) fields[name] = template[name];
235+
return fields;
236+
}
237+
238+
// Default message fields
239+
var defaultFields = {
240+
"ismaster" : true,
241+
"msg" : "isdbgrid",
242+
"maxBsonObjectSize" : 16777216,
243+
"maxMessageSizeBytes" : 48000000,
244+
"maxWriteBatchSize" : 1000,
245+
"localTime" : new Date(),
246+
"maxWireVersion" : 5,
247+
"minWireVersion" : 0,
248+
"ok" : 1
249+
}
250+
251+
// Primary server states
252+
var serverIsMaster = [extend(defaultFields, {})];
253+
// Received command on server
254+
var command = null;
255+
// Boot the mock
256+
co(function*() {
257+
mongos1 = yield mockupdb.createServer(52000, 'localhost');
258+
mongos2 = yield mockupdb.createServer(52001, 'localhost');
259+
260+
// Mongos
261+
co(function*() {
262+
while(running) {
263+
var request = yield mongos1.receive();
264+
265+
// Get the document
266+
var doc = request.document;
267+
268+
if(doc.ismaster) {
269+
request.reply(serverIsMaster[0]);
270+
}
271+
}
272+
});
273+
274+
// Mongos
275+
co(function*() {
276+
while(running) {
277+
var request = yield mongos2.receive();
278+
279+
// Get the document
280+
var doc = request.document;
281+
282+
if(doc.ismaster) {
283+
request.reply(serverIsMaster[0]);
284+
}
285+
}
286+
});
287+
288+
MongoClient.connect('mongodb://localhost:52000,localhost:52001/test?socketTimeoutMS=120000&connectTimeoutMS=15000', function(err, db) {
289+
test.equal(null, err);
290+
test.equal(15000, db.serverConfig.s.mongos.s.options.connectionTimeout);
291+
test.equal(120000, db.serverConfig.s.mongos.s.options.socketTimeout);
292+
293+
db.close();
294+
mongos1.destroy();
295+
running = false;
296+
test.done();
297+
});
298+
});
299+
}
300+
}

test/test_topologies.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ Sharded.prototype.stop = function(callback) {
154154
return this.topology.stop();
155155
}
156156

157+
Sharded.prototype.discover = function() {
158+
return this.topology.discover();
159+
}
160+
157161
Sharded.prototype.purge = function() {
158162
return this.topology.purge();
159163
}

0 commit comments

Comments
 (0)