Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test_runner: make end of work check stricter
Browse files Browse the repository at this point in the history
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]>
cjihrig authored and atlowChemi committed May 23, 2024

Verified

This commit was signed with the committer’s verified signature.
atlowChemi Chemi Atlow
1 parent 07c45ba commit e056a7c
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
@@ -778,11 +778,20 @@ class Test extends AsyncResource {
this.reporter.complete(this.nesting, this.loc, this.testNumber, this.name, report.details, report.directive);

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) {
11 changes: 11 additions & 0 deletions test/parallel/test-runner-filter-warning.js
Original file line number Diff line number Diff line change
@@ -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}`);
}

0 comments on commit e056a7c

Please sign in to comment.