Skip to content

Commit 8f7eb85

Browse files
parent 70d476a
author Aditi Khare <[email protected]> 1734376794 -0500 committer Aditi Khare <[email protected]> 1737656635 -0500 parent 70d476a author Aditi Khare <[email protected]> 1734376794 -0500 committer Aditi Khare <[email protected]> 1737656626 -0500 parent 70d476a author Aditi Khare <[email protected]> 1734376794 -0500 committer Aditi Khare <[email protected]> 1737656617 -0500 parent 70d476a author Aditi Khare <[email protected]> 1734376794 -0500 committer Aditi Khare <[email protected]> 1737656617 -0500 parent 70d476a author Aditi Khare <[email protected]> 1734376794 -0500 committer Aditi Khare <[email protected]> 1737656613 -0500 parent 70d476a author Aditi Khare <[email protected]> 1734376794 -0500 committer Aditi Khare <[email protected]> 1737656583 -0500 parent 70d476a author Aditi Khare <[email protected]> 1734376794 -0500 committer Aditi Khare <[email protected]> 1737656581 -0500 skeleton skeleton updates refactor for table fix remove misc file clean up Delete logs.txt requested changes: additional expectation remove extra file ready for review server selection test fix
1 parent 70d476a commit 8f7eb85

File tree

3 files changed

+141
-7
lines changed

3 files changed

+141
-7
lines changed

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

