Skip to content

Commit ec996e6

Browse files
chore(NODE-6945): remove dependency on v8-heapsnapshot (#4763)
1 parent 7d879fd commit ec996e6

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
lines changed

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const MB_PERMITTED_OFFSET = 5;
1717
describe('Driver Resources', () => {
1818
let startingMemoryUsed;
1919
let endingMemoryUsed;
20-
let heap;
20+
let clientsInMemory;
2121

2222
beforeEach(function () {
2323
if (globalThis.AbortController == null) {
@@ -34,12 +34,6 @@ describe('Driver Resources', () => {
3434

3535
context('on MongoClient.close()', () => {
3636
before('create leak reproduction script', async function () {
37-
if (process.version.includes('v24')) {
38-
if (this.test) {
39-
this.test.skipReason = 'TODO(NODE-6945): Fix v24 heap snapshot parsing';
40-
}
41-
this.test?.skip();
42-
}
4337
if (globalThis.AbortController == null || typeof this.configuration.serverApi === 'string') {
4438
return;
4539
}
@@ -58,7 +52,7 @@ describe('Driver Resources', () => {
5852

5953
startingMemoryUsed = res.startingMemoryUsed;
6054
endingMemoryUsed = res.endingMemoryUsed;
61-
heap = res.heap;
55+
clientsInMemory = res.clientsInMemory;
6256
});
6357

6458
describe('ending memory usage', () => {
@@ -77,11 +71,10 @@ describe('Driver Resources', () => {
7771

7872
describe('ending heap snapshot', () => {
7973
it('has 0 MongoClients in memory', async () => {
80-
const clients = heap.nodes.filter(n => n.name === 'MongoClient' && n.type === 'object');
8174
// lengthOf crashes chai b/c it tries to print out a gigantic diff
8275
expect(
83-
clients.length,
84-
`expected no MongoClients in the heapsnapshot, found ${clients.length}`
76+
clientsInMemory,
77+
`expected no MongoClients in the heapsnapshot, found ${clientsInMemory}`
8578
).to.equal(0);
8679
});
8780
});

test/integration/node-specific/resource_tracking_script_builder.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { inspect } from 'node:util';
77

88
import { AssertionError, expect } from 'chai';
99
import type * as timers from 'timers';
10-
import { parseSnapshot } from 'v8-heapsnapshot';
1110

1211
import type * as mongodb from '../../../src';
1312
import { type TestConfiguration } from '../../tools/runner/config';
@@ -105,7 +104,6 @@ export async function runScriptAndReturnHeapInfo(
105104
};
106105
log('starting');
107106
const scriptName = `${name}.cjs`;
108-
const heapsnapshotFile = `${name}.heapsnapshot.json`;
109107

110108
const scriptContent = await testScriptFactory(
111109
name,
@@ -144,8 +142,16 @@ export async function runScriptAndReturnHeapInfo(
144142

145143
log('fetching messages 3: ', ending);
146144

147-
const startingMemoryUsed = starting.value[0].startingMemoryUsed;
148-
const endingMemoryUsed = ending.value[0].endingMemoryUsed;
145+
const {
146+
value: [{ startingMemoryUsed }]
147+
} = starting;
148+
const {
149+
value: [{ endingMemoryUsed }]
150+
} = ending;
151+
152+
const {
153+
value: [{ clientsInMemory }]
154+
} = await messages.next();
149155

150156
// make sure the process ended
151157
const [exitCode] = await willClose;
@@ -154,21 +160,16 @@ export async function runScriptAndReturnHeapInfo(
154160

155161
expect(exitCode, 'process should have exited with zero').to.equal(0);
156162

157-
const heap = await readFile(heapsnapshotFile, { encoding: 'utf8' }).then(c =>
158-
parseSnapshot(JSON.parse(c))
159-
);
160-
161163
log('done.');
162164

163165
// If any of the above throws we won't reach these unlinks that clean up the created files.
164166
// This is intentional so that when debugging the file will still be present to check it for errors
165167
await unlink(scriptName);
166-
await unlink(heapsnapshotFile);
167168

168169
return {
169170
startingMemoryUsed,
170171
endingMemoryUsed,
171-
heap
172+
clientsInMemory
172173
};
173174
}
174175

test/tools/fixtures/heap_resource_script.in.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
const driverPath = DRIVER_SOURCE_PATH;
66
const func = FUNCTION_STRING;
7-
const name = SCRIPT_NAME_STRING;
87
const uri = URI_STRING;
98
const iterations = ITERATIONS_STRING;
109
const { inspect } = require('util');
@@ -15,7 +14,6 @@ const v8 = require('node:v8');
1514
const util = require('node:util');
1615
const timers = require('node:timers');
1716

18-
const now = performance.now.bind(performance);
1917
const sleep = util.promisify(timers.setTimeout);
2018

2119
const run = func;
@@ -59,11 +57,11 @@ async function main() {
5957
process.send({ endingMemoryUsed });
6058
log('second message sent.');
6159

62-
const start = now();
63-
v8.writeHeapSnapshot(`${name}.heapsnapshot.json`);
64-
const end = now();
60+
const clientsInMemory = v8.queryObjects(MongoClient);
6561

66-
log(`heap snapshot written in ${end - start}ms. script exiting`);
62+
process.send({ clientsInMemory });
63+
64+
log('clients instances in memory sent.');
6765
}
6866

6967
main()

0 commit comments

Comments
 (0)