Skip to content

Commit 804c464

Browse files
ready for review
1 parent a79ed0a commit 804c464

File tree

1 file changed

+103
-5
lines changed

1 file changed

+103
-5
lines changed

test/integration/node-specific/client_close.test.ts

Lines changed: 103 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-empty-function */
2+
import { expect } from 'chai';
3+
24
import { type TestConfiguration } from '../../tools/runner/config';
35
import { runScriptAndGetProcessInfo } from './resource_tracking_script_builder';
46

@@ -500,29 +502,85 @@ describe.skip('MongoClient.close() Integration', () => {
500502
});
501503

502504
describe('ClientSession (Implicit)', () => {
505+
let idleSessionsBeforeClose;
506+
let idleSessionsAfterClose;
507+
508+
beforeEach(async function () {
509+
const client = this.configuration.newClient();
510+
await client.connect();
511+
const session = client.startSession({ explicit: false });
512+
session.startTransaction();
513+
await client.db('db').collection('collection').insertOne({ x: 1 }, { session });
514+
515+
const opBefore = await client.db().admin().command({ currentOp: 1 });
516+
idleSessionsBeforeClose = opBefore.inprog.filter(s => s.type === 'idleSession');
517+
518+
await client.close();
519+
await client.connect();
520+
521+
const opAfter = await client.db().admin().command({ currentOp: 1 });
522+
idleSessionsAfterClose = opAfter.inprog.filter(s => s.type === 'idleSession');
523+
524+
await client.close();
525+
});
526+
503527
describe('Server resource: LSID/ServerSession', () => {
504528
describe('after a clientSession is implicitly created and used', () => {
505-
it.skip('the server-side ServerSession is cleaned up by client.close()', async function () {});
529+
it('the server-side ServerSession is cleaned up by client.close()', async function () {
530+
expect(idleSessionsBeforeClose).to.not.be.empty;
531+
expect(idleSessionsAfterClose).to.be.empty;
532+
});
506533
});
507534
});
508535

509536
describe('Server resource: Transactions', () => {
510537
describe('after a clientSession is implicitly created and used', () => {
511-
it.skip('the server-side transaction is cleaned up by client.close()', async function () {});
538+
it('the server-side transaction is cleaned up by client.close()', async function () {
539+
expect(idleSessionsBeforeClose[0].transaction.txnNumber).to.not.null;
540+
expect(idleSessionsAfterClose).to.be.empty;
541+
});
512542
});
513543
});
514544
});
515545

516546
describe('ClientSession (Explicit)', () => {
547+
let idleSessionsBeforeClose;
548+
let idleSessionsAfterClose;
549+
550+
beforeEach(async function () {
551+
const client = this.configuration.newClient();
552+
await client.connect();
553+
const session = client.startSession();
554+
session.startTransaction();
555+
await client.db('db').collection('collection').insertOne({ x: 1 }, { session });
556+
557+
const opBefore = await client.db().admin().command({ currentOp: 1 });
558+
idleSessionsBeforeClose = opBefore.inprog.filter(s => s.type === 'idleSession');
559+
560+
await client.close();
561+
await client.connect();
562+
563+
const opAfter = await client.db().admin().command({ currentOp: 1 });
564+
idleSessionsAfterClose = opAfter.inprog.filter(s => s.type === 'idleSession');
565+
566+
await client.close();
567+
});
568+
517569
describe('Server resource: LSID/ServerSession', () => {
518570
describe('after a clientSession is created and used', () => {
519-
it.skip('the server-side ServerSession is cleaned up by client.close()', async function () {});
571+
it('the server-side ServerSession is cleaned up by client.close()', async function () {
572+
expect(idleSessionsBeforeClose).to.not.be.empty;
573+
expect(idleSessionsAfterClose).to.be.empty;
574+
});
520575
});
521576
});
522577

523578
describe('Server resource: Transactions', () => {
524579
describe('after a clientSession is created and used', () => {
525-
it.skip('the server-side transaction is cleaned up by client.close()', async function () {});
580+
it('the server-side transaction is cleaned up by client.close()', async function () {
581+
expect(idleSessionsBeforeClose[0].transaction.txnNumber).to.not.null;
582+
expect(idleSessionsAfterClose).to.be.empty;
583+
});
526584
});
527585
});
528586
});
@@ -632,7 +690,47 @@ describe.skip('MongoClient.close() Integration', () => {
632690

633691
describe('Server resource: Cursor', () => {
634692
describe('after cursors are created', () => {
635-
it.skip('all active server-side cursors are closed by client.close()', async function () {});
693+
let client;
694+
let coll;
695+
let cursor;
696+
697+
beforeEach(async function () {
698+
client = this.configuration.newClient();
699+
coll = client.db('db').collection('coll');
700+
});
701+
702+
afterEach(async function () {
703+
await client?.close();
704+
await cursor?.close();
705+
});
706+
707+
it('all active server-side cursors are closed by client.close()', async function () {
708+
const getCursors = async () => {
709+
const res = await client
710+
.db()
711+
.admin()
712+
.command({
713+
aggregate: 1,
714+
cursor: { batchSize: 10 },
715+
pipeline: [{ $currentOp: { idleCursors: true } }]
716+
});
717+
return res.cursor.firstBatch.filter(
718+
r => r.type === 'idleCursor' || (r.type === 'op' && r.desc === 'getMore')
719+
);
720+
};
721+
722+
await coll.insertMany([{ a: 1 }, { b: 2 }, { c: 3 }]);
723+
cursor = await coll.find();
724+
725+
// assert creation
726+
expect(await getCursors()).to.not.be.empty;
727+
728+
await client.close();
729+
await client.connect();
730+
731+
// assert clean-up
732+
expect(await getCursors()).to.be.empty;
733+
});
636734
});
637735
});
638736
});

0 commit comments

Comments
 (0)