diff --git a/lib/admin.js b/lib/admin.js index ff4b8157ca..01c96ffc7a 100644 --- a/lib/admin.js +++ b/lib/admin.js @@ -89,11 +89,12 @@ define.classMethod('command', { callback: true, promise: true }); */ Admin.prototype.buildInfo = function(options, callback) { if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; const cmd = { buildinfo: 1 }; return executeOperation(this.s.db.s.topology, this.s.db.executeDbAdminCommand.bind(this.s.db), [ cmd, - undefined, + options, callback ]); }; @@ -111,6 +112,7 @@ define.classMethod('buildInfo', { callback: true, promise: true }); */ Admin.prototype.serverInfo = function(options, callback) { if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; const cmd = { buildinfo: 1 }; return executeOperation(this.s.db.s.topology, this.s.db.executeDbAdminCommand.bind(this.s.db), [ @@ -132,6 +134,8 @@ define.classMethod('serverInfo', { callback: true, promise: true }); */ Admin.prototype.serverStatus = function(options, callback) { if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; + return executeOperation(this.s.db.s.topology, serverStatus, [this, options, callback]); }; @@ -158,6 +162,7 @@ define.classMethod('serverStatus', { callback: true, promise: true }); */ Admin.prototype.ping = function(options, callback) { if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; const cmd = { ping: 1 }; return executeOperation(this.s.db.s.topology, this.s.db.executeDbAdminCommand.bind(this.s.db), [ @@ -272,13 +277,15 @@ define.classMethod('removeUser', { callback: true, promise: true }); * @return {Promise} returns Promise if no callback passed */ Admin.prototype.validateCollection = function(collectionName, options, callback) { - var args = Array.prototype.slice.call(arguments, 1); - callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined; - - options = args.length ? args.shift() : {}; + if (typeof options === 'function') (callback = options), (options = {}); options = options || {}; - return executeOperation(this.s.db.s.topology, validateCollection, [this, collectionName, options, callback]); + return executeOperation(this.s.db.s.topology, validateCollection, [ + this, + collectionName, + options, + callback + ]); }; var validateCollection = function(self, collectionName, options, callback) { @@ -287,12 +294,12 @@ var validateCollection = function(self, collectionName, options, callback) { // Decorate command with extra options for (var i = 0; i < keys.length; i++) { - if (options.hasOwnProperty(keys[i])) { + if (options.hasOwnProperty(keys[i]) && keys[i] !== 'session') { command[keys[i]] = options[keys[i]]; } } - self.s.db.command(command, function(err, doc) { + self.s.db.command(command, options, function(err, doc) { if (err != null) return callback(err, null); if (doc.ok === 0) return callback(new Error('Error with validate command'), null); @@ -343,6 +350,8 @@ define.classMethod('listDatabases', { callback: true, promise: true }); */ Admin.prototype.replSetGetStatus = function(options, callback) { if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; + return executeOperation(this.s.db.s.topology, replSetGetStatus, [this, options, callback]); }; diff --git a/lib/authenticate.js b/lib/authenticate.js index f645c55e19..1a7003965c 100644 --- a/lib/authenticate.js +++ b/lib/authenticate.js @@ -81,6 +81,8 @@ var authenticate = function(client, username, password, options, callback) { module.exports = function(self, username, password, options, callback) { if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; + // Shallow copy the options options = shallowClone(options); diff --git a/lib/bulk/ordered.js b/lib/bulk/ordered.js index 66401faaa4..129ca70ca7 100644 --- a/lib/bulk/ordered.js +++ b/lib/bulk/ordered.js @@ -429,7 +429,7 @@ Object.defineProperty(OrderedBulkOperation.prototype, 'length', { // // Execute next write command in a chain -var executeCommands = function(self, callback) { +var executeCommands = function(self, options, callback) { if (self.s.batches.length === 0) { return handleCallback(callback, null, new BulkWriteResult(self.s.bulkResult)); } @@ -484,10 +484,10 @@ var executeCommands = function(self, callback) { } // Execute the next command in line - executeCommands(self, callback); + executeCommands(self, options, callback); }; - var finalOptions = { ordered: true }; + var finalOptions = Object.assign({ ordered: true }, options); if (self.s.writeConcern != null) { finalOptions.writeConcern = self.s.writeConcern; } @@ -563,7 +563,10 @@ var executeCommands = function(self, callback) { * @throws {MongoError} * @return {Promise} returns Promise if no callback passed */ -OrderedBulkOperation.prototype.execute = function(_writeConcern, callback) { +OrderedBulkOperation.prototype.execute = function(_writeConcern, options, callback) { + if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; + if (this.s.executed) { var executedError = toError('batch cannot be re-executed'); return typeof callback === 'function' @@ -588,7 +591,7 @@ OrderedBulkOperation.prototype.execute = function(_writeConcern, callback) { : this.s.promiseLibrary.reject(emptyBatchError); } - return executeOperation(this.s.topology, executeCommands, [this, callback]); + return executeOperation(this.s.topology, executeCommands, [this, options, callback]); }; define.classMethod('execute', { callback: true, promise: false }); diff --git a/lib/bulk/unordered.js b/lib/bulk/unordered.js index 06333142af..ca9e36bb6f 100644 --- a/lib/bulk/unordered.js +++ b/lib/bulk/unordered.js @@ -436,8 +436,8 @@ UnorderedBulkOperation.prototype.raw = function(op) { // // Execute the command -var executeBatch = function(self, batch, callback) { - var finalOptions = { ordered: false }; +var executeBatch = function(self, batch, options, callback) { + var finalOptions = Object.assign({ ordered: false }, options); if (self.s.writeConcern != null) { finalOptions.writeConcern = self.s.writeConcern; } @@ -506,11 +506,11 @@ var executeBatch = function(self, batch, callback) { // // Execute all the commands -var executeBatches = function(self, callback) { +var executeBatches = function(self, options, callback) { var numberOfCommandsToExecute = self.s.batches.length; // Execute over all the batches for (var i = 0; i < self.s.batches.length; i++) { - executeBatch(self, self.s.batches[i], function(err) { + executeBatch(self, self.s.batches[i], options, function(err) { // Count down the number of commands left to execute numberOfCommandsToExecute = numberOfCommandsToExecute - 1; @@ -575,7 +575,10 @@ var executeBatches = function(self, callback) { * @throws {MongoError} * @return {Promise} returns Promise if no callback passed */ -UnorderedBulkOperation.prototype.execute = function(_writeConcern, callback) { +UnorderedBulkOperation.prototype.execute = function(_writeConcern, options, callback) { + if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; + if (this.s.executed) { var executedError = toError('batch cannot be re-executed'); return typeof callback === 'function' @@ -602,7 +605,7 @@ UnorderedBulkOperation.prototype.execute = function(_writeConcern, callback) { : this.s.promiseLibrary.reject(emptyBatchError); } - return executeOperation(this.s.topology, executeBatches, [this, callback]); + return executeOperation(this.s.topology, executeBatches, [this, options, callback]); }; define.classMethod('execute', { callback: true, promise: false }); diff --git a/lib/collection.js b/lib/collection.js index 0913374db2..51d0273146 100644 --- a/lib/collection.js +++ b/lib/collection.js @@ -889,6 +889,7 @@ define.classMethod('insert', { callback: true, promise: true }); */ Collection.prototype.updateOne = function(filter, update, options, callback) { if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; var err = checkForAtomicOperators(update); if (err) { @@ -1013,6 +1014,7 @@ define.classMethod('replaceOne', { callback: true, promise: true }); */ Collection.prototype.updateMany = function(filter, update, options, callback) { if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; var err = checkForAtomicOperators(update); if (err) { @@ -1119,13 +1121,22 @@ var updateDocuments = function(self, selector, document, options, callback) { * @deprecated use updateOne, updateMany or bulkWrite */ Collection.prototype.update = function(selector, document, options, callback) { + if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; + // Add ignoreUndfined if (this.s.options.ignoreUndefined) { options = shallowClone(options); options.ignoreUndefined = this.s.options.ignoreUndefined; } - return executeOperation(this.s.topology, updateDocuments, [this, selector, document, options, callback]); + return executeOperation(this.s.topology, updateDocuments, [ + this, + selector, + document, + options, + callback + ]); }; define.classMethod('update', { callback: true, promise: true }); @@ -1498,13 +1509,13 @@ define.classMethod('drop', { callback: true, promise: true }); */ Collection.prototype.options = function(opts, callback) { if (typeof opts === 'function') (callback = opts), (opts = {}); + opts = opts || {}; return executeOperation(this.s.topology, options, [this, opts, callback]); }; var options = function(self, opts, callback) { - opts = assign({}, { name: self.s.name }, opts); - self.s.db.listCollections(opts).toArray(function(err, collections) { + self.s.db.listCollections({ name: self.s.name }, opts).toArray(function(err, collections) { if (err) return handleCallback(callback, err); if (collections.length === 0) { return handleCallback( @@ -1530,6 +1541,7 @@ define.classMethod('options', { callback: true, promise: true }); */ Collection.prototype.isCapped = function(options, callback) { if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; return executeOperation(this.s.topology, isCapped, [this, options, callback]); }; @@ -1596,6 +1608,7 @@ define.classMethod('createIndex', { callback: true, promise: true }); */ Collection.prototype.createIndexes = function(indexSpecs, options, callback) { if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; return executeOperation(this.s.topology, createIndexes, [this, indexSpecs, options, callback]); }; @@ -1842,6 +1855,7 @@ define.classMethod('ensureIndex', { callback: true, promise: true }); */ Collection.prototype.indexExists = function(indexes, options, callback) { if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; return executeOperation(this.s.topology, indexExists, [this, indexes, options, callback]); }; @@ -1939,8 +1953,9 @@ var count = function(self, query, options, callback) { if (hint) cmd.hint = hint; options = shallowClone(options); + // Ensure we have the right read preference inheritance - options = getReadPreference(self, options, self.s.db, self); + options = getReadPreference(self, options, self.s.db); // Do we have a readConcern specified if (self.s.readConcern) { @@ -1977,7 +1992,13 @@ Collection.prototype.distinct = function(key, query, options, callback) { var queryOption = args.length ? args.shift() || {} : {}; var optionsOption = args.length ? args.shift() || {} : {}; - return executeOperation(this.s.topology, distinct, [this, key, queryOption, optionsOption, callback]); + return executeOperation(this.s.topology, distinct, [ + this, + key, + queryOption, + optionsOption, + callback + ]); }; var distinct = function(self, key, query, options, callback) { @@ -2025,6 +2046,7 @@ define.classMethod('distinct', { callback: true, promise: true }); */ Collection.prototype.indexes = function(options, callback) { if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; return executeOperation(this.s.topology, indexes, [this, options, callback]); }; @@ -2148,7 +2170,13 @@ Collection.prototype.findOneAndReplace = function(filter, replacement, options, if (replacement == null || typeof replacement !== 'object') throw toError('replacement parameter must be an object'); - return executeOperation(this.s.topology, findOneAndReplace, [this, filter, replacement, options, callback]); + return executeOperation(this.s.topology, findOneAndReplace, [ + this, + filter, + replacement, + options, + callback + ]); }; var findOneAndReplace = function(self, filter, replacement, options, callback) { @@ -2192,7 +2220,13 @@ Collection.prototype.findOneAndUpdate = function(filter, update, options, callba if (update == null || typeof update !== 'object') throw toError('update parameter must be an object'); - return executeOperation(this.s.topology, findOneAndUpdate, [this, filter, update, options, callback]); + return executeOperation(this.s.topology, findOneAndUpdate, [ + this, + filter, + update, + options, + callback + ]); }; var findOneAndUpdate = function(self, filter, update, options, callback) { @@ -2241,7 +2275,14 @@ Collection.prototype.findAndModify = function(query, sort, doc, options, callbac // Force read preference primary options.readPreference = ReadPreference.PRIMARY; - return executeOperation(this.s.topology, findAndModify, [this, query, sort, doc, options, callback]); + return executeOperation(this.s.topology, findAndModify, [ + this, + query, + sort, + doc, + options, + callback + ]); }; var findAndModify = function(self, query, sort, doc, options, callback) { @@ -2679,7 +2720,8 @@ var geoNear = function(self, x, y, point, options, callback) { var exclude = { readPreference: true, geoNear: true, - near: true + near: true, + session: true }; // Filter out any excluded objects @@ -2736,7 +2778,7 @@ var geoHaystackSearch = function(self, x, y, options, callback) { }; // Remove read preference from hash if it exists - commandObject = decorateCommand(commandObject, options, { readPreference: true }); + commandObject = decorateCommand(commandObject, options, { readPreference: true, session: true }); options = shallowClone(options); // Ensure we have the right read preference inheritance @@ -3014,7 +3056,7 @@ var mapReduce = function(self, map, reduce, options, callback) { }; // Exclusion list - var exclusionList = ['readPreference']; + var exclusionList = ['readPreference', 'session']; // Add any other options passed in for (var n in options) { diff --git a/lib/cursor.js b/lib/cursor.js index 672b919f25..625817a43d 100644 --- a/lib/cursor.js +++ b/lib/cursor.js @@ -208,7 +208,9 @@ var define = (Cursor.define = new Define('Cursor', Cursor, true)); * @return {Promise} returns Promise if no callback passed */ Cursor.prototype.hasNext = function(callback) { - return executeOperation(this.s.topology, hasNext, [this, callback]); + return executeOperation(this.s.topology, hasNext, [this, callback], { + skipSessions: true + }); }; const hasNext = (self, callback) => { @@ -235,7 +237,9 @@ define.classMethod('hasNext', { callback: true, promise: true }); * @return {Promise} returns Promise if no callback passed */ Cursor.prototype.next = function(callback) { - return executeOperation(this.s.topology, next, [this, callback]); + return executeOperation(this.s.topology, next, [this, callback], { + skipSessions: true + }); }; const next = (self, callback) => { @@ -909,7 +913,9 @@ Cursor.prototype.toArray = function(callback) { }); } - return executeOperation(this.s.topology, toArray, [this, callback]); + return executeOperation(this.s.topology, toArray, [this, callback], { + skipSessions: true + }); }; var toArray = function(self, callback) { @@ -979,7 +985,9 @@ Cursor.prototype.count = function(applySkipLimit, opts, callback) { if (typeof opts === 'function') (callback = opts), (opts = {}); opts = opts || {}; - return executeOperation(this.s.topology, count, [this, applySkipLimit, opts, callback]); + return executeOperation(this.s.topology, count, [this, applySkipLimit, opts, callback], { + skipSessions: true + }); }; var count = function(self, applySkipLimit, opts, callback) { @@ -1128,7 +1136,9 @@ Cursor.prototype.explain = function(callback) { delete this.s.cmd['readConcern']; } - return executeOperation(this.s.topology, this._next.bind(this), [callback]); + return executeOperation(this.s.topology, this._next.bind(this), [callback], { + skipSessions: true + }); }; define.classMethod('explain', { callback: true, promise: true }); diff --git a/lib/db.js b/lib/db.js index 6c273e82fd..bbc73f338f 100644 --- a/lib/db.js +++ b/lib/db.js @@ -58,7 +58,8 @@ var illegalCommandFields = [ 'serializeFunctions', 'pkFactory', 'raw', - 'readPreference' + 'readPreference', + 'session' ]; /** @@ -494,11 +495,13 @@ var createCollection = function(self, name, options, callback) { // Get the write concern options var finalOptions = writeConcern(shallowClone(options), self, options); // Did the user destroy the topology - if (self.serverConfig && self.serverConfig.isDestroyed()) + if (self.serverConfig && self.serverConfig.isDestroyed()) { return callback(new MongoError('topology was destroyed')); + } + // Check if we have the name self - .listCollections({ name: name }) + .listCollections({ name: name }, finalOptions) .setReadPreference(ReadPreference.PRIMARY) .toArray(function(err, collections) { if (err != null) return handleCallback(callback, err, null); @@ -932,12 +935,14 @@ define.classMethod('dropDatabase', { callback: true, promise: true }); */ Db.prototype.collections = function(options, callback) { if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; + return executeOperation(this.s.topology, collections, [this, options, callback]); }; var collections = function(self, options, callback) { // Let's get the collection names - self.listCollections(options).toArray(function(err, documents) { + self.listCollections({}, options).toArray(function(err, documents) { if (err != null) return handleCallback(callback, err, null); // Filter collections removing any illegal ones documents = documents.filter(function(doc) { @@ -983,7 +988,12 @@ Db.prototype.executeDbAdminCommand = function(selector, options, callback) { options.readPreference = convertReadPreference(options.readPreference); } - return executeOperation(this.s.topology, executeDbAdminCommand, [this, selector, options, callback]); + return executeOperation(this.s.topology, executeDbAdminCommand, [ + this, + selector, + options, + callback + ]); }; const executeDbAdminCommand = (self, selector, options, callback) => { @@ -1032,7 +1042,13 @@ Db.prototype.createIndex = function(name, fieldOrSpec, options, callback) { // Shallow clone the options options = shallowClone(options); - return executeOperation(this.s.topology, createIndex, [this, name, fieldOrSpec, options, callback]); + return executeOperation(this.s.topology, createIndex, [ + this, + name, + fieldOrSpec, + options, + callback + ]); }; var createIndex = function(self, name, fieldOrSpec, options, callback) { @@ -1117,7 +1133,13 @@ Db.prototype.ensureIndex = function(name, fieldOrSpec, options, callback) { if (typeof options === 'function') (callback = options), (options = {}); options = options || {}; - return executeOperation(this.s.topology, ensureIndex, [this, name, fieldOrSpec, options, callback]); + return executeOperation(this.s.topology, ensureIndex, [ + this, + name, + fieldOrSpec, + options, + callback + ]); }; var ensureIndex = function(self, name, fieldOrSpec, options, callback) { @@ -1321,6 +1343,8 @@ define.classMethod('addUser', { callback: true, promise: true }); var _executeAuthRemoveUserCommand = function(self, username, options, callback) { if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; + // Did the user destroy the topology if (self.serverConfig && self.serverConfig.isDestroyed()) return callback(new MongoError('topology was destroyed')); @@ -1413,6 +1437,8 @@ Db.prototype.removeUser = function(username, options, callback) { */ Db.prototype.setProfilingLevel = function(level, options, callback) { if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; + return executeOperation(this.s.topology, setProfilingLevel, [this, level, options, callback]); }; @@ -1454,6 +1480,8 @@ define.classMethod('setProfilingLevel', { callback: true, promise: true }); */ Db.prototype.profilingInfo = function(options, callback) { if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; + return executeOperation(this.s.topology, profilingInfo, [this, options, callback]); }; @@ -1461,7 +1489,7 @@ var profilingInfo = function(self, options, callback) { try { self .collection('system.profile') - .find({}, options) + .find({}, null, options) .toArray(callback); } catch (err) { return callback(err, null); @@ -1480,6 +1508,8 @@ define.classMethod('profilingInfo', { callback: true, promise: true }); */ Db.prototype.profilingLevel = function(options, callback) { if (typeof options === 'function') (callback = options), (options = {}); + options = options || {}; + return executeOperation(this.s.topology, profilingLevel, [this, options, callback]); }; @@ -1600,17 +1630,19 @@ var createIndexUsingCreateIndexes = function(self, name, fieldOrSpec, options, c // Set up the index var indexes = [{ name: indexName, key: indexParameters.fieldHash }]; // merge all the options - var keysToOmit = Object.keys(indexes[0]); + var keysToOmit = Object.keys(indexes[0]).concat([ + 'w', + 'wtimeout', + 'j', + 'fsync', + 'readPreference', + 'session' + ]); + for (var optionName in options) { if (keysToOmit.indexOf(optionName) === -1) { indexes[0][optionName] = options[optionName]; } - - // Remove any write concern operations - var removeKeys = ['w', 'wtimeout', 'j', 'fsync', 'readPreference']; - for (var i = 0; i < removeKeys.length; i++) { - delete indexes[0][removeKeys[i]]; - } } // Get capabilities diff --git a/lib/gridfs/grid_store.js b/lib/gridfs/grid_store.js index 266e696884..0e14ccfd4d 100644 --- a/lib/gridfs/grid_store.js +++ b/lib/gridfs/grid_store.js @@ -661,16 +661,17 @@ define.classMethod('collection', { callback: true, promise: false, returns: [Col * @return {Promise} returns Promise if no callback passed * @deprecated Use GridFSBucket API instead */ -GridStore.prototype.readlines = function(separator, callback) { +GridStore.prototype.readlines = function(separator, options, callback) { var args = Array.prototype.slice.call(arguments, 0); callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined; separator = args.length ? args.shift() : '\n'; separator = separator || '\n'; + options = args.length ? args.shift() : {}; - return executeOperation(this.db.s.topology, readlines, [this, separator, callback]); + return executeOperation(this.db.s.topology, readlines, [this, separator, options, callback]); }; -var readlines = function(self, separator, callback) { +var readlines = function(self, separator, options, callback) { self.read(function(err, data) { if (err) return callback(err); @@ -758,16 +759,17 @@ define.classMethod('rewind', { callback: true, promise: true }); * @return {Promise} returns Promise if no callback passed * @deprecated Use GridFSBucket API instead */ -GridStore.prototype.read = function(length, buffer, callback) { +GridStore.prototype.read = function(length, buffer, options, callback) { var args = Array.prototype.slice.call(arguments, 0); callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined; length = args.length ? args.shift() : null; buffer = args.length ? args.shift() : null; + options = args.length ? args.shift() : {}; - return executeOperation(this.db.s.topology, read, [this, length, buffer, callback]); + return executeOperation(this.db.s.topology, read, [this, length, buffer, options, callback]); }; -var read = function(self, length, buffer, callback) { +var read = function(self, length, buffer, options, callback) { // The data is a c-terminated string and thus the length - 1 var finalLength = length == null ? self.length - self.position : length; var finalBuffer = buffer == null ? new Buffer(finalLength) : buffer; @@ -872,15 +874,22 @@ define.classMethod('tell', { callback: true, promise: true }); * @return {Promise} returns Promise if no callback passed * @deprecated Use GridFSBucket API instead */ -GridStore.prototype.seek = function(position, seekLocation, callback) { +GridStore.prototype.seek = function(position, seekLocation, options, callback) { var args = Array.prototype.slice.call(arguments, 1); callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined; seekLocation = args.length ? args.shift() : null; + options = args.length ? args.shift() : {}; - return executeOperation(this.db.s.topology, seek, [this, position, seekLocation, callback]); + return executeOperation(this.db.s.topology, seek, [ + this, + position, + seekLocation, + options, + callback + ]); }; -var seek = function(self, position, seekLocation, callback) { +var seek = function(self, position, seekLocation, options, callback) { // Seek only supports read mode if (self.mode !== 'r') { return callback( diff --git a/lib/topologies/topology_base.js b/lib/topologies/topology_base.js index 65b02f388b..c0efc4f4da 100644 --- a/lib/topologies/topology_base.js +++ b/lib/topologies/topology_base.js @@ -306,7 +306,7 @@ class TopologyBase extends EventEmitter { } startSession(options) { - return new ClientSession(this.s.coreTopology, this.s.sessionPool, options); + return new ClientSession(this, this.s.sessionPool, options); } // Server capabilities diff --git a/lib/utils.js b/lib/utils.js index 3f785a6e96..5acbd82632 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -126,6 +126,7 @@ var checkCollectionName = function checkCollectionName(collectionName) { var handleCallback = function(callback, err, value1, value2) { try { if (callback == null) return; + if (callback) { return value2 ? callback(err, value1, value2) : callback(err, value1); } @@ -405,12 +406,31 @@ const executeOperation = (topology, operation, args, options) => { let resultMutator = options.resultMutator; let callback = args[args.length - 1]; + // The driver sessions spec mandates that we implicitly create sessions for operations + // that are not explicitly provided with a session. + + let session; + if (!options.skipSessions) { + const opOptions = args[args.length - 2]; + if (opOptions == null || opOptions.session == null) { + session = topology.startSession(); + assign(args[args.length - 2], { session: session }); + } + } + // Execute using callback if (typeof callback === 'function') { callback = args.pop(); args.push((err, result) => { - if (err) return callback(err, null); - return resultMutator ? callback(null, resultMutator(result)) : callback(null, result); + if (session) { + session.endSession(() => { + if (err) return callback(err, null); + return resultMutator ? callback(null, resultMutator(result)) : callback(null, result); + }); + } else { + if (err) return callback(err, null); + return resultMutator ? callback(null, resultMutator(result)) : callback(null, result); + } }); return operation.apply(null, args); @@ -424,9 +444,17 @@ const executeOperation = (topology, operation, args, options) => { return new Promise(function(resolve, reject) { args[args.length - 1] = (err, r) => { - if (err) return reject(err); - if (resultMutator) return resolve(resultMutator(r)); - resolve(r); + if (session) { + session.endSession(() => { + if (err) return reject(err); + if (resultMutator) return resolve(resultMutator(r)); + resolve(r); + }); + } else { + if (err) return reject(err); + if (resultMutator) return resolve(resultMutator(r)); + resolve(r); + } }; operation.apply(null, args); diff --git a/test/functional/apm_tests.js b/test/functional/apm_tests.js index 02529a0aeb..73803bba85 100644 --- a/test/functional/apm_tests.js +++ b/test/functional/apm_tests.js @@ -993,6 +993,7 @@ describe('APM', function() { return setupDatabase(this.configuration); }); + var filterSessionsCommands = x => x.filter(y => y.commandName !== 'endSessions'); var validateExpecations = function(expectation, results) { var obj, databaseName, commandName, reply, result; if (expectation.command_started_event) { @@ -1043,6 +1044,7 @@ describe('APM', function() { commandName = obj.command_name; // Get the result + results.failures = filterSessionsCommands(results.failures); result = results.failures.shift(); // Validate the test diff --git a/test/functional/buffering_proxy_tests.js b/test/functional/buffering_proxy_tests.js index 3134bf0d07..8bc761e7ee 100644 --- a/test/functional/buffering_proxy_tests.js +++ b/test/functional/buffering_proxy_tests.js @@ -146,6 +146,8 @@ describe.skip('Buffering Proxy', function() { request.reply({ ok: 1, n: 1 }); } else if (doc.aggregate) { request.reply({ ok: 1, n: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } } }); @@ -158,6 +160,8 @@ describe.skip('Buffering Proxy', function() { } else { if (doc.ismaster) { request.reply(firstSecondary[currentIsMasterIndex]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } } }); @@ -170,6 +174,8 @@ describe.skip('Buffering Proxy', function() { } else { if (doc.ismaster) { request.reply(secondSecondary[currentIsMasterIndex]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } } }); @@ -362,6 +368,8 @@ describe.skip('Buffering Proxy', function() { } else { if (doc.ismaster) { request.reply(primary[currentIsMasterIndex]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } } }); @@ -378,6 +386,8 @@ describe.skip('Buffering Proxy', function() { request.reply({ ok: 1, n: 10 }); } else if (doc.find) { request.reply({ ok: 1, n: 10 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } } }); @@ -394,6 +404,8 @@ describe.skip('Buffering Proxy', function() { request.reply({ ok: 1, n: 10 }); } else if (doc.find) { request.reply({ ok: 1, n: 10 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } } }); diff --git a/test/functional/change_stream_tests.js b/test/functional/change_stream_tests.js index 0b642d2792..99382e20f4 100644 --- a/test/functional/change_stream_tests.js +++ b/test/functional/change_stream_tests.js @@ -778,6 +778,8 @@ describe('Change Streams', function() { defaultFields ) ); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } // Do not respond to other requests }); @@ -900,6 +902,8 @@ describe('Change Streams', function() { request.reply(changeDoc, { cursorId: new Long(1407, 1407) }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); }); @@ -1356,6 +1360,8 @@ describe('Change Streams', function() { request.reply(changeDoc, { cursorId: new Long(1407, 1407) }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); }); diff --git a/test/functional/collations_tests.js b/test/functional/collations_tests.js index d1c6568726..113ba91532 100644 --- a/test/functional/collations_tests.js +++ b/test/functional/collations_tests.js @@ -37,12 +37,13 @@ describe('Collation', function() { const singleServer = yield mock.createServer(); singleServer.setMessageHandler(request => { var doc = request.document; - if (doc.ismaster) { request.reply(primary[0]); } else if (doc.findandmodify) { commandResult = doc; request.reply({ ok: 1, result: {} }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -93,6 +94,8 @@ describe('Collation', function() { } else if (doc.count) { commandResult = doc; request.reply({ ok: 1, result: { n: 1 } }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -137,6 +140,8 @@ describe('Collation', function() { } else if (doc.aggregate) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -186,6 +191,8 @@ describe('Collation', function() { } else if (doc.distinct) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -232,6 +239,8 @@ describe('Collation', function() { } else if (doc.geoNear) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -280,6 +289,8 @@ describe('Collation', function() { } else if (doc.group) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -336,6 +347,8 @@ describe('Collation', function() { } else if (doc.mapreduce) { commandResult = doc; request.reply({ ok: 1, result: 'tempCollection' }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -390,6 +403,8 @@ describe('Collation', function() { } else if (doc.delete) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -434,6 +449,8 @@ describe('Collation', function() { } else if (doc.update) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -482,6 +499,8 @@ describe('Collation', function() { } else if (doc.find) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -529,6 +548,8 @@ describe('Collation', function() { } else if (doc.find) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -577,6 +598,8 @@ describe('Collation', function() { } else if (doc.find) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -633,6 +656,8 @@ describe('Collation', function() { } else if (doc.create) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -676,6 +701,8 @@ describe('Collation', function() { request.reply(primary[0]); } else if (doc.find) { request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -718,6 +745,8 @@ describe('Collation', function() { request.reply(primary[0]); } else if (doc.find) { request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -761,6 +790,8 @@ describe('Collation', function() { request.reply({ ok: 1 }); } else if (doc.delete) { request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -817,6 +848,8 @@ describe('Collation', function() { request.reply(primary[0]); } else if (doc.update) { request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -925,6 +958,8 @@ describe('Collation', function() { var doc = request.document; if (doc.ismaster) { request.reply(firstSecondary[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -932,6 +967,8 @@ describe('Collation', function() { var doc = request.document; if (doc.ismaster) { request.reply(arbiter[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -988,6 +1025,8 @@ describe('Collation', function() { } else if (doc.createIndexes) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -1039,6 +1078,8 @@ describe('Collation', function() { request.reply(primary[0]); } else if (doc.createIndexes) { request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -1082,6 +1123,8 @@ describe('Collation', function() { request.reply(primary[0]); } else if (doc.createIndexes) { request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); diff --git a/test/functional/command_write_concern_tests.js b/test/functional/command_write_concern_tests.js index 44d9a97d28..e71343b16d 100644 --- a/test/functional/command_write_concern_tests.js +++ b/test/functional/command_write_concern_tests.js @@ -89,6 +89,8 @@ describe('Command Write Concern', function() { } else if (doc.aggregate) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -96,6 +98,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(firstSecondary[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -103,6 +107,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(arbiter[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -211,6 +217,8 @@ describe('Command Write Concern', function() { } else if (doc.create) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -218,6 +226,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(firstSecondary[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -225,6 +235,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(arbiter[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -319,6 +331,8 @@ describe('Command Write Concern', function() { } else if (doc.createIndexes) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -326,6 +340,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(firstSecondary[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -333,6 +349,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(arbiter[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -432,6 +450,8 @@ describe('Command Write Concern', function() { } else if (doc.drop) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -439,6 +459,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(firstSecondary[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -446,6 +468,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(arbiter[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -543,6 +567,8 @@ describe('Command Write Concern', function() { } else if (doc.dropDatabase) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -550,6 +576,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(firstSecondary[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -557,6 +585,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(arbiter[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -656,6 +686,8 @@ describe('Command Write Concern', function() { } else if (doc.dropIndexes) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -663,6 +695,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(firstSecondary[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -670,6 +704,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(arbiter[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -768,6 +804,8 @@ describe('Command Write Concern', function() { } else if (doc.mapreduce) { commandResult = doc; request.reply({ ok: 1, result: 'tempCollection' }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -775,6 +813,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(firstSecondary[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -782,6 +822,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(arbiter[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -887,6 +929,8 @@ describe('Command Write Concern', function() { } else if (doc.createUser) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -894,6 +938,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(firstSecondary[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -901,6 +947,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(arbiter[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -994,6 +1042,8 @@ describe('Command Write Concern', function() { } else if (doc.dropUser) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -1001,6 +1051,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(firstSecondary[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -1008,6 +1060,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(arbiter[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -1101,6 +1155,8 @@ describe('Command Write Concern', function() { } else if (doc.findandmodify) { commandResult = doc; request.reply({ ok: 1, result: {} }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -1108,6 +1164,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(firstSecondary[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -1115,6 +1173,8 @@ describe('Command Write Concern', function() { var doc = request.document; if (doc.ismaster) { request.reply(arbiter[0]); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); diff --git a/test/functional/connection_tests.js b/test/functional/connection_tests.js index 7055c8e6e0..635908972e 100644 --- a/test/functional/connection_tests.js +++ b/test/functional/connection_tests.js @@ -283,7 +283,7 @@ describe('Connection', function() { configuration.url(), { auto_reconnect: true, poolSize: 4 }, connectionTester(configuration, 'testConnectServerOptions', function(client) { - test.equal(1, client.topology.poolSize); + test.equal(2, client.topology.poolSize); test.equal(4, client.topology.s.coreTopology.s.pool.size); test.equal(true, client.topology.autoReconnect); client.close(); diff --git a/test/functional/max_staleness_tests.js b/test/functional/max_staleness_tests.js index ebad18dbc5..e9fee82fd3 100644 --- a/test/functional/max_staleness_tests.js +++ b/test/functional/max_staleness_tests.js @@ -35,6 +35,8 @@ describe('Max Staleness', function() { }, ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); }); diff --git a/test/functional/mongo_client_options_tests.js b/test/functional/mongo_client_options_tests.js index 65ca1afa87..45215f399c 100644 --- a/test/functional/mongo_client_options_tests.js +++ b/test/functional/mongo_client_options_tests.js @@ -23,7 +23,7 @@ describe('MongoClient Options', function() { configuration.url(), { autoReconnect: true, poolSize: 4 }, connectionTester(configuration, 'testConnectServerOptions', function(client) { - test.equal(1, client.topology.poolSize); + test.equal(2, client.topology.poolSize); test.equal(4, client.topology.s.coreTopology.s.pool.size); test.equal(true, client.topology.autoReconnect); client.close(); @@ -48,7 +48,7 @@ describe('MongoClient Options', function() { configuration.url(), { autoReconnect: true, poolSize: 4 }, connectionTester(configuration, 'testConnectServerOptions', function(client) { - test.equal(1, client.topology.poolSize); + test.equal(2, client.topology.poolSize); test.equal(4, client.topology.s.coreTopology.s.pool.size); test.equal(true, client.topology.autoReconnect); client.close(); diff --git a/test/functional/readpreference_tests.js b/test/functional/readpreference_tests.js index 9701df9eab..26dae73d67 100644 --- a/test/functional/readpreference_tests.js +++ b/test/functional/readpreference_tests.js @@ -32,7 +32,10 @@ describe('ReadPreference', function() { // Set up our checker method client.topology.command = function() { var args = Array.prototype.slice.call(arguments, 0); - test.equal(ReadPreference.SECONDARY_PREFERRED, args[2].readPreference.preference); + if (args[0] === 'integration_tests.$cmd') { + test.equal(ReadPreference.SECONDARY_PREFERRED, args[2].readPreference.preference); + } + return command.apply(db.serverConfig, args); }; @@ -74,7 +77,10 @@ describe('ReadPreference', function() { // Set up our checker method client.topology.command = function() { var args = Array.prototype.slice.call(arguments, 0); - test.equal(ReadPreference.SECONDARY_PREFERRED, args[2].readPreference.preference); + if (args[0] === 'integration_tests.$cmd') { + test.equal(ReadPreference.SECONDARY_PREFERRED, args[2].readPreference.preference); + } + return command.apply(db.serverConfig, args); }; @@ -162,7 +168,10 @@ describe('ReadPreference', function() { // Set up our checker method client.topology.command = function() { var args = Array.prototype.slice.call(arguments, 0); - test.equal(ReadPreference.SECONDARY_PREFERRED, args[2].readPreference.preference); + if (args[0] === 'integration_tests.$cmd') { + test.equal(ReadPreference.SECONDARY_PREFERRED, args[2].readPreference.preference); + } + return command.apply(db.serverConfig, args); }; @@ -205,7 +214,10 @@ describe('ReadPreference', function() { // Set up our checker method client.topology.command = function() { var args = Array.prototype.slice.call(arguments, 0); - test.equal(ReadPreference.SECONDARY_PREFERRED, args[2].readPreference.preference); + if (args[0] === 'integration_tests.$cmd') { + test.equal(ReadPreference.SECONDARY_PREFERRED, args[2].readPreference.preference); + } + return command.apply(db.serverConfig, args); }; @@ -250,7 +262,10 @@ describe('ReadPreference', function() { // Set up our checker method client.topology.command = function() { var args = Array.prototype.slice.call(arguments, 0); - test.equal(ReadPreference.SECONDARY_PREFERRED, args[2].readPreference.preference); + if (args[0] === 'integration_tests.$cmd') { + test.equal(ReadPreference.SECONDARY_PREFERRED, args[2].readPreference.preference); + } + return command.apply(db.serverConfig, args); }; @@ -305,7 +320,10 @@ describe('ReadPreference', function() { // Set up our checker method client.topology.command = function() { var args = Array.prototype.slice.call(arguments, 0); - test.equal(ReadPreference.SECONDARY_PREFERRED, args[2].readPreference.preference); + if (args[0] === 'integration_tests.$cmd') { + test.equal(ReadPreference.SECONDARY_PREFERRED, args[2].readPreference.preference); + } + return command.apply(db.serverConfig, args); }; @@ -400,7 +418,10 @@ describe('ReadPreference', function() { // Set up our checker method client.topology.command = function() { var args = Array.prototype.slice.call(arguments, 0); - test.equal(ReadPreference.SECONDARY_PREFERRED, args[2].readPreference.preference); + if (args[0] === 'integration_tests.$cmd') { + test.equal(ReadPreference.SECONDARY_PREFERRED, args[2].readPreference.preference); + } + return command.apply(db.serverConfig, args); }; @@ -461,7 +482,10 @@ describe('ReadPreference', function() { // Set up our checker method client.topology.command = function() { var args = Array.prototype.slice.call(arguments, 0); - test.equal(ReadPreference.SECONDARY_PREFERRED, args[2].readPreference.preference); + if (args[0] === 'integration_tests.$cmd') { + test.equal(ReadPreference.SECONDARY_PREFERRED, args[2].readPreference.preference); + } + return command.apply(db.serverConfig, args); }; @@ -496,7 +520,10 @@ describe('ReadPreference', function() { // Set up our checker method client.topology.command = function() { var args = Array.prototype.slice.call(arguments, 0); - test.equal(ReadPreference.SECONDARY, args[2].readPreference.preference); + if (args[0] === 'integration_tests.$cmd') { + test.equal(ReadPreference.SECONDARY, args[2].readPreference.preference); + } + return command.apply(db.serverConfig, args); }; @@ -505,7 +532,10 @@ describe('ReadPreference', function() { client.topology.command = function() { var args = Array.prototype.slice.call(arguments, 0); - test.equal(ReadPreference.SECONDARY_PREFERRED, args[2].readPreference.preference); + if (args[0] === 'integration_tests.$cmd') { + test.equal(ReadPreference.SECONDARY_PREFERRED, args[2].readPreference.preference); + } + return command.apply(db.serverConfig, args); }; diff --git a/test/functional/replicaset_mock_tests.js b/test/functional/replicaset_mock_tests.js index f70d7fc20c..119c7e16bd 100644 --- a/test/functional/replicaset_mock_tests.js +++ b/test/functional/replicaset_mock_tests.js @@ -35,6 +35,8 @@ describe('ReplSet (mocks)', function() { request.reply(serverIsMaster[0]); } else if (doc.insert) { request.reply({ ok: 1, n: doc.documents, lastOp: new Date() }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -44,6 +46,8 @@ describe('ReplSet (mocks)', function() { request.reply(serverIsMaster[1]); } else if (doc.insert) { request.reply({ ok: 1, n: doc.documents, lastOp: new Date() }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); }); diff --git a/test/functional/view_tests.js b/test/functional/view_tests.js index 7584fe5e98..468da6a94f 100644 --- a/test/functional/view_tests.js +++ b/test/functional/view_tests.js @@ -39,6 +39,8 @@ describe('Views', function() { } else if (doc.create) { commandResult = doc; request.reply({ ok: 1 }); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); diff --git a/test/unit/sessions/client_tests.js b/test/unit/sessions/client_tests.js index ad252c68e6..82950b8ca4 100644 --- a/test/unit/sessions/client_tests.js +++ b/test/unit/sessions/client_tests.js @@ -22,6 +22,8 @@ describe('Sessions', function() { var doc = request.document; if (doc.ismaster) { request.reply(assign({}, mock.DEFAULT_ISMASTER)); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); @@ -49,6 +51,8 @@ describe('Sessions', function() { logicalSessionTimeoutMinutes: 10 }) ); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); } }); diff --git a/yarn.lock b/yarn.lock index 68cf33e3fe..a643f1dadc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -47,13 +47,13 @@ ajv@^4.7.0: json-stable-stringify "^1.0.1" ajv@^5.1.0, ajv@^5.2.0, ajv@^5.2.3: - version "5.2.3" - resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.2.3.tgz#c06f598778c44c6b161abafe3466b81ad1814ed2" + version "5.3.0" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.3.0.tgz#4414ff74a50879c208ee5fdc826e32c303549eda" dependencies: co "^4.6.0" fast-deep-equal "^1.0.0" + fast-json-stable-stringify "^2.0.0" json-schema-traverse "^0.3.0" - json-stable-stringify "^1.0.1" align-text@^0.1.1, align-text@^0.1.3: version "0.1.4" @@ -75,14 +75,14 @@ ampersand-events@^2.0.1: lodash "^4.6.1" ampersand-state@^5.0.1: - version "5.0.2" - resolved "https://registry.yarnpkg.com/ampersand-state/-/ampersand-state-5.0.2.tgz#16830def866c644ecd21da8c8ba8717aa2b8d23c" + version "5.0.3" + resolved "https://registry.yarnpkg.com/ampersand-state/-/ampersand-state-5.0.3.tgz#33402ea604375af64a249f664a0312c1160da475" dependencies: ampersand-events "^2.0.1" ampersand-version "^1.0.0" array-next "~0.0.1" key-tree-store "^1.3.0" - lodash "^4.11.1" + lodash "^4.12.0" ampersand-version@^1.0.0, ampersand-version@^1.0.2: version "1.0.2" @@ -313,8 +313,8 @@ babylon@^6.18.0: resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3" babylon@~7.0.0-beta.19: - version "7.0.0-beta.27" - resolved "https://registry.yarnpkg.com/babylon/-/babylon-7.0.0-beta.27.tgz#b6edd30ef30619e2f630eb52585fdda84e6542cd" + version "7.0.0-beta.29" + resolved "https://registry.yarnpkg.com/babylon/-/babylon-7.0.0-beta.29.tgz#6a3e0e6287390385a36f5511e7f94db8618574ae" balanced-match@^1.0.0: version "1.0.0" @@ -483,8 +483,8 @@ chalk@^1.1.1, chalk@^1.1.3: supports-color "^2.0.0" chalk@^2.0.0, chalk@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.1.0.tgz#ac5becf14fa21b99c6c92ca7a7d7cfd5b17e743e" + version "2.3.0" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.3.0.tgz#b5ea48efc9c1793dccc9b4767c93914d3f2d52ba" dependencies: ansi-styles "^3.1.0" escape-string-regexp "^1.0.5" @@ -943,8 +943,8 @@ eslint-scope@^3.7.1: estraverse "^4.1.1" eslint@^4.5.0: - version "4.8.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.8.0.tgz#229ef0e354e0e61d837c7a80fdfba825e199815e" + version "4.9.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.9.0.tgz#76879d274068261b191fe0f2f56c74c2f4208e8b" dependencies: ajv "^5.2.0" babel-code-frame "^6.22.0" @@ -1085,6 +1085,10 @@ fast-diff@^1.1.1: version "1.1.2" resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.1.2.tgz#4b62c42b8e03de3f848460b639079920695d0154" +fast-json-stable-stringify@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2" + fast-levenshtein@~2.0.4: version "2.0.6" resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" @@ -1343,8 +1347,8 @@ growl@1.9.2: resolved "https://registry.yarnpkg.com/growl/-/growl-1.9.2.tgz#0ea7743715db8d8de2c5ede1775e1b45ac85c02f" handlebars@^4.0.1: - version "4.0.10" - resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.0.10.tgz#3d30c718b09a3d96f23ea4cc1f403c4d3ba9ff4f" + version "4.0.11" + resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.0.11.tgz#630a35dfe0294bc281edae6ffc5d329fc7982dcc" dependencies: async "^1.4.0" optimist "^0.6.1" @@ -1477,8 +1481,8 @@ ieee754@^1.1.4: resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.8.tgz#be33d40ac10ef1926701f6f08a2d86fbfd1ad3e4" ignore@^3.3.3: - version "3.3.5" - resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.5.tgz#c4e715455f6073a8d7e5dae72d2fc9d71663dba6" + version "3.3.7" + resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.7.tgz#612289bfb3c220e186a58118618d5be8c1bab021" imurmurhash@^0.1.4: version "0.1.4" @@ -1533,8 +1537,8 @@ is-arrayish@^0.2.1: resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d" is-buffer@^1.1.5: - version "1.1.5" - resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.5.tgz#1f3b26ef613b214b88cbca23cc6c01d87961eecc" + version "1.1.6" + resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" is-builtin-module@^1.0.0: version "1.0.0" @@ -1971,7 +1975,7 @@ lodash.transform@^4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash.transform/-/lodash.transform-4.6.0.tgz#12306422f63324aed8483d3f38332b5f670547a0" -lodash@^4.0.0, lodash@^4.11.1, lodash@^4.14.0, lodash@^4.17.4, lodash@^4.3.0, lodash@^4.6.1: +lodash@^4.0.0, lodash@^4.12.0, lodash@^4.14.0, lodash@^4.17.4, lodash@^4.3.0, lodash@^4.6.1: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" @@ -2001,10 +2005,10 @@ lru-cache@^4.0.1: yallist "^2.1.2" make-dir@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-1.0.0.tgz#97a011751e91dd87cfadef58832ebb04936de978" + version "1.1.0" + resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-1.1.0.tgz#19b4369fe48c116f53c2af95ad102c0e39e85d51" dependencies: - pify "^2.3.0" + pify "^3.0.0" map-stream@~0.1.0: version "0.1.0" @@ -2026,7 +2030,11 @@ metamocha@^1.2.5: dependencies: mocha "^3.5.3" -mime-db@^1.28.0, mime-db@~1.30.0: +mime-db@^1.28.0: + version "1.31.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.31.0.tgz#a49cd8f3ebf3ed1a482b60561d9105ad40ca74cb" + +mime-db@~1.30.0: version "1.30.0" resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.30.0.tgz#74c643da2dd9d6a45399963465b26d5ca7d71f01" @@ -2098,7 +2106,7 @@ mongodb-core@2.1.17: mongodb-core@mongodb-js/mongodb-core#3.0.0: version "2.1.90" - resolved "https://codeload.github.com/mongodb-js/mongodb-core/tar.gz/d92efecfabd8774df6ff46b7fcabdd4ddcc83aed" + resolved "https://codeload.github.com/mongodb-js/mongodb-core/tar.gz/1bf9864cc427e95eccb4fcebb7334b684df61956" dependencies: bson "~1.0.4" require_optional "^1.0.1" @@ -2703,8 +2711,8 @@ sntp@1.x.x: hoek "2.x.x" sntp@2.x.x: - version "2.0.2" - resolved "https://registry.yarnpkg.com/sntp/-/sntp-2.0.2.tgz#5064110f0af85f7cfdb7d6b67a40028ce52b4b2b" + version "2.1.0" + resolved "https://registry.yarnpkg.com/sntp/-/sntp-2.1.0.tgz#2c6cec14fedc2222739caf9b5c3d85d1cc5a2cc8" dependencies: hoek "4.x.x" @@ -2832,8 +2840,8 @@ strip-bom@^3.0.0: resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3" strip-dirs@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/strip-dirs/-/strip-dirs-2.0.0.tgz#610cdb2928200da0004f41dcb90fc95cd919a0b6" + version "2.1.0" + resolved "https://registry.yarnpkg.com/strip-dirs/-/strip-dirs-2.1.0.tgz#4987736264fc344cf20f6c34aca9d13d1d4ed6c5" dependencies: is-natural-number "^4.0.1" @@ -2868,8 +2876,8 @@ supports-color@^3.1.0: has-flag "^1.0.0" supports-color@^4.0.0: - version "4.4.0" - resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.4.0.tgz#883f7ddabc165142b2a61427f3352ded195d1a3e" + version "4.5.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.5.0.tgz#be7a0de484dec5c5cddf8b3d59125044912f635b" dependencies: has-flag "^2.0.0"