Skip to content

Commit ab880fd

Browse files
update leak checker to have better description
1 parent 1d02768 commit ab880fd

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

test/tools/runner/hooks/leak_checker.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ const leakCheckerAfterEach = async function () {
143143
const TRACE_SOCKETS = process.env.TRACE_SOCKETS === 'true' ? true : false;
144144
const kSocketId = Symbol('socketId');
145145
const originalCreateConnection = net.createConnection;
146-
let socketCounter = 0n;
147146

148-
const socketLeakCheckBeforeAll = function socketLeakCheckBeforeAll() {
147+
const socketLeakCheckBeforeEach = function socketLeakCheckBeforeAll() {
148+
const description = this.currentTest.title;
149+
let id = 0;
149150
// @ts-expect-error: Typescript says this is readonly, but it is not at runtime
150151
net.createConnection = options => {
151152
const socket = originalCreateConnection(options);
152-
socket[kSocketId] = socketCounter.toString().padStart(5, '0');
153-
socketCounter++;
153+
socket[kSocketId] = `"${description}" (${id++})`;
154154
return socket;
155155
};
156156
};
@@ -175,7 +175,6 @@ const socketLeakCheckAfterEach: Mocha.AsyncFunc = async function socketLeakCheck
175175
}
176176
};
177177

178-
const beforeAll = TRACE_SOCKETS ? [socketLeakCheckBeforeAll] : [];
179-
const beforeEach = [leakCheckerBeforeEach];
178+
const beforeEach = [leakCheckerBeforeEach, ...(TRACE_SOCKETS ? [socketLeakCheckBeforeEach] : [])];
180179
const afterEach = [leakCheckerAfterEach, ...(TRACE_SOCKETS ? [socketLeakCheckAfterEach] : [])];
181-
export const mochaHooks = { beforeAll, beforeEach, afterEach };
180+
export const mochaHooks = { beforeEach, afterEach };

0 commit comments

Comments
 (0)