-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sessions): MongoClient will now track sessions and release
As initially implemented, sessions must be explicitly ended by the user. This is likely to lead to cases where users forget to do this, and therefore leak sessions. Instead, MongoClient now tracks all sessions created on the client, and explicitly cleans them up upon client close. NODE-1106
- Loading branch information
Showing
5 changed files
with
72 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
const expect = require('chai').expect, | ||
mongo = require('../..'), | ||
setupDatabase = require('./shared').setupDatabase; | ||
|
||
const ignoredCommands = ['ismaster']; | ||
const test = { commands: { started: [], succeeded: [] } }; | ||
describe('Sessions', function() { | ||
before(function() { | ||
return setupDatabase(this.configuration); | ||
}); | ||
|
||
afterEach(() => test.listener.uninstrument()); | ||
beforeEach(function() { | ||
test.commands = { started: [], succeeded: [] }; | ||
test.listener = mongo.instrument(err => expect(err).to.be.null); | ||
test.listener.on('started', event => { | ||
if (ignoredCommands.indexOf(event.commandName) === -1) test.commands.started.push(event); | ||
}); | ||
|
||
test.listener.on('succeeded', event => { | ||
if (ignoredCommands.indexOf(event.commandName) === -1) test.commands.succeeded.push(event); | ||
}); | ||
|
||
test.client = this.configuration.newClient({ w: 1 }, { poolSize: 1, auto_reconnect: false }); | ||
return test.client.connect(); | ||
}); | ||
|
||
it('should send endSessions for multiple sessions', { | ||
metadata: { requires: { topology: ['single'] } }, | ||
test: function(done) { | ||
var client = this.configuration.newClient({ w: 1 }, { poolSize: 1, auto_reconnect: false }); | ||
client.connect((err, client) => { | ||
let sessions = [client.startSession(), client.startSession()].map(s => s.id); | ||
|
||
client.close(err => { | ||
expect(err).to.not.exist; | ||
expect(test.commands.started).to.have.length(1); | ||
expect(test.commands.started[0].commandName).to.equal('endSessions'); | ||
expect(test.commands.started[0].command.endSessions).to.include.deep.members(sessions); | ||
|
||
expect(client.s.sessions).to.have.length(0); | ||
done(); | ||
}); | ||
}); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters