Skip to content

Commit a50e7b2

Browse files
review
1 parent 804c464 commit a50e7b2

File tree

1 file changed

+87
-46
lines changed

1 file changed

+87
-46
lines changed

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

Lines changed: 87 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { expect } from 'chai';
44
import { type TestConfiguration } from '../../tools/runner/config';
55
import { runScriptAndGetProcessInfo } from './resource_tracking_script_builder';
66

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

1010
let config: TestConfiguration;
@@ -15,7 +15,7 @@ describe.skip('MongoClient.close() Integration', () => {
1515

1616
describe('Node.js resource: TLS File read', () => {
1717
describe('when client is connecting and reads an infinite TLS file', () => {
18-
it('the file read is interrupted by client.close()', async function () {
18+
it.skip('the file read is interrupted by client.close()', async function () {
1919
await runScriptAndGetProcessInfo(
2020
'tls-file-read',
2121
config,
@@ -51,7 +51,7 @@ describe.skip('MongoClient.close() Integration', () => {
5151
});
5252

5353
describe('when MongoClientAuthProviders is instantiated and token file read hangs', () => {
54-
it('the file read is interrupted by client.close()', async () => {
54+
it.skip('the file read is interrupted by client.close()', async () => {
5555
await runScriptAndGetProcessInfo(
5656
'token-file-read',
5757
config,
@@ -77,7 +77,7 @@ describe.skip('MongoClient.close() Integration', () => {
7777
describe('Topology', () => {
7878
describe('Node.js resource: Server Selection Timer', () => {
7979
describe('after a Topology is created through client.connect()', () => {
80-
it('server selection timers are cleaned up by client.close()', async () => {
80+
it.skip('server selection timers are cleaned up by client.close()', async () => {
8181
const run = async function ({
8282
MongoClient,
8383
uri,
@@ -133,7 +133,7 @@ describe.skip('MongoClient.close() Integration', () => {
133133
describe('MonitorInterval', () => {
134134
describe('Node.js resource: Timer', () => {
135135
describe('after a new monitor is made', () => {
136-
it(
136+
it.skip(
137137
'monitor interval timer is cleaned up by client.close()',
138138
metadata,
139139
async function () {
@@ -164,7 +164,7 @@ describe.skip('MongoClient.close() Integration', () => {
164164
});
165165

166166
describe('after a heartbeat fails', () => {
167-
it(
167+
it.skip(
168168
'the new monitor interval timer is cleaned up by client.close()',
169169
metadata,
170170
async () => {
@@ -199,7 +199,7 @@ describe.skip('MongoClient.close() Integration', () => {
199199

200200
describe('Connection Monitoring', () => {
201201
describe('Node.js resource: Socket', () => {
202-
it('no sockets remain after client.close()', metadata, async function () {
202+
it.skip('no sockets remain after client.close()', metadata, async function () {
203203
const run = async function ({ MongoClient, uri, expect }) {
204204
const client = new MongoClient(uri);
205205
await client.connect();
@@ -234,7 +234,7 @@ describe.skip('MongoClient.close() Integration', () => {
234234
describe('RTT Pinger', () => {
235235
describe('Node.js resource: Timer', () => {
236236
describe('after entering monitor streaming mode ', () => {
237-
it(
237+
it.skip(
238238
'the rtt pinger timer is cleaned up by client.close()',
239239
metadata,
240240
async function () {
@@ -274,7 +274,7 @@ describe.skip('MongoClient.close() Integration', () => {
274274
describe('Connection', () => {
275275
describe('Node.js resource: Socket', () => {
276276
describe('when rtt monitoring is turned on', () => {
277-
it('no sockets remain after client.close()', metadata, async () => {
277+
it.skip('no sockets remain after client.close()', metadata, async () => {
278278
const run = async ({ MongoClient, uri, expect, sleep }) => {
279279
const heartbeatFrequencyMS = 100;
280280
const client = new MongoClient(uri, {
@@ -331,7 +331,7 @@ describe.skip('MongoClient.close() Integration', () => {
331331
describe('ConnectionPool', () => {
332332
describe('Node.js resource: minPoolSize timer', () => {
333333
describe('after new connection pool is created', () => {
334-
it('the minPoolSize timer is cleaned up by client.close()', async function () {
334+
it.skip('the minPoolSize timer is cleaned up by client.close()', async function () {
335335
const run = async function ({ MongoClient, uri, expect, getTimerCount }) {
336336
const client = new MongoClient(uri, { minPoolSize: 1 });
337337
let minPoolSizeTimerCreated = false;
@@ -361,7 +361,7 @@ describe.skip('MongoClient.close() Integration', () => {
361361

362362
describe('Node.js resource: checkOut Timer', () => {
363363
describe('after new connection pool is created', () => {
364-
it('the wait queue timer is cleaned up by client.close()', async function () {
364+
it.skip('the wait queue timer is cleaned up by client.close()', async function () {
365365
const run = async function ({
366366
MongoClient,
367367
uri,
@@ -438,7 +438,7 @@ describe.skip('MongoClient.close() Integration', () => {
438438
describe('Connection', () => {
439439
describe('Node.js resource: Socket', () => {
440440
describe('after a minPoolSize has been set on the ConnectionPool', () => {
441-
it('no sockets remain after client.close()', async function () {
441+
it.skip('no sockets remain after client.close()', async function () {
442442
const run = async function ({ MongoClient, uri, expect }) {
443443
const connectionMonitoringReport = () =>
444444
process.report.getReport().libuv.filter(r => r.type === 'tcp');
@@ -480,13 +480,13 @@ describe.skip('MongoClient.close() Integration', () => {
480480
};
481481

482482
describe('after SRVPoller is created', () => {
483-
it('timers are cleaned up by client.close()', metadata, async () => {
483+
it.skip('timers are cleaned up by client.close()', metadata, async () => {
484484
const run = async function ({ MongoClient, uri, expect, getTimerCount }) {
485485
const client = new MongoClient(uri);
486486
await client.connect();
487487
const description = client.topology.s.description;
488488
// simulate transition to sharded
489-
client.topology.emit('topologyDescriptionChanged', description, {
489+
client.topology.emit.skip('topologyDescriptionChanged', description, {
490490
...description,
491491
type: 'Sharded'
492492
});
@@ -504,83 +504,119 @@ describe.skip('MongoClient.close() Integration', () => {
504504
describe('ClientSession (Implicit)', () => {
505505
let idleSessionsBeforeClose;
506506
let idleSessionsAfterClose;
507+
let client;
508+
let utilClient;
509+
let session;
510+
511+
const metadata: MongoDBMetadataUI = { requires: { topology: ['replicaset', 'sharded'] } };
507512

508513
beforeEach(async function () {
509-
const client = this.configuration.newClient();
514+
client = this.configuration.newClient();
515+
utilClient = this.configuration.newClient();
510516
await client.connect();
511-
const session = client.startSession({ explicit: false });
517+
session = client.startSession({ explicit: false });
512518
session.startTransaction();
513519
await client.db('db').collection('collection').insertOne({ x: 1 }, { session });
514520

515-
const opBefore = await client.db().admin().command({ currentOp: 1 });
521+
const opBefore = await utilClient.db().admin().command({ currentOp: 1 });
516522
idleSessionsBeforeClose = opBefore.inprog.filter(s => s.type === 'idleSession');
517523

518524
await client.close();
519-
await client.connect();
520525

521-
const opAfter = await client.db().admin().command({ currentOp: 1 });
526+
const opAfter = await utilClient.db().admin().command({ currentOp: 1 });
522527
idleSessionsAfterClose = opAfter.inprog.filter(s => s.type === 'idleSession');
523528

524-
await client.close();
529+
await utilClient.close();
530+
});
531+
532+
afterEach(async function () {
533+
await utilClient?.close();
534+
await session?.endSession();
535+
await client?.close();
525536
});
526537

527538
describe('Server resource: LSID/ServerSession', () => {
528539
describe('after a clientSession is implicitly created and used', () => {
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-
});
540+
it(
541+
'the server-side ServerSession is cleaned up by client.close()',
542+
metadata,
543+
async function () {
544+
expect(idleSessionsBeforeClose).to.not.be.empty;
545+
expect(idleSessionsAfterClose).to.be.empty;
546+
}
547+
);
533548
});
534549
});
535550

536551
describe('Server resource: Transactions', () => {
537552
describe('after a clientSession is implicitly created and used', () => {
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-
});
553+
it(
554+
'the server-side transaction is cleaned up by client.close()',
555+
metadata,
556+
async function () {
557+
expect(idleSessionsBeforeClose[0].transaction.txnNumber).to.not.null;
558+
expect(idleSessionsAfterClose).to.be.empty;
559+
}
560+
);
542561
});
543562
});
544563
});
545564

546565
describe('ClientSession (Explicit)', () => {
547566
let idleSessionsBeforeClose;
548567
let idleSessionsAfterClose;
568+
let client;
569+
let utilClient;
570+
let session;
571+
572+
const metadata: MongoDBMetadataUI = { requires: { topology: ['replicaset', 'sharded'] } };
549573

550574
beforeEach(async function () {
551-
const client = this.configuration.newClient();
575+
client = this.configuration.newClient();
576+
utilClient = this.configuration.newClient();
552577
await client.connect();
553-
const session = client.startSession();
578+
session = client.startSession();
554579
session.startTransaction();
555580
await client.db('db').collection('collection').insertOne({ x: 1 }, { session });
556581

557-
const opBefore = await client.db().admin().command({ currentOp: 1 });
582+
const opBefore = await utilClient.db().admin().command({ currentOp: 1 });
558583
idleSessionsBeforeClose = opBefore.inprog.filter(s => s.type === 'idleSession');
559584

560585
await client.close();
561-
await client.connect();
562586

563-
const opAfter = await client.db().admin().command({ currentOp: 1 });
587+
const opAfter = await utilClient.db().admin().command({ currentOp: 1 });
564588
idleSessionsAfterClose = opAfter.inprog.filter(s => s.type === 'idleSession');
589+
});
565590

566-
await client.close();
591+
afterEach(async function () {
592+
await utilClient?.close();
593+
await session?.endSession();
594+
await client?.close();
567595
});
568596

569597
describe('Server resource: LSID/ServerSession', () => {
570598
describe('after a clientSession is created and used', () => {
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-
});
599+
it(
600+
'the server-side ServerSession is cleaned up by client.close()',
601+
metadata,
602+
async function () {
603+
expect(idleSessionsBeforeClose).to.not.be.empty;
604+
expect(idleSessionsAfterClose).to.be.empty;
605+
}
606+
);
575607
});
576608
});
577609

578610
describe('Server resource: Transactions', () => {
579611
describe('after a clientSession is created and used', () => {
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-
});
612+
it(
613+
'the server-side transaction is cleaned up by client.close()',
614+
metadata,
615+
async function () {
616+
expect(idleSessionsBeforeClose[0].transaction.txnNumber).to.not.null;
617+
expect(idleSessionsAfterClose).to.be.empty;
618+
}
619+
);
584620
});
585621
});
586622
});
@@ -596,7 +632,7 @@ describe.skip('MongoClient.close() Integration', () => {
596632
describe('KMS Request', () => {
597633
describe('Node.js resource: TLS file read', () => {
598634
describe('when KMSRequest reads an infinite TLS file', () => {
599-
it('the file read is interrupted by client.close()', async () => {
635+
it.skip('the file read is interrupted by client.close()', async () => {
600636
await runScriptAndGetProcessInfo(
601637
'tls-file-read-auto-encryption',
602638
config,
@@ -693,20 +729,24 @@ describe.skip('MongoClient.close() Integration', () => {
693729
let client;
694730
let coll;
695731
let cursor;
732+
let utilClient;
696733

697734
beforeEach(async function () {
698735
client = this.configuration.newClient();
736+
utilClient = this.configuration.newClient();
737+
await client.connect();
699738
coll = client.db('db').collection('coll');
700739
});
701740

702741
afterEach(async function () {
742+
await utilClient?.close();
703743
await client?.close();
704744
await cursor?.close();
705745
});
706746

707-
it('all active server-side cursors are closed by client.close()', async function () {
747+
it.skip('all active server-side cursors are closed by client.close()', async function () {
708748
const getCursors = async () => {
709-
const res = await client
749+
const res = await utilClient
710750
.db()
711751
.admin()
712752
.command({
@@ -720,13 +760,14 @@ describe.skip('MongoClient.close() Integration', () => {
720760
};
721761

722762
await coll.insertMany([{ a: 1 }, { b: 2 }, { c: 3 }]);
763+
await coll.insertMany([{ d: 4 }, { e: 5 }, { f: 3 }]);
723764
cursor = await coll.find();
765+
await cursor.next();
724766

725767
// assert creation
726768
expect(await getCursors()).to.not.be.empty;
727769

728770
await client.close();
729-
await client.connect();
730771

731772
// assert clean-up
732773
expect(await getCursors()).to.be.empty;

0 commit comments

Comments
 (0)