diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 149d4547b4a65d..9c7d95f9420de5 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -829,11 +829,20 @@ class Test extends AsyncResource { this.parent.activeSubtests--; } + // The call to processPendingSubtests() below can change the number of + // pending subtests. When detecting if we are done running tests, we want + // to check if there are no pending subtests both before and after + // calling processPendingSubtests(). Otherwise, it is possible to call + // root.run() multiple times (which is harmless but can trigger an + // EventEmitter leak warning). + const pendingSiblingCount = this.parent.pendingSubtests.length; + this.parent.addReadySubtest(this); this.parent.processReadySubtestRange(false); this.parent.processPendingSubtests(); if (this.parent === this.root && + pendingSiblingCount === 0 && this.root.activeSubtests === 0 && this.root.pendingSubtests.length === 0 && this.root.readySubtests.size === 0) { diff --git a/test/parallel/test-runner-filter-warning.js b/test/parallel/test-runner-filter-warning.js new file mode 100644 index 00000000000000..0f98f796d9f1c7 --- /dev/null +++ b/test/parallel/test-runner-filter-warning.js @@ -0,0 +1,11 @@ +// Flags: --test-only +'use strict'; +const common = require('../common'); +const { test } = require('node:test'); +const { defaultMaxListeners } = require('node:events'); + +process.on('warning', common.mustNotCall()); + +for (let i = 0; i < defaultMaxListeners + 1; ++i) { + test(`test ${i + 1}`); +}