diff --git a/lib/mongo_client.js b/lib/mongo_client.js index e334d57fe7..b2737e0d04 100644 --- a/lib/mongo_client.js +++ b/lib/mongo_client.js @@ -16,7 +16,6 @@ const shallowClone = require('./utils').shallowClone; const authenticate = require('./authenticate'); const ServerSessionPool = require('mongodb-core').Sessions.ServerSessionPool; const executeOperation = require('./utils').executeOperation; -const isPromiseLike = require('./utils').isPromiseLike; /** * @fileOverview The **MongoClient** class is a class that allows for making Connections to MongoDB. @@ -519,7 +518,12 @@ MongoClient.prototype.withSession = function(options, operation) { if (typeof options === 'function') (operation = options), (options = undefined); const session = this.startSession(options); - const cleanupHandler = (err, result, opts) => { + let cleanupHandler = (err, result, opts) => { + // prevent multiple calls to cleanupHandler + cleanupHandler = () => { + throw new ReferenceError('cleanupHandler was called too many times'); + }; + opts = Object.assign({ throw: true }, opts); session.endSession(); diff --git a/test/functional/sessions_tests.js b/test/functional/sessions_tests.js index ccb6b2612c..8501c81ecf 100644 --- a/test/functional/sessions_tests.js +++ b/test/functional/sessions_tests.js @@ -93,54 +93,6 @@ describe('Sessions', function() { operation: (/* client */) => (/* session */) => { throw new Error('something went wrong!'); } - }, - { - description: 'should support operations that return promises with a callback', - operation: client => session => { - return client - .db('test') - .collection('foo') - .find({}, { session }) - .toArray(); - }, - callback: resolve => (err, res) => { - expect(err).to.not.exist; - expect(res).to.exist; - resolve(); - } - }, - { - description: 'should support operations that return rejected promises and a callback', - operation: (/* client */) => (/* session */) => { - return Promise.reject(new Error('something awful')); - }, - callback: resolve => (err, res) => { - expect(err).to.exist; - expect(res).to.not.exist; - resolve(); - } - }, - { - description: "should support operations that don't return promises with a callback", - operation: (/* client */) => (/* session */) => { - setTimeout(() => {}); - }, - callback: resolve => (err, res) => { - expect(err).to.exist; - expect(res).to.not.exist; - resolve(); - } - }, - { - description: 'should support operations that throw exceptions with a callback', - operation: (/* client */) => (/* session */) => { - throw new Error('something went wrong!'); - }, - callback: resolve => (err, res) => { - expect(err).to.exist; - expect(res).to.not.exist; - resolve(); - } } ].forEach(testCase => { it(testCase.description, function() {