Commit 0d97ec4
test_runner: expose worker ID for concurrent test execution
This adds support for identifying which worker is running a test file
when tests execute concurrently, similar to JEST_WORKER_ID in Jest,
VITEST_POOL_ID in Vitest, and MOCHA_WORKER_ID in Mocha.
When running with --test-isolation=process (default), each test file
runs in a separate child process and receives a unique worker ID from
1 to N. When running with --test-isolation=none, all tests run in the
same process and the worker ID is always 1.
This enables users to allocate separate resources (databases, ports,
etc.) for each test worker to avoid conflicts during concurrent
execution.
Changes:
- Add WorkerIdPool class to manage worker ID allocation and reuse
- Set NODE_TEST_WORKER_ID environment variable for child processes
- Add context.workerId getter to TestContext class
- Add tests for worker ID functionality
- Add documentation for context.workerId
Fixes: #55842
PR-URL: #61394
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>1 parent 243e6b2 commit 0d97ec4Copy full SHA for 0d97ec4
7 files changed
+308Lines changed: 308 additions & 0 deletions
File tree
Expand file treeCollapse file tree
Open diff view settings
Filter options
- doc/api
- lib/internal/test_runner
- test
- fixtures/test-runner/worker-id
- parallel
Expand file treeCollapse file tree
Open diff view settings
Collapse file
+33Lines changed: 33 additions & 0 deletions
- Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
3804 | 3804 | |
3805 | 3805 | |
3806 | 3806 | |
| 3807 | + |
| 3808 | + |
| 3809 | + |
| 3810 | + |
| 3811 | + |
| 3812 | + |
| 3813 | + |
| 3814 | + |
| 3815 | + |
| 3816 | + |
| 3817 | + |
| 3818 | + |
| 3819 | + |
| 3820 | + |
| 3821 | + |
| 3822 | + |
| 3823 | + |
| 3824 | + |
| 3825 | + |
| 3826 | + |
| 3827 | + |
| 3828 | + |
| 3829 | + |
| 3830 | + |
| 3831 | + |
| 3832 | + |
| 3833 | + |
| 3834 | + |
| 3835 | + |
| 3836 | + |
| 3837 | + |
| 3838 | + |
| 3839 | + |
3807 | 3840 | |
3808 | 3841 | |
3809 | 3842 | |
|
Collapse file
lib/internal/test_runner/runner.js
Copy file name to clipboardExpand all lines: lib/internal/test_runner/runner.js+51Lines changed: 51 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
15 | 15 | |
16 | 16 | |
17 | 17 | |
| 18 | + |
18 | 19 | |
19 | 20 | |
20 | 21 | |
| ||
23 | 24 | |
24 | 25 | |
25 | 26 | |
| 27 | + |
26 | 28 | |
27 | 29 | |
28 | 30 | |
| ||
33 | 35 | |
34 | 36 | |
35 | 37 | |
| 38 | + |
36 | 39 | |
37 | 40 | |
38 | 41 | |
| ||
117 | 120 | |
118 | 121 | |
119 | 122 | |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | + |
120 | 138 | |
121 | 139 | |
122 | 140 | |
| ||
404 | 422 | |
405 | 423 | |
406 | 424 | |
| 425 | + |
| 426 | + |
| 427 | + |
| 428 | + |
| 429 | + |
| 430 | + |
| 431 | + |
| 432 | + |
| 433 | + |
407 | 434 | |
408 | 435 | |
409 | 436 | |
| ||
769 | 796 | |
770 | 797 | |
771 | 798 | |
| 799 | + |
| 800 | + |
| 801 | + |
| 802 | + |
| 803 | + |
| 804 | + |
| 805 | + |
| 806 | + |
| 807 | + |
| 808 | + |
| 809 | + |
| 810 | + |
| 811 | + |
| 812 | + |
| 813 | + |
| 814 | + |
| 815 | + |
| 816 | + |
| 817 | + |
772 | 818 | |
773 | 819 | |
774 | 820 | |
| ||
786 | 832 | |
787 | 833 | |
788 | 834 | |
| 835 | + |
789 | 836 | |
790 | 837 | |
791 | 838 | |
| ||
812 | 859 | |
813 | 860 | |
814 | 861 | |
| 862 | + |
| 863 | + |
| 864 | + |
| 865 | + |
815 | 866 | |
816 | 867 | |
817 | 868 | |
|
Collapse file
lib/internal/test_runner/test.js
Copy file name to clipboardExpand all lines: lib/internal/test_runner/test.js+5Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
285 | 285 | |
286 | 286 | |
287 | 287 | |
| 288 | + |
| 289 | + |
| 290 | + |
| 291 | + |
| 292 | + |
288 | 293 | |
289 | 294 | |
290 | 295 | |
|
Collapse file
test/fixtures/test-runner/worker-id/test-1.mjs
Copy file name to clipboard+26Lines changed: 26 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
Collapse file
test/fixtures/test-runner/worker-id/test-2.mjs
Copy file name to clipboard+26Lines changed: 26 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
Collapse file
test/fixtures/test-runner/worker-id/test-3.mjs
Copy file name to clipboard+26Lines changed: 26 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
Collapse file
test/parallel/test-runner-worker-id.js
Copy file name to clipboard+141Lines changed: 141 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | + |
0 commit comments