Skip to content

Commit 5f37b14

Browse files
4/5 tests complted
1 parent a79ed0a commit 5f37b14

File tree

1 file changed

+89
-6
lines changed

1 file changed

+89
-6
lines changed

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

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

5-
describe.skip('MongoClient.close() Integration', () => {
7+
describe.only('MongoClient.close() Integration', () => {
68
// note: these tests are set-up in accordance of the resource ownership tree
79

810
let config: TestConfiguration;
@@ -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,32 @@ 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 cursor;
695+
696+
afterEach(async function () {
697+
await client?.close();
698+
await cursor?.close();
699+
});
700+
701+
it.only('all active server-side cursors are closed by client.close()', async function () {
702+
client = this.configuration.newClient();
703+
const coll = client.db('db').collection('coll');
704+
await coll.insertMany([{ a: 1 }, { b: 1 }]);
705+
cursor = await coll.find();
706+
await cursor.next();
707+
708+
const before = await client.db().admin().command({ aggregate: 1, cursor: {}, pipeline: [ { $currentOp: { idleCursors: true, } }] });
709+
const beforeOp = await before.cursor.toArray();
710+
//const cursorsBefore = opBefore.inprog.filter(r => r.type === 'idleCursor');
711+
//expect(cursorsBefore).to.not.be.empty;
712+
713+
await client.close();
714+
await client.connect();
715+
716+
const opAfter = await client.db().admin().command({ aggregate: 1, cursor: {}, pipeline: [ { $currentOp: { idleCursors: true } }] });
717+
//expect(cursorsAfter).to.be.empty;
718+
});
636719
});
637720
});
638721
});

0 commit comments

Comments
 (0)