|
| 1 | +'use strict'; |
| 2 | +const expect = require('chai').expect, |
| 3 | + mongo = require('../..'), |
| 4 | + setupDatabase = require('./shared').setupDatabase; |
| 5 | + |
| 6 | +const ignoredCommands = ['ismaster']; |
| 7 | +const test = { commands: { started: [], succeeded: [] } }; |
| 8 | +describe('Sessions', function() { |
| 9 | + before(function() { |
| 10 | + return setupDatabase(this.configuration); |
| 11 | + }); |
| 12 | + |
| 13 | + afterEach(() => test.listener.uninstrument()); |
| 14 | + beforeEach(function() { |
| 15 | + test.commands = { started: [], succeeded: [] }; |
| 16 | + test.listener = mongo.instrument(err => expect(err).to.be.null); |
| 17 | + test.listener.on('started', event => { |
| 18 | + if (ignoredCommands.indexOf(event.commandName) === -1) test.commands.started.push(event); |
| 19 | + }); |
| 20 | + |
| 21 | + test.listener.on('succeeded', event => { |
| 22 | + if (ignoredCommands.indexOf(event.commandName) === -1) test.commands.succeeded.push(event); |
| 23 | + }); |
| 24 | + |
| 25 | + test.client = this.configuration.newClient({ w: 1 }, { poolSize: 1, auto_reconnect: false }); |
| 26 | + return test.client.connect(); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should send endSessions for multiple sessions', { |
| 30 | + metadata: { requires: { topology: ['single'] } }, |
| 31 | + test: function(done) { |
| 32 | + var client = this.configuration.newClient({ w: 1 }, { poolSize: 1, auto_reconnect: false }); |
| 33 | + client.connect((err, client) => { |
| 34 | + let sessions = [client.startSession(), client.startSession()].map(s => s.id); |
| 35 | + |
| 36 | + client.close(err => { |
| 37 | + expect(err).to.not.exist; |
| 38 | + expect(test.commands.started).to.have.length(1); |
| 39 | + expect(test.commands.started[0].commandName).to.equal('endSessions'); |
| 40 | + expect(test.commands.started[0].command.endSessions).to.include.deep.members(sessions); |
| 41 | + |
| 42 | + expect(client.s.sessions).to.have.length(0); |
| 43 | + done(); |
| 44 | + }); |
| 45 | + }); |
| 46 | + } |
| 47 | + }); |
| 48 | +}); |
0 commit comments