Skip to content

Commit

Permalink
moved test to generator test case file
Browse files Browse the repository at this point in the history
  • Loading branch information
christkv committed Dec 15, 2016
1 parent 83ba471 commit bcaf5c7
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 91 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dependencies": {
"es6-promise": "3.2.1",
"mongodb-core": "2.1.2",
"mongodb-core": "christkv/mongodb-core#2.0",
"readable-stream": "2.1.5"
},
"devDependencies": {
Expand Down
91 changes: 91 additions & 0 deletions test/functional/replicaset_mock_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,94 @@ exports['Should correctly print warning and error when no mongos proxies in seed
});
}
}

exports['Should correctly set socketTimeoutMS and connectTimeoutMS for mongos'] = {
metadata: {
requires: {
generators: true,
topology: "single"
}
},

test: function(configuration, test) {
var MongoClient = configuration.require.MongoClient,
ObjectId = configuration.require.ObjectId,
ReadPreference = configuration.require.ReadPreference,
Long = configuration.require.Long,
co = require('co'),
mockupdb = require('../mock');

// Contain mock server
var mongos1 = null;
var mongos2 = null;
var running = true;

// Extend the object
var extend = function(template, fields) {
for(var name in template) fields[name] = template[name];
return fields;
}

// Default message fields
var defaultFields = {
"ismaster" : true,
"msg" : "isdbgrid",
"maxBsonObjectSize" : 16777216,
"maxMessageSizeBytes" : 48000000,
"maxWriteBatchSize" : 1000,
"localTime" : new Date(),
"maxWireVersion" : 5,
"minWireVersion" : 0,
"ok" : 1
}

// Primary server states
var serverIsMaster = [extend(defaultFields, {})];
// Received command on server
var command = null;
// Boot the mock
co(function*() {
mongos1 = yield mockupdb.createServer(52000, 'localhost');
mongos2 = yield mockupdb.createServer(52001, 'localhost');

// Mongos
co(function*() {
while(running) {
var request = yield mongos1.receive();

// Get the document
var doc = request.document;

if(doc.ismaster) {
request.reply(serverIsMaster[0]);
}
}
});

// Mongos
co(function*() {
while(running) {
var request = yield mongos2.receive();

// Get the document
var doc = request.document;

if(doc.ismaster) {
request.reply(serverIsMaster[0]);
}
}
});

MongoClient.connect('mongodb://localhost:52000,localhost:52001/test?socketTimeoutMS=120000&connectTimeoutMS=15000', function(err, db) {
test.equal(null, err);
test.equal(15000, db.serverConfig.s.mongos.s.options.connectionTimeout);
test.equal(120000, db.serverConfig.s.mongos.s.options.socketTimeout);

db.close();
mongos1.destroy();
running = false;
test.done();
});
});
}
}
91 changes: 0 additions & 91 deletions test/functional/sharding_connection_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,94 +207,3 @@ exports['Should correctly modify the server reconnectTries for all sharded proxy
});
}
}

exports['Should correctly set socketTimeoutMS and connectTimeoutMS for mongos'] = {
metadata: {
requires: {
generators: true,
topology: "single"
}
},

test: function(configuration, test) {
var MongoClient = configuration.require.MongoClient,
ObjectId = configuration.require.ObjectId,
ReadPreference = configuration.require.ReadPreference,
Long = configuration.require.Long,
co = require('co'),
mockupdb = require('../mock');

// Contain mock server
var mongos1 = null;
var mongos2 = null;
var running = true;

// Extend the object
var extend = function(template, fields) {
for(var name in template) fields[name] = template[name];
return fields;
}

// Default message fields
var defaultFields = {
"ismaster" : true,
"msg" : "isdbgrid",
"maxBsonObjectSize" : 16777216,
"maxMessageSizeBytes" : 48000000,
"maxWriteBatchSize" : 1000,
"localTime" : new Date(),
"maxWireVersion" : 5,
"minWireVersion" : 0,
"ok" : 1
}

// Primary server states
var serverIsMaster = [extend(defaultFields, {})];
// Received command on server
var command = null;
// Boot the mock
co(function*() {
mongos1 = yield mockupdb.createServer(52000, 'localhost');
mongos2 = yield mockupdb.createServer(52001, 'localhost');

// Mongos
co(function*() {
while(running) {
var request = yield mongos1.receive();

// Get the document
var doc = request.document;

if(doc.ismaster) {
request.reply(serverIsMaster[0]);
}
}
});

// Mongos
co(function*() {
while(running) {
var request = yield mongos2.receive();

// Get the document
var doc = request.document;

if(doc.ismaster) {
request.reply(serverIsMaster[0]);
}
}
});

MongoClient.connect('mongodb://localhost:52000,localhost:52001/test?socketTimeoutMS=120000&connectTimeoutMS=15000', function(err, db) {
test.equal(null, err);
test.equal(15000, db.serverConfig.s.mongos.s.options.connectionTimeout);
test.equal(120000, db.serverConfig.s.mongos.s.options.socketTimeout);

db.close();
mongos1.destroy();
running = false;
test.done();
});
});
}
}

0 comments on commit bcaf5c7

Please sign in to comment.