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

Commit 31dbaf4

Browse files
committed
test(sessions): add test for ClientSession.endSession
NODE-1088
1 parent 19e1b0f commit 31dbaf4

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/tests/unit/single/sessions_tests.js

+43
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,49 @@ describe('Sessions (Single)', function() {
217217
}
218218
});
219219

220+
it.only('should return server sessions to the pool on `endSession`', {
221+
metadata: { requires: { topology: 'single' } },
222+
test: function(done) {
223+
let sentIsMaster = false;
224+
test.server.setMessageHandler(request => {
225+
if (sentIsMaster) {
226+
request.reply({ ok: 1 });
227+
return;
228+
}
229+
230+
sentIsMaster = true;
231+
request.reply(
232+
assign({}, mock.DEFAULT_ISMASTER, {
233+
maxWireVersion: 6
234+
})
235+
);
236+
});
237+
238+
const client = new Server(test.server.address());
239+
const sessionPool = new ServerSessionPool(client);
240+
const session = new ClientSession(client, sessionPool);
241+
const clientServerSession = session.serverSession;
242+
243+
client.on('error', done);
244+
client.once('connect', () => {
245+
client.command('admin.$cmd', { ping: 1 }, { session: session }, err => {
246+
expect(err).to.not.exist;
247+
248+
session.endSession(err => {
249+
expect(err).to.not.exist;
250+
expect(session.hasEnded).to.be.true;
251+
expect(sessionPool.sessions).to.have.length(1);
252+
expect(sessionPool.sessions[0]).to.eql(clientServerSession);
253+
254+
done();
255+
});
256+
});
257+
});
258+
259+
client.connect();
260+
}
261+
});
262+
220263
it('should default `logicalSessionTimeoutMinutes` to `null`', {
221264
metadata: { requires: { topology: 'single' } },
222265
test: function() {

0 commit comments

Comments
 (0)