Skip to content

Commit 3cb2435

Browse files
committed
Added test case to exercise all non-crud methods on mongos topologies, fixed numberOfConnectedServers on mongos topology instance.
1 parent af66afc commit 3cb2435

File tree

6 files changed

+84
-4
lines changed

6 files changed

+84
-4
lines changed

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2.0.42 08-18-2015
2+
-----------------
3+
* Added test case to exercise all non-crud methods on mongos topologies, fixed numberOfConnectedServers on mongos topology instance.
4+
15
2.0.41 08-14-2015
26
-----------------
37
* Added missing Mongos.prototype.parserType function.

lib/command_cursor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ inherits(CommandCursor, Readable);
142142
// Set the methods to inherit from prototype
143143
var methodsToInherit = ['_next', 'next', 'each', 'forEach', 'toArray'
144144
, 'rewind', 'bufferedCount', 'readBufferedDocuments', 'close', 'isClosed', 'kill'
145-
, '_find', '_getmore', '_killcursor'];
145+
, '_find', '_getmore', '_killcursor', 'isDead', 'isNotified', 'isKilled'];
146146

147147
// Only inherit the types we need
148148
for(var i = 0; i < methodsToInherit.length; i++) {

lib/mongos.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ var Mongos = function(servers, options) {
192192

193193
// Last ismaster
194194
Object.defineProperty(this, 'numberOfConnectedServers', {
195-
enumerable:true, get: function() { return self.s.mongos.connectedServers().length; }
195+
enumerable:true, get: function() {
196+
return self.s.mongos.s.mongosState.connectedServers().length;
197+
}
196198
});
197199

198200
// BSON property

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mongodb",
3-
"version": "2.0.41",
3+
"version": "2.0.42",
44
"description": "MongoDB legacy driver emulation layer on top of mongodb-core",
55
"main": "index.js",
66
"repository": {

test/functional/crud_api_tests.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,3 +871,41 @@ exports['should correctly execute updateOne operations with w:0 and upsert'] = {
871871
});
872872
}
873873
}
874+
875+
exports['should correctly execute crud operations using w:0'] = {
876+
// Add a tag that our runner can trigger on
877+
// in this case we are setting that node needs to be higher than 0.10.X to run
878+
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
879+
880+
// The actual test we wish to run
881+
test: function(configuration, test) {
882+
var db = configuration.newDbInstance(configuration.writeConcernMax(), {poolSize:1, auto_reconnect:false});
883+
// Establish connection to db
884+
db.open(function(err, db) {
885+
test.equal(null, err);
886+
887+
var collection = db.collection('w0crudoperations');
888+
collection.insertOne({}, function(err, r) {
889+
console.log("-------------------------------------------")
890+
console.dir(err)
891+
console.dir(r)
892+
893+
db.close();
894+
test.done();
895+
});
896+
897+
// collection.insertOne({a:1});
898+
// collection.insertMany([{b:1}]);
899+
// collection.updateOne({c:1}, {$set:{a:1}}, {upsert:true});
900+
901+
902+
// db.collection('try').updateOne({_id:1}, {$set:{x:1}}, {upsert:true, w:0}, function(err, r) {
903+
// test.equal(null, err);
904+
// test.ok(r != null);
905+
906+
// db.close();
907+
// test.done();
908+
// });
909+
});
910+
}
911+
}

test/functional/sharding_connection_tests.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,40 @@ exports['Should correctly emit open and fullsetup to all db instances'] = {
141141
});
142142
});
143143
}
144-
}
144+
}
145+
146+
/**
147+
* @ignore
148+
*/
149+
exports['Should exercise all options on mongos topology'] = {
150+
metadata: { requires: { topology: 'sharded' } },
151+
152+
// The actual test we wish to run
153+
test: function(configuration, test) {
154+
var MongoClient = configuration.require.MongoClient;
155+
156+
var url = f('mongodb://%s:%s,%s:%s/sharded_test_db?w=1&readPreference=secondaryPreferred&readPreferenceTags=sf%3A1&readPreferenceTags='
157+
, configuration.host, configuration.port
158+
, configuration.host, configuration.port + 1);
159+
MongoClient.connect(url, {
160+
mongos: {
161+
haInterval: 500
162+
}
163+
}, function(err, db) {
164+
test.equal(null, err);
165+
test.ok(db != null);
166+
test.equal(500, db.serverConfig.haInterval);
167+
test.ok(db.serverConfig.capabilities() != null);
168+
test.ok(db.serverConfig.parserType() != null);
169+
test.equal(true, db.serverConfig.isConnected());
170+
test.ok(db.serverConfig.lastIsMaster() != null);
171+
test.ok(db.serverConfig.connections() != null);
172+
test.ok(db.serverConfig.isMasterDoc != null);
173+
test.ok(db.serverConfig.numberOfConnectedServers != null);
174+
test.ok(db.serverConfig.bson != null);
175+
176+
db.close();
177+
test.done();
178+
});
179+
}
180+
}

0 commit comments

Comments
 (0)