Skip to content

Commit 4481c1b

Browse files
cjihrigmarco-ippolito
authored andcommitted
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 <benjamingr@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 4a3ecbf commit 4481c1b

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

lib/internal/test_runner/test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,11 +880,20 @@ class Test extends AsyncResource {
880880
this.reporter.complete(this.nesting, this.loc, this.testNumber, this.name, report.details, report.directive);
881881

882882
this.parent.activeSubtests--;
883+
// The call to processPendingSubtests() below can change the number of
884+
// pending subtests. When detecting if we are done running tests, we want
885+
// to check if there are no pending subtests both before and after
886+
// calling processPendingSubtests(). Otherwise, it is possible to call
887+
// root.run() multiple times (which is harmless but can trigger an
888+
// EventEmitter leak warning).
889+
const pendingSiblingCount = this.parent.pendingSubtests.length;
890+
883891
this.parent.addReadySubtest(this);
884892
this.parent.processReadySubtestRange(false);
885893
this.parent.processPendingSubtests();
886894

887895
if (this.parent === this.root &&
896+
pendingSiblingCount === 0 &&
888897
this.root.activeSubtests === 0 &&
889898
this.root.pendingSubtests.length === 0 &&
890899
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)