Skip to content
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

test_runner: fix concurrent describe queuing #43998

Merged
Merged
Show file tree
Hide file tree
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
17 changes: 7 additions & 10 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,25 +561,22 @@ class Suite extends Test {

try {
const context = { signal: this.signal };
this.buildSuite = this.runInAsyncScope(this.fn, context, [context]);
this.buildSuite = PromisePrototypeThen(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd personally prefer an async iife

PromiseResolve(this.runInAsyncScope(this.fn, context, [context])),
undefined,
(err) => {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
});
} catch (err) {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
}
this.fn = () => {};
this.buildPhaseFinished = true;
}

start() {
return this.run();
}

async run() {
try {
await this.buildSuite;
} catch (err) {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
}
this.parent.activeSubtests++;
await this.buildSuite;
this.startTime = hrtime();

if (this[kShouldAbort]()) {
Expand Down
55 changes: 44 additions & 11 deletions test/message/test_runner_describe_it.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,6 @@ describe('level 0a', { concurrency: 4 }, () => {
return p0a;
});

describe('top level', { concurrency: 2 }, () => {
Copy link
Member Author

@MoLow MoLow Jul 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fact this test worked until this PR is a bug:
in test(...) syntax - if you don't await subtests - the parent finishes without waiting for the child.
in describe - the suite won't be complete unless all its children completed
so this suite will:

  1. block all tests/suites defined after it from starting (this is desired - fixed in this PR)
  2. since there is unref - no async activity is queued so process.on('beforeExit') will cancel this suite and all the suites defined after it

Copy link
Member Author

@MoLow MoLow Jul 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope my explanation of what is going on os fine, it took me a while to understand it myself

it('+long running', async () => {
return new Promise((resolve, reject) => {
setTimeout(resolve, 3000).unref();
});
});

describe('+short running', async () => {
it('++short running', async () => {});
});
});

describe('invalid subtest - pass but subtest fails', () => {
setImmediate(() => {
Expand Down Expand Up @@ -339,3 +328,47 @@ describe('timeouts', () => {
setTimeout(done, 10);
});
});

describe('successful thenable', () => {
it('successful thenable', () => {
let thenCalled = false;
return {
get then() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly personally I think anything related to non-native promises isn't important to even test or support anymore probably :D?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #43998.

if (thenCalled) throw new Error();
thenCalled = true;
return (successHandler) => successHandler();
},
};
});

it('rejected thenable', () => {
let thenCalled = false;
return {
get then() {
if (thenCalled) throw new Error();
thenCalled = true;
return (_, errorHandler) => errorHandler(new Error('custom error'));
},
};
});

let thenCalled = false;
return {
get then() {
if (thenCalled) throw new Error();
thenCalled = true;
return (successHandler) => successHandler();
},
};
});

describe('rejected thenable', () => {
let thenCalled = false;
return {
get then() {
if (thenCalled) throw new Error();
thenCalled = true;
return (_, errorHandler) => errorHandler(new Error('custom error'));
},
};
});
Loading