Lines changed: 104 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+
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('MongoClient.close() Integration', () => {
68
// note: these tests are set-up in accordance of the resource ownership tree
79

810
let config: TestConfiguration;
@@ -452,29 +454,85 @@ describe.skip('MongoClient.close() Integration', () => {
452454
});
453455

454456
describe('ClientSession (Implicit)', () => {
457+
let idleSessionsBeforeClose;
458+
let idleSessionsAfterClose;
459+
460+
beforeEach(async function () {
461+
const client = this.configuration.newClient();
462+
await client.connect();
463+
const session = client.startSession({ explicit: false });
464+
session.startTransaction();
465+
await client.db('db').collection('collection').insertOne({ x: 1 }, { session });
466+
467+
const opBefore = await client.db().admin().command({ currentOp: 1 });
468+
idleSessionsBeforeClose = opBefore.inprog.filter(s => s.type === 'idleSession');
469+
470+
await client.close();
471+
await client.connect();
472+
473+
const opAfter = await client.db().admin().command({ currentOp: 1 });
474+
idleSessionsAfterClose = opAfter.inprog.filter(s => s.type === 'idleSession');
475+
476+
await client.close();
477+
});
478+
455479
describe('Server resource: LSID/ServerSession', () => {
456480
describe('after a clientSession is implicitly created and used', () => {
457-
it.skip('the server-side ServerSession is cleaned up by client.close()', async function () {});
481+
it('the server-side ServerSession is cleaned up by client.close()', async function () {
482+
expect(idleSessionsBeforeClose).to.not.be.empty;
483+
expect(idleSessionsAfterClose).to.be.empty;
484+
});
458485
});
459486
});
460487

461488
describe('Server resource: Transactions', () => {
462489
describe('after a clientSession is implicitly created and used', () => {
463-
it.skip('the server-side transaction is cleaned up by client.close()', async function () {});
490+
it('the server-side transaction is cleaned up by client.close()', async function () {
491+
expect(idleSessionsBeforeClose[0].transaction.txnNumber).to.not.null;
492+
expect(idleSessionsAfterClose).to.be.empty;
493+
});
464494
});
465495
});
466496
});
467497

468498
describe('ClientSession (Explicit)', () => {
499+
let idleSessionsBeforeClose;
500+
let idleSessionsAfterClose;
501+
502+
beforeEach(async function () {
503+
const client = this.configuration.newClient();
504+
await client.connect();
505+
const session = client.startSession();
506+
session.startTransaction();
507+
await client.db('db').collection('collection').insertOne({ x: 1 }, { session });
508+
509+
const opBefore = await client.db().admin().command({ currentOp: 1 });
510+
idleSessionsBeforeClose = opBefore.inprog.filter(s => s.type === 'idleSession');
511+
512+
await client.close();
513+
await client.connect();
514+
515+
const opAfter = await client.db().admin().command({ currentOp: 1 });
516+
idleSessionsAfterClose = opAfter.inprog.filter(s => s.type === 'idleSession');
517+
518+
await client.close();
519+
});
520+
469521
describe('Server resource: LSID/ServerSession', () => {
470522
describe('after a clientSession is created and used', () => {
471-
it.skip('the server-side ServerSession is cleaned up by client.close()', async function () {});
523+
it('the server-side ServerSession is cleaned up by client.close()', async function () {
524+
expect(idleSessionsBeforeClose).to.not.be.empty;
525+
expect(idleSessionsAfterClose).to.be.empty;
526+
});
472527
});
473528
});
474529

475530
describe('Server resource: Transactions', () => {
476531
describe('after a clientSession is created and used', () => {
477-
it.skip('the server-side transaction is cleaned up by client.close()', async function () {});
532+
it('the server-side transaction is cleaned up by client.close()', async function () {
533+
expect(idleSessionsBeforeClose[0].transaction.txnNumber).to.not.null;
534+
expect(idleSessionsAfterClose).to.be.empty;
535+
});
478536
});
479537
});
480538
});
@@ -584,7 +642,47 @@ describe.skip('MongoClient.close() Integration', () => {
584642

585643
describe('Server resource: Cursor', () => {
586644
describe('after cursors are created', () => {
587-
it.skip('all active server-side cursors are closed by client.close()', async function () {});
645+
let client;
646+
let coll;
647+
let cursor;
648+
649+
beforeEach(async function () {
650+
client = this.configuration.newClient();
651+
coll = client.db('db').collection('coll');
652+
});
653+
654+
afterEach(async function () {
655+
await client?.close();
656+
await cursor?.close();
657+
});
658+
659+
it('all active server-side cursors are closed by client.close()', async function () {
660+
const getCursors = async () => {
661+
const res = await client
662+
.db()
663+
.admin()
664+
.command({
665+
aggregate: 1,
666+
cursor: { batchSize: 10 },
667+
pipeline: [{ $currentOp: { idleCursors: true } }]
668+
});
669+
return res.cursor.firstBatch.filter(
670+
r => r.type === 'idleCursor' || (r.type === 'op' && r.desc === 'getMore')
671+
);
672+
};
673+
674+
await coll.insertMany([{ a: 1 }, { b: 2 }, { c: 3 }]);
675+
cursor = await coll.find();
676+
677+
// assert creation
678+
expect(await getCursors()).to.not.be.empty;
679+
680+
await client.close();
681+
await client.connect();
682+
683+
// assert clean-up
684+
expect(await getCursors()).to.be.empty;
685+
});
588686
});
589687
});
590688
});

test/integration/node-specific/resource_tracking_script_builder.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ export async function testScriptFactory(
5858
resourceScript = resourceScript.replace('FUNCTION_STRING', `(${func.toString()})`);
5959
resourceScript = resourceScript.replace('SCRIPT_NAME_STRING', JSON.stringify(name));
6060
resourceScript = resourceScript.replace('URI_STRING', JSON.stringify(uri));
61-
resourceScript = resourceScript.replace('ITERATIONS_STRING', `${iterations}`);
61+
if (resourceScriptPath === HEAP_RESOURCE_SCRIPT_PATH) {
62+
resourceScript = resourceScript.replace('ITERATIONS_STRING', `${iterations}`);
63+
}
6264

6365
return resourceScript;
6466
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
/* eslint-disable no-undef */
4+
5+
const driverPath = DRIVER_SOURCE_PATH;
6+
const func = FUNCTION_STRING;
7+
const name = NAME_STRING;
8+
const uri = URI_STRING;
9+
const iterations = ITERATIONS_STRING;
10+
11+
const { MongoClient } = require(driverPath);
12+
const process = require('node:process');
13+
const v8 = require('node:v8');
14+
const util = require('node:util');
15+
const timers = require('node:timers');
16+
17+
const run = func;
18+
19+
async function main() {
20+
process.on('beforeExit', (code) => {
21+
process.send({beforeExit: true});
22+
});
23+
await run({ MongoClient, uri, iteration });
24+
const report = process.report.getReport();
25+
process.send({ report });
26+
}
27+
28+
main()
29+
.then(() => {
30+
process.exit(0);
31+
})
32+
.catch(() => {
33+
process.exit(1);
34+
});

0 commit comments

Comments
 (0)