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: Add test coverage for "TSFN::Ref()" #1196

Merged
merged 4 commits into from
Sep 2, 2022

Conversation

JckXia
Copy link
Member

@JckXia JckXia commented Aug 13, 2022

We currently do not have a test for testing the Ref(Env env) function attached to the TSFN class. But I am not too sure if this is the best way to test this functionality. From what I understand this method is a wrapper around napi_ref_threadsafe_function which prevents the event loop from exiting until the tsfn gets destroyed by a call to Release().

My thought behind this approach is that we first reference this TSFN function, before the callback in setTimeout Unref's the TSFN which causes the event loop to exit. Though it appears that this tsfn should already be referenced prior to calling Ref, and napi_ref_threadsafe_function is idempotent so it has no effect. Is there a better approach to test this method? Also in what scenarios would napi_ref_threadsafe_function or TSFN::Ref() be used? Thanks!

@@ -32,6 +32,7 @@ static Value TestUnref(const CallbackInfo& info) {
static_cast<FinalizerDataType*>(nullptr));

tsfn->BlockingCall();
tsfn->Ref(info.Env());
Copy link
Member

Choose a reason for hiding this comment

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

Is this change still needed?

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 mhdawson merged commit 225ca35 into nodejs:main Sep 2, 2022
@JckXia JckXia deleted the add-ref-typed-threadsafe-func branch December 14, 2022 00:46
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.

2 participants