diff --git a/test/integration/node-specific/resource_clean_up.test.ts b/test/integration/node-specific/resource_clean_up.test.ts index 4fd1bd53b1e..edcb7e48fc2 100644 --- a/test/integration/node-specific/resource_clean_up.test.ts +++ b/test/integration/node-specific/resource_clean_up.test.ts @@ -17,7 +17,7 @@ const MB_PERMITTED_OFFSET = 5; describe('Driver Resources', () => { let startingMemoryUsed; let endingMemoryUsed; - let heap; + let clientsInMemory; beforeEach(function () { if (globalThis.AbortController == null) { @@ -34,12 +34,6 @@ describe('Driver Resources', () => { context('on MongoClient.close()', () => { before('create leak reproduction script', async function () { - if (process.version.includes('v24')) { - if (this.test) { - this.test.skipReason = 'TODO(NODE-6945): Fix v24 heap snapshot parsing'; - } - this.test?.skip(); - } if (globalThis.AbortController == null || typeof this.configuration.serverApi === 'string') { return; } @@ -58,7 +52,7 @@ describe('Driver Resources', () => { startingMemoryUsed = res.startingMemoryUsed; endingMemoryUsed = res.endingMemoryUsed; - heap = res.heap; + clientsInMemory = res.clientsInMemory; }); describe('ending memory usage', () => { @@ -77,11 +71,10 @@ describe('Driver Resources', () => { describe('ending heap snapshot', () => { it('has 0 MongoClients in memory', async () => { - const clients = heap.nodes.filter(n => n.name === 'MongoClient' && n.type === 'object'); // lengthOf crashes chai b/c it tries to print out a gigantic diff expect( - clients.length, - `expected no MongoClients in the heapsnapshot, found ${clients.length}` + clientsInMemory, + `expected no MongoClients in the heapsnapshot, found ${clientsInMemory}` ).to.equal(0); }); }); diff --git a/test/integration/node-specific/resource_tracking_script_builder.ts b/test/integration/node-specific/resource_tracking_script_builder.ts index e166dfb6b4c..f4160d8e539 100644 --- a/test/integration/node-specific/resource_tracking_script_builder.ts +++ b/test/integration/node-specific/resource_tracking_script_builder.ts @@ -7,7 +7,6 @@ import { inspect } from 'node:util'; import { AssertionError, expect } from 'chai'; import type * as timers from 'timers'; -import { parseSnapshot } from 'v8-heapsnapshot'; import type * as mongodb from '../../mongodb'; import { type MongoClient } from '../../mongodb'; @@ -106,7 +105,6 @@ export async function runScriptAndReturnHeapInfo( }; log('starting'); const scriptName = `${name}.cjs`; - const heapsnapshotFile = `${name}.heapsnapshot.json`; const scriptContent = await testScriptFactory( name, @@ -145,8 +143,16 @@ export async function runScriptAndReturnHeapInfo( log('fetching messages 3: ', ending); - const startingMemoryUsed = starting.value[0].startingMemoryUsed; - const endingMemoryUsed = ending.value[0].endingMemoryUsed; + const { + value: [{ startingMemoryUsed }] + } = starting; + const { + value: [{ endingMemoryUsed }] + } = ending; + + const { + value: [{ clientsInMemory }] + } = await messages.next(); // make sure the process ended const [exitCode] = await willClose; @@ -155,21 +161,16 @@ export async function runScriptAndReturnHeapInfo( expect(exitCode, 'process should have exited with zero').to.equal(0); - const heap = await readFile(heapsnapshotFile, { encoding: 'utf8' }).then(c => - parseSnapshot(JSON.parse(c)) - ); - log('done.'); // If any of the above throws we won't reach these unlinks that clean up the created files. // This is intentional so that when debugging the file will still be present to check it for errors await unlink(scriptName); - await unlink(heapsnapshotFile); return { startingMemoryUsed, endingMemoryUsed, - heap + clientsInMemory }; } diff --git a/test/tools/fixtures/heap_resource_script.in.js b/test/tools/fixtures/heap_resource_script.in.js index afe7407fcb0..690214168d9 100644 --- a/test/tools/fixtures/heap_resource_script.in.js +++ b/test/tools/fixtures/heap_resource_script.in.js @@ -4,7 +4,6 @@ const driverPath = DRIVER_SOURCE_PATH; const func = FUNCTION_STRING; -const name = SCRIPT_NAME_STRING; const uri = URI_STRING; const iterations = ITERATIONS_STRING; const { inspect } = require('util'); @@ -15,7 +14,6 @@ const v8 = require('node:v8'); const util = require('node:util'); const timers = require('node:timers'); -const now = performance.now.bind(performance); const sleep = util.promisify(timers.setTimeout); const run = func; @@ -59,11 +57,11 @@ async function main() { process.send({ endingMemoryUsed }); log('second message sent.'); - const start = now(); - v8.writeHeapSnapshot(`${name}.heapsnapshot.json`); - const end = now(); + const clientsInMemory = v8.queryObjects(MongoClient); - log(`heap snapshot written in ${end - start}ms. script exiting`); + process.send({ clientsInMemory }); + + log('clients instances in memory sent.'); } main()