Skip to content

Commit

Permalink
test(withSession): remove tests using callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Apr 19, 2018
1 parent afac811 commit 8dfa93d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 50 deletions.
8 changes: 6 additions & 2 deletions lib/mongo_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();

Expand Down
48 changes: 0 additions & 48 deletions test/functional/sessions_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 8dfa93d

Please sign in to comment.