Skip to content

test_runner: don't exceed call stack when filtering #52488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const {
} = primordials;
const { getCallerLocation } = internalBinding('util');
const { addAbortListener } = require('internal/events/abort_listener');
const { queueMicrotask } = require('internal/process/task_queues');
const { AsyncResource } = require('async_hooks');
const { AbortController } = require('internal/abort_controller');
const {
Expand Down Expand Up @@ -673,7 +674,7 @@ class Test extends AsyncResource {
this.pass();
this.subtests = [];
this.report = noop;
this.postRun();
queueMicrotask(() => this.postRun());
}

async run() {
Expand Down Expand Up @@ -829,29 +830,9 @@ 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) {
// At this point all of the tests have finished running. However, there
// might be ref'ed handles keeping the event loop alive. This gives the
// global after() hook a chance to clean them up. The user may also
// want to force the test runner to exit despite ref'ed handles.
this.root.run();
}
} else if (!this.reported) {
const {
diagnostics,
Expand Down Expand Up @@ -914,6 +895,15 @@ class Test extends AsyncResource {
this.report();
this.parent.waitingOn++;
this.finished = true;

if (this.parent === this.root &&
this.root.waitingOn > this.root.subtests.length) {
// At this point all of the tests have finished running. However, there
// might be ref'ed handles keeping the event loop alive. This gives the
// global after() hook a chance to clean them up. The user may also
// want to force the test runner to exit despite ref'ed handles.
this.root.run();
}
}

duration() {
Expand Down