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: fix undocumented assumptions about the timing of tsfn calls #995

Closed
wants to merge 2 commits into from

Conversation

legendecas
Copy link
Member

@legendecas legendecas commented May 10, 2021

Fixes #994

Copy link

@indutny-signal indutny-signal left a comment

Choose a reason for hiding this comment

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

Node.js didn't need the test change because we increased the array size to be over 1000 elements:

nodejs/node@7abc7e4#diff-7025abd678052220b281a720c8e5f2b995120dd65ccd8f8557b0158a1a43025bR10

I think this change is good as it is, but just wanted to suggest some alternatives.

@@ -25,11 +25,9 @@ async function test(binding) {
binding.threadsafe_function[threadStarter](function testCallback(value) {
array.push(value);
if (array.length === quitAfter) {
setImmediate(() => {

Choose a reason for hiding this comment

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

Or you could use process.nextTick if you'd like to keep it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't know the exact intention of deferring the close of TSFN here. However, tests all passed with or without deferring.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, original TSFN implementation was re-scheduling each call on the next physical UV loop tick (which was terribly slow), so the setImmediate() got a chance to run right after the first invocation.

Copy link
Member

Choose a reason for hiding this comment

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

@KevinEady @gabrielschulhof any input on using/not using process.nextTick(). I'll plan to land this tomorrow unless I hear from you so that we can get back to green CI.

@legendecas
Copy link
Member Author

So the related patch doesn't seem to be released on the latest v16.x. We don't have GitHub Actions setup for nightly Node.js builds... (as nightly build probably fails for arbitrary reasons)�¯_(ツ)_/¯, what can we do here? This test fixup doesn't break all existing releasing lines. And I've tested against the latest main branch of Node.js.

@legendecas legendecas marked this pull request as ready for review May 10, 2021 17:34
@mhdawson
Copy link
Member

Ran on a few of the versions in our CI, its possibly there are other places with the same issue:

https://ci.nodejs.org/view/x%20-%20Abi%20stable%20module%20API/job/node-test-node-addon-api-new/4087/nodes=rhel7-s390x/console

Running test 'threadsafe_function/threadsafe_function_sum'
Running test 'threadsafe_function/threadsafe_function_unref'
Running test 'typed_threadsafe_function/typed_threadsafe_function'
FATAL ERROR: TypedDataSourceThread Queue was never closing
Tests aborted with SIGSEGV

@mhdawson
Copy link
Member

@legendecas , Well actually just looks like the similar typed version of the test likely needs the same fix

@mhdawson
Copy link
Member

mhdawson commented May 11, 2021

@mhdawson
Copy link
Member

@mhdawson
Copy link
Member

CI runs were good. I'll land to unbreak the CI.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

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

LGTM

mhdawson pushed a commit that referenced this pull request May 11, 2021
PR-URL: #995
Reviewed-By: Michael Dawson <midawson@redhat.com>
@mhdawson
Copy link
Member

mhdawson commented May 11, 2021

@mhdawson
Copy link
Member

CI run was all green. @legendecas thanks for helping get this resolved so quickly. @indutny-signal thanks for helping out as well.

@mhdawson mhdawson closed this May 11, 2021
@legendecas legendecas deleted the test-tsfn branch May 11, 2021 17:20
deepakrkris pushed a commit to deepakrkris/node-addon-api that referenced this pull request Sep 23, 2021
PR-URL: nodejs#995
Reviewed-By: Michael Dawson <midawson@redhat.com>
deepakrkris pushed a commit to deepakrkris/node-addon-api that referenced this pull request Oct 15, 2021
PR-URL: nodejs#995
Reviewed-By: Michael Dawson <midawson@redhat.com>
kevindavies8 added a commit to kevindavies8/node-addon-api-Develop that referenced this pull request Aug 24, 2022
PR-URL: nodejs/node-addon-api#995
Reviewed-By: Michael Dawson <midawson@redhat.com>
Marlyfleitas added a commit to Marlyfleitas/node-api-addon-Development that referenced this pull request Aug 26, 2022
PR-URL: nodejs/node-addon-api#995
Reviewed-By: Michael Dawson <midawson@redhat.com>
wroy7860 added a commit to wroy7860/addon-api-benchmark-node that referenced this pull request Sep 19, 2022
PR-URL: nodejs/node-addon-api#995
Reviewed-By: Michael Dawson <midawson@redhat.com>
austinli64 added a commit to austinli64/node-addon-api that referenced this pull request May 9, 2023
PR-URL: nodejs/node-addon-api#995
Reviewed-By: Michael Dawson <midawson@redhat.com>
johnfrench3 pushed a commit to johnfrench3/node-addon-api-git that referenced this pull request Aug 11, 2023
PR-URL: nodejs/node-addon-api#995
Reviewed-By: Michael Dawson <midawson@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

threadsafe_function test - CI failing on Master since May 4th
4 participants