Skip to content

Commit 52f8dcf

Browse files
authored
test_runner: make end of work check stricter
This commit updates the logic that checks for the end of the test run. Prior to this change, it was possible for root.run() to be called multiple times because of the way pending subtests were tracked. The extra calls to root.run() were harmless, but could trigger an EventEmitter leak warning due to 'abort' listeners being created. PR-URL: #52326 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
1 parent d32a914 commit 52f8dcf

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/internal/test_runner/test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,11 +829,20 @@ class Test extends AsyncResource {
829829
this.parent.activeSubtests--;
830830
}
831831

832+
// The call to processPendingSubtests() below can change the number of
833+
// pending subtests. When detecting if we are done running tests, we want
834+
// to check if there are no pending subtests both before and after
835+
// calling processPendingSubtests(). Otherwise, it is possible to call
836+
// root.run() multiple times (which is harmless but can trigger an
837+
// EventEmitter leak warning).
838+
const pendingSiblingCount = this.parent.pendingSubtests.length;
839+
832840
this.parent.addReadySubtest(this);
833841
this.parent.processReadySubtestRange(false);
834842
this.parent.processPendingSubtests();
835843

836844
if (this.parent === this.root &&
845+
pendingSiblingCount === 0 &&
837846
this.root.activeSubtests === 0 &&
838847
this.root.pendingSubtests.length === 0 &&
839848
this.root.readySubtests.size === 0) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Flags: --test-only
2+
'use strict';
3+
const common = require('../common');
4+
const { test } = require('node:test');
5+
const { defaultMaxListeners } = require('node:events');
6+
7+
process.on('warning', common.mustNotCall());
8+
9+
for (let i = 0; i < defaultMaxListeners + 1; ++i) {
10+
test(`test ${i + 1}`);
11+
}

0 commit comments

Comments
 (0)