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: run interfering tests in their own process #1325

Conversation

gabrielschulhof
Copy link
Contributor

@gabrielschulhof gabrielschulhof commented Jun 10, 2023

Tests such as addon and addon_data both use SetInstanceData. Thus, they overwrite each other's instance data. We change them both to run in a child process such that they do not call SetInstanceData on init, but rather they return a JS function on init which, when called, produces the actual binding which needs SetInstanceData.

We also introduce a utility function for launching a test in its own child process for the purpose of running tests that would otherwise interfere with each other.

@mhdawson
Copy link
Member

mhdawson commented Jun 28, 2023

Jenkins ci run on latest (main) - https://ci.nodejs.org/job/node-test-node-addon-api-new/7647/

jenkins ci run on earliest (16.x) - https://ci.nodejs.org/job/node-test-node-addon-api-new/7648/

// 0. A boolean named "verbose" is stored in the instance data. The constructor
// for JS `VerboseIndicator` instances is also stored in the instance data.
// 0. The constructor for JS `VerboseIndicator` instances, which have a private
// member named "verbose" is stored in the instance data.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// member named "verbose" is stored in the instance data.
// member named "verbose" stored in the instance data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I meant to say that the constructor is stored on the instance data, so rather than remove the word "is", I need to put a comma in front of it.

// Capture the exit code and signal.
child
.on('exit', (code, signal) => maybeResolve({ code, signal }))
.on('close', () => maybeResolve());
Copy link
Member

Choose a reason for hiding this comment

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

'close' event is always emitted after the 'exit' event (https://nodejs.org/api/child_process.html#event-close). So this can be simplified as:

Suggested change
.on('close', () => maybeResolve());
.on('close', (code, signal) => resolve({ code, signal }));

Tests such as addon and addon_data both use SetInstanceData. Thus, they
overwrite each other's instance data. We change them both to run in a
child process such that they do not call SetInstanceData on init, but
rather they return a JS function on init which, when called, produces
the actual binding which needs SetInstanceData.

We also introduce a utility function for launching a test in its own
child process for the purpose of running tests that would otherwise
interfere with each other.
@gabrielschulhof gabrielschulhof force-pushed the remove-instance-data-interference branch from 1de5ef4 to 38061b3 Compare July 7, 2023 06:51
@gabrielschulhof
Copy link
Contributor Author

gabrielschulhof commented Jul 8, 2023

gabrielschulhof added a commit that referenced this pull request Jul 8, 2023
Tests such as addon and addon_data both use SetInstanceData. Thus, they
overwrite each other's instance data. We change them both to run in a
child process such that they do not call SetInstanceData on init, but
rather they return a JS function on init which, when called, produces
the actual binding which needs SetInstanceData.

We also introduce a utility function for launching a test in its own
child process for the purpose of running tests that would otherwise
interfere with each other.

Signed-off-by: Gabriel Schulhof <gabrielschulhof@gmail.com>
PR-URL: #1325
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
@gabrielschulhof
Copy link
Contributor Author

Landed in 414be9e.

johnfrench3 pushed a commit to johnfrench3/node-addon-api-git that referenced this pull request Aug 11, 2023
Tests such as addon and addon_data both use SetInstanceData. Thus, they
overwrite each other's instance data. We change them both to run in a
child process such that they do not call SetInstanceData on init, but
rather they return a JS function on init which, when called, produces
the actual binding which needs SetInstanceData.

We also introduce a utility function for launching a test in its own
child process for the purpose of running tests that would otherwise
interfere with each other.

Signed-off-by: Gabriel Schulhof <gabrielschulhof@gmail.com>
PR-URL: nodejs/node-addon-api#1325
Reviewed-By: Chengzhong Wu <legendecas@gmail.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.

None yet

3 participants