Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
test(sessions): add test for ClientSession.endSession
Browse files Browse the repository at this point in the history
NODE-1088
  • Loading branch information
mbroadst committed Oct 6, 2017
1 parent 19e1b0f commit 31dbaf4
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/tests/unit/single/sessions_tests.js
Expand Up @@ -217,6 +217,49 @@ describe('Sessions (Single)', function() {
}
});

it.only('should return server sessions to the pool on `endSession`', {
metadata: { requires: { topology: 'single' } },
test: function(done) {
let sentIsMaster = false;
test.server.setMessageHandler(request => {
if (sentIsMaster) {
request.reply({ ok: 1 });
return;
}

sentIsMaster = true;
request.reply(
assign({}, mock.DEFAULT_ISMASTER, {
maxWireVersion: 6
})
);
});

const client = new Server(test.server.address());
const sessionPool = new ServerSessionPool(client);
const session = new ClientSession(client, sessionPool);
const clientServerSession = session.serverSession;

client.on('error', done);
client.once('connect', () => {
client.command('admin.$cmd', { ping: 1 }, { session: session }, err => {
expect(err).to.not.exist;

session.endSession(err => {
expect(err).to.not.exist;
expect(session.hasEnded).to.be.true;
expect(sessionPool.sessions).to.have.length(1);
expect(sessionPool.sessions[0]).to.eql(clientServerSession);

done();
});
});
});

client.connect();
}
});

it('should default `logicalSessionTimeoutMinutes` to `null`', {
metadata: { requires: { topology: 'single' } },
test: function() {
Expand Down

0 comments on commit 31dbaf4

Please sign in to comment.