test_runner: introduce NODE_TEST_WORKER_ID for improved concurrent te…#56091
test_runner: introduce NODE_TEST_WORKER_ID for improved concurrent te…#560910hmX wants to merge 1 commit intonodejs:mainfrom
Conversation
|
Review requested:
|
pmarchini
left a comment
There was a problem hiding this comment.
Hey @cu8code, thanks for the PR.
I'm requesting changes since we're still missing tests.
Regarding the implementation, LGTM.
Another important thing: to make this new feature available to users, we also need to update the documentation with this behavior 🚀
|
Regarding the tests, I think you'll want to use |
|
I'm concerned this has too much cross-over with If there is a good reason behind making If there is not a particular rationale for the non-sequentiality of The problem described in the cited issue is well handled via If we're merely trying to facilitate migration, I think we should first consider that point and whether there is a way to ease that migration without redundancy. Without seeing the OP's code, I can only imagine what it looks like, but I suspect perhaps less than 20% would need to be adjusted. Likely the biggest hindrance is knowledge, which can be provided (ex a Learn article). |
|
@JakobJingleheimer Thanks for helping with the test creation! |
cjihrig
left a comment
There was a problem hiding this comment.
Left a few comments. Have you verified that this works with watch mode (particularly watch mode + process isolation)?
doc/api/test.md
Outdated
|
|
||
| ## Environment Variables | ||
|
|
||
| ### `NODE_TEST_WORKER_ID` |
There was a problem hiding this comment.
This should be documented in doc/api/cli.md instead.
| @@ -0,0 +1,7 @@ | |||
| // This file tests the `NODE_TEST_WORKER_ID` feature. | |||
| // The test logic is implemented in `test/parallel/test-runner-cli.js`. | |||
There was a problem hiding this comment.
Can you remove this line. If things get moved around, this will almost certainly be forgotten about.
|
|
||
| test('test1', t => { | ||
| console.log('NODE_TEST_WORKER_ID', process.env.NODE_TEST_WORKER_ID) | ||
| }); No newline at end of file |
There was a problem hiding this comment.
Please add a newline at the end of the file.
| @@ -0,0 +1,7 @@ | |||
| // This file tests the `NODE_TEST_WORKER_ID` feature. | |||
There was a problem hiding this comment.
Please rename the directory from NODE_TEST_WORKER_ID to worker-id.
There was a problem hiding this comment.
@cu8code this still needs to be addressed 😁
| @@ -0,0 +1,7 @@ | |||
| // This file tests the `NODE_TEST_WORKER_ID` feature. | |||
There was a problem hiding this comment.
The same comments apply to this file.
| @@ -0,0 +1,7 @@ | |||
| // This file tests the `NODE_TEST_WORKER_ID` feature. | |||
There was a problem hiding this comment.
The same comments apply to this file.
| @@ -0,0 +1,7 @@ | |||
| // This file tests the `NODE_TEST_WORKER_ID` feature. | |||
There was a problem hiding this comment.
I think three files is enough for this. I would drop this file.
test/parallel/test-runner-cli.js
Outdated
| assert.strictEqual(child.signal, null); | ||
| } | ||
|
|
||
| { |
There was a problem hiding this comment.
Please move these new tests to a new file - test/parallel/test-runner-worker-id.js.
yes I have tested, its working fine! both for |
c722258 to
391e805
Compare
|
@cjihrig I’ve made the updates you requested. Please take a moment to review them! |
| const fixtures = require('../common/fixtures'); | ||
| const testFixtures = fixtures.path('test-runner'); | ||
|
|
||
| { |
There was a problem hiding this comment.
Could you please implement the tests using node:test ?
Here is an example : https://github.com/nodejs/node/blob/main/test/parallel/test-runner-run.mjs
Hey @cu8code, regarding this: could you please also add some tests? |
…st execution Added a new environment variable, `NODE_TEST_WORKER_ID`, which ranges from 1 to N when `--experimental-test-isolation=process` is enabled and defaults to 1 when `--experimental-test-isolation=none` is used.
|
🤟 @cjihrig @pmarchini review |
| }); | ||
|
|
||
|
|
||
| test('testing with isolation enabled in watch mode', async () => { |
There was a problem hiding this comment.
The watch mode tests added here have at least two problems:
- They don't actually test watch mode beyond passing the
--watchflag. To properly test watch mode, you have to trigger the restart functionality. - These tests will almost certainly be flaky in the CI. Waiting for a second, killing the child process, and expecting it to have run successfully probably works locally, but the CI machines can be very slow. I don't think we want to have a timeout at all.
I think these need to be refactored so that:
- The test runs once.
- Once the expected output is seen, a source file is modified (we don't want to modify the fixtures files directly either) to trigger a restart.
- The test runs again. We need the output to be the same both times.
| const fixtures = require('../common/fixtures'); | ||
| const testFixtures = fixtures.path('test-runner'); | ||
|
|
||
| test('testing with isolation enabled', () => { |
There was a problem hiding this comment.
nit: I suggest being more expressive about what we are testing.
For example, describe('test runner worker-id'), followed by it('should set NODE_TEST_WORKER_ID in isolation x'), etc.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #56091 +/- ##
==========================================
- Coverage 88.00% 87.99% -0.01%
==========================================
Files 656 656
Lines 189000 189084 +84
Branches 35995 35991 -4
==========================================
+ Hits 166320 166379 +59
- Misses 15840 15869 +29
+ Partials 6840 6836 -4
|
|
Hey @cu8code, commit linter is failing, could you please fix it? |
| output will be sent to stdout in the TAP format. If any other value is provided, | ||
| Node.js makes no guarantees about the reporter format used or its stability. | ||
|
|
||
| ### `NODE_TEST_WORKER_ID` |
There was a problem hiding this comment.
I'm not sure this is the correct place for this. this is a list of env vars node accepts, not env vars it exposes
| let workerId = 1; | ||
| return SafePromiseAllSettledReturnVoid(testFiles, (path) => { | ||
| const subtest = runTestFile(path, filesWatcher, opts); | ||
| const subtest = runTestFile(path, filesWatcher, opts, workerId); |
There was a problem hiding this comment.
if I have 8 cpus and 16 tests, I would expect each worker to be reused twice, but this implementation will not reuse worker ids, I think that is misleading
|
@cu8code are you still working on this? If not, we should close this PR so that other folks can pick up the work. |
ref: #55842
Added a new environment variable,
NODE_TEST_WORKER_ID, which ranges from 1 to N when--experimental-test-isolation=processis enabled and defaults to 1 when--experimental-test-isolation=noneis used.Before merging, I want to add some tests but haven't come up with a good approach yet. Here's what I aim to test:
--experimental-test-isolation=processis enabled, verify thatNODE_TEST_WORKER_IDranges from 1 to N.--experimental-test-isolation=noneis used, ensure thatNODE_TEST_WORKER_IDis set to 1.Any suggestions on how to create such tests would be greatly appreciated!