1- import { fork } from 'child_process' ;
2- import {
3- MongoClient ,
4- } from '../../mongodb' ;
5- import { on , once } from 'node:events' ;
6- import { readFile , unlink , writeFile } from 'node:fs/promises' ;
71import { TestConfiguration } from '../../tools/runner/config' ;
8- import { expect } from 'chai' ;
9- import { StringOrPlaceholder } from '../../tools/unified-spec-runner/schema' ;
10-
11- /*
12- export async function testScriptFactory(
13- name: string,
14- uri: string,
15- iterations: number,
16- func: Function
17- ) {
18- let resourceScript = await readFile(RESOURCE_SCRIPT_PATH, { encoding: 'utf8' });
19-
20- resourceScript = resourceScript.replace('DRIVER_SOURCE_PATH', DRIVER_SRC_PATH);
21- resourceScript = resourceScript.replace('FUNCTION_STRING', `(${func.toString()})`);
22- resourceScript = resourceScript.replace('NAME_STRING', JSON.stringify(name));
23- resourceScript = resourceScript.replace('URI_STRING', JSON.stringify(uri));
24- resourceScript = resourceScript.replace('ITERATIONS_STRING', `${iterations}`);
25-
26- return resourceScript;
27- }
28-
29- export async function runScriptAndReturnResourceInfo(
30- name: string,
31- config: TestConfiguration,
32- func: Function
33- ) {
34-
35- const pathName = `scripts/${name}.cjs`;
36- const scriptContent = await testScriptFactory(name, config.url(), func);
37- await writeFile(name, func.toString(), { encoding: 'utf8' });
38-
39- const processDiedController = new AbortController();
40- const script = fork(name, { execArgv: ['--expose-gc'] });
41-
42- // Interrupt our awaiting of messages if the process crashed
43- script.once('close', exitCode => {
44- if (exitCode !== 0) {
45- processDiedController.abort(new Error(`process exited with: ${exitCode}`));
46- }
47- });
48-
49- const willClose = once(script, 'close');
50-
51- // make sure the process ended
52- const [exitCode] = await willClose;
53- expect(exitCode, 'process should have exited with zero').to.equal(0);
54-
55- return process.report.getReport().libuv;
56- }
57- */
2+ import { runScriptAndReturnResourceInfo } from './resource_tracking_script_builder' ;
583
594describe . only ( 'client.close() Integration' , ( ) => {
60- let client : MongoClient ;
615 let config : TestConfiguration ;
626 beforeEach ( function ( ) {
637 config = this . configuration ;
64- client = this . configuration . newClient ( ) ;
658 } ) ;
669
67- describe ( 'File System' , ( ) => {
68- describe ( 'when client is connected and reading a TLS long file' , ( ) => {
69- it ( 'the file read is interrupted by client.close' , ( ) => {
70-
71- } ) ;
72- } ) ;
73- describe ( 'when client is created and reading a long docker file' , ( ) => {
10+ describe ( 'MongoClient' , ( ) => {
11+ describe ( 'when client is being instantiated and reads a long docker file' , ( ) => {
7412 // our docker env detection uses fs.access which will not be aborted until after it runs
7513 // fs.access does not support abort signals
7614 it ( 'the file read is not interrupted by client.close' , ( ) => {
7715 } ) ;
7816 } ) ;
79-
80- describe ( 'when FLE is enabled and the client has made a KMS request that is reading a long TLS file' , ( ) => {
17+ describe ( 'when client is connecting and reads a TLS long file' , ( ) => {
8118 it ( 'the file read is interrupted by client.close' , ( ) => {
82-
8319 } ) ;
8420 } ) ;
8521 } ) ;
8622
87- describe ( 'Connection Creation and Socket Lifetime' , ( ) => {
88- describe ( 'after client is connected' , ( ) => {
89- it ( 'no sockets remain after client.close' , ( ) => {
90-
91- } ) ;
92- it ( 'no server-side connection threads remain after client.close' , ( ) => {
93-
23+ describe ( 'MongoClientAuthProviders' , ( ) => {
24+ describe ( 'when MongoClientAuthProviders is instantiated' , ( ) => {
25+ it ( 'the token cache is cleaned up by client.close' , ( ) => {
9426 } ) ;
9527 } ) ;
28+ } ) ;
9629
97- describe ( 'after a connection is checked out' , ( ) => {
98- it ( 'no sockets remain after client.close' , ( ) => {
30+ describe ( 'Topology' , ( ) => {
31+ describe ( 'after a Topology is explicitly created' , ( ) => {
32+ it ( 'timers are cleaned up by client.close()' , ( ) => {
9933
10034 } ) ;
101- it ( 'no server-side connection threads remain after client.close' , ( ) => {
35+ } ) ;
36+ describe ( 'after a Topology is created through client.connect()' , ( ) => {
37+ it ( 'timers are cleaned up by client.close()' , ( ) => {
10238
10339 } ) ;
10440 } ) ;
41+ } ) ;
10542
106- describe ( 'after a minPoolSize has been set on the ConnectionPool' , ( ) => {
107- it ( 'no sockets remain after client.close' , ( ) => {
108-
109- } ) ;
110- it ( 'no server-side connection threads remain after client.close' , ( ) => {
43+ describe ( 'SRVPoller' , ( ) => {
44+ describe ( 'after SRVPoller is explicitly created' , ( ) => {
45+ it ( 'timers are cleaned up by client.close()' , ( ) => {
11146
11247 } ) ;
11348 } ) ;
11449
115- describe ( 'when connection monitoring is turned on' , ( ) => {
116- it ( 'no sockets remain after client.close' , ( ) => {
117-
118- } ) ;
119- it ( 'no server-side connection threads remain after client.close' , ( ) => {
50+ // SRVPoller is implicitly created after an SRV string's topology transitions to sharded
51+ describe ( 'after SRVPoller is implicitly created' , ( ) => {
52+ it ( 'timers are cleaned up by client.close()' , ( ) => {
12053
12154 } ) ;
12255 } ) ;
56+ } ) ;
12357
124- describe ( 'when rtt monitoring is turned on' , ( ) => {
125- it ( 'no sockets remain after client.close' , ( ) => {
126-
127- } ) ;
128- it ( 'no server-side connection threads remain after client.close' , ( ) => {
58+ describe ( 'ClientSession' , ( ) => {
59+ describe ( 'after a clientSession is created' , ( ) => {
60+ it ( 'the server-side ServerSession and transaction are cleaned up by client.close()' , ( ) => {
12961
13062 } ) ;
13163 } ) ;
64+ } ) ;
13265
66+ describe ( 'StateMachine' , ( ) => {
13367 describe ( 'when FLE is enabled and the client has made a KMS request' , ( ) => {
13468 it ( 'no sockets remain after client.close' , ( ) => {
13569
13670 } ) ;
13771 it ( 'no server-side connection threads remain after client.close' , ( ) => {
13872
13973 } ) ;
140- } ) ;
141- } ) ;
142-
143- describe ( 'Timers' , ( ) => {
144- describe ( 'after SRVPoller is explicitly created' , ( ) => {
145- it ( 'timers are cleaned up by client.close()' , ( ) => {
146-
147- } ) ;
148- } ) ;
149-
150- // SRVPoller is implicitly created after an SRV string's topology transitions to sharded
151- describe ( 'after SRVPoller is implicitly created' , ( ) => {
152- it ( 'timers are cleaned up by client.close()' , ( ) => {
74+ describe ( 'when the TLS file read hangs' , ( ) => {
75+ it ( 'the file read is interrupted by client.close' , ( ) => {
15376
77+ } ) ;
15478 } ) ;
15579 } ) ;
80+ } ) ;
15681
82+ describe ( 'ConnectionPool' , ( ) => {
15783 describe ( 'after new connection pool is created' , ( ) => {
15884 it ( 'minPoolSize timer is cleaned up by client.close()' , ( ) => {
15985
16086 } ) ;
16187 } ) ;
88+ } ) ;
16289
90+ describe ( 'MonitorInterval' , ( ) => {
16391 describe ( 'after a new monitor is made' , ( ) => {
16492 it ( 'monitor interval timer is cleaned up by client.close()' , ( ) => {
16593
@@ -171,25 +99,57 @@ describe.only('client.close() Integration', () => {
17199
172100 } ) ;
173101 } ) ;
102+ } ) ;
174103
104+ describe ( 'RTTPinger' , ( ) => {
175105 describe ( 'after helloReply has a topologyVersion defined fails' , ( ) => {
176106 it ( 'rtt pinger timer is cleaned up by client.close()' , ( ) => {
177107
178108 } ) ;
179109 } ) ;
180110 } ) ;
181111
182- describe ( 'Cursor Clean-up' , ( ) => {
183- describe ( 'after cursors are created' , ( ) => {
184- it ( 'all active server-side cursors are closed by client.close()' , ( ) => {
112+ describe ( 'Connection' , ( ) => {
113+ describe ( 'when connection monitoring is turned on' , ( ) => {
114+ it ( 'no sockets remain after client.close' , ( ) => {
115+
116+ } ) ;
117+ it ( 'no server-side connection threads remain after client.close' , ( ) => {
118+
119+ } ) ;
120+ } ) ;
121+
122+ describe ( 'when rtt monitoring is turned on' , ( ) => {
123+ it ( 'no sockets remain after client.close' , ( ) => {
124+
125+ } ) ;
126+ it ( 'no server-side connection threads remain after client.close' , ( ) => {
127+
128+ } ) ;
129+ } ) ;
130+
131+ describe ( 'after a connection is checked out' , ( ) => {
132+ it ( 'no sockets remain after client.close' , ( ) => {
133+
134+ } ) ;
135+ it ( 'no server-side connection threads remain after client.close' , ( ) => {
136+
137+ } ) ;
138+ } ) ;
139+
140+ describe ( 'after a minPoolSize has been set on the ConnectionPool' , ( ) => {
141+ it ( 'no sockets remain after client.close' , ( ) => {
142+
143+ } ) ;
144+ it ( 'no server-side connection threads remain after client.close' , ( ) => {
185145
186146 } ) ;
187147 } ) ;
188148 } ) ;
189149
190- describe ( 'Sessions ' , ( ) => {
191- describe ( 'after a clientSession is created' , ( ) => {
192- it ( 'the server-side ServerSession is cleaned up by client.close()' , ( ) => {
150+ describe ( 'Cursor ' , ( ) => {
151+ describe ( 'after cursors are created' , ( ) => {
152+ it ( 'all active server-side cursors are closed by client.close()' , ( ) => {
193153
194154 } ) ;
195155 } ) ;
0 commit comments