-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
test_runner: add shards support #48639
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
Changes from 16 commits
a93fa41
3bc36b8
bf9d2e5
3663fb2
09c8734
ed19709
5e39d75
5c6ab88
d293da5
51f7697
0625b75
2e0040b
602f767
4ce4d76
b7009d7
76cfcb6
5a846d2
d4f9168
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,13 @@ const { isUsingInspector } = require('internal/util/inspector'); | |
| const { run } = require('internal/test_runner/runner'); | ||
| const { setupTestReporters } = require('internal/test_runner/utils'); | ||
| const { exitCodes: { kGenericUserError } } = internalBinding('errors'); | ||
| const { | ||
| codes: { | ||
| ERR_INVALID_ARG_VALUE, | ||
| }, | ||
| } = require('internal/errors'); | ||
| const { NumberParseInt, RegExpPrototypeExec, StringPrototypeSplit } = | ||
| primordials; | ||
rluvaton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| prepareMainThreadExecution(false); | ||
| markBootstrapComplete(); | ||
|
|
@@ -22,7 +29,32 @@ if (isUsingInspector()) { | |
| inspectPort = process.debugPort; | ||
| } | ||
|
|
||
| run({ concurrency, inspectPort, watch: getOptionValue('--watch'), setup: setupTestReporters }) | ||
| let shard; | ||
| const shardOption = getOptionValue('--test-shard'); | ||
| if (shardOption) { | ||
| if (!RegExpPrototypeExec(/^\d+\/\d+$/, shardOption)) { | ||
| process.exitCode = kGenericUserError; | ||
|
|
||
| throw new ERR_INVALID_ARG_VALUE( | ||
| '--test-shard', | ||
| shardOption, | ||
| 'must be in the form of <index>/<total>', | ||
| ); | ||
| } | ||
|
|
||
| const { 0: indexStr, 1: totalStr } = StringPrototypeSplit(shardOption, '/'); | ||
|
|
||
| const index = NumberParseInt(indexStr, 10); | ||
| const total = NumberParseInt(totalStr, 10); | ||
|
Comment on lines
+50
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fwiw if it's NumberParseInt, the , 10 isn't required - only on the global one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on the global one it's not required as far as I know There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's required in the conceptual sense, because |
||
|
|
||
| shard = { | ||
| __proto__: null, | ||
| index, | ||
rluvaton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| total, | ||
| }; | ||
| } | ||
|
|
||
| run({ concurrency, inspectPort, watch: getOptionValue('--watch'), setup: setupTestReporters, shard }) | ||
| .once('test:fail', () => { | ||
| process.exitCode = kGenericUserError; | ||
| }); | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -39,10 +39,18 @@ const console = require('internal/console/global'); | |||||
| const { | ||||||
| codes: { | ||||||
| ERR_INVALID_ARG_TYPE, | ||||||
| ERR_INVALID_ARG_VALUE, | ||||||
| ERR_TEST_FAILURE, | ||||||
| ERR_OUT_OF_RANGE, | ||||||
| }, | ||||||
| } = require('internal/errors'); | ||||||
| const { validateArray, validateBoolean, validateFunction } = require('internal/validators'); | ||||||
| const { | ||||||
| validateArray, | ||||||
| validateBoolean, | ||||||
| validateFunction, | ||||||
| validateObject, | ||||||
| validateInteger, | ||||||
| } = require('internal/validators'); | ||||||
| const { getInspectPort, isUsingInspector, isInspectorMessage } = require('internal/util/inspector'); | ||||||
| const { isRegExp } = require('internal/util/types'); | ||||||
| const { kEmptyObject } = require('internal/util'); | ||||||
|
|
@@ -416,7 +424,7 @@ function run(options) { | |||||
| if (options === null || typeof options !== 'object') { | ||||||
| options = kEmptyObject; | ||||||
| } | ||||||
| let { testNamePatterns } = options; | ||||||
| let { testNamePatterns, shard } = options; | ||||||
| const { concurrency, timeout, signal, files, inspectPort, watch, setup } = options; | ||||||
|
|
||||||
| if (files != null) { | ||||||
|
|
@@ -425,6 +433,22 @@ function run(options) { | |||||
| if (watch != null) { | ||||||
| validateBoolean(watch, 'options.watch'); | ||||||
| } | ||||||
| if (shard != null) { | ||||||
| validateObject(shard, 'options.shard'); | ||||||
| // Avoid re-evaluating the shard object in case it's a getter | ||||||
| shard = { index: shard.index, total: shard.total }; | ||||||
|
||||||
| shard = { index: shard.index, total: shard.total }; | |
| shard = { __proto__: null, index: shard.index, total: shard.total }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason there is no eslint rule for that or there is some limitation prevents from implementing it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think anybody's taken the time to make one. There will be a few places where objects shouldn't have a null prototype - mostly when they're returned to userland - but those could have override comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#48646 need to answer some questions before changing all files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed based on my previous comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see that comment answer 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why would you use sharding if you need to watch all the files? watch is for active development
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You had a bug in a certain shard in CI and you want to iteratively fix it? Is there a reason not to allow it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you add a file it will change the sharding, we can add it I just think it won't be really useful
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| 'use strict'; | ||
| const test = require('node:test'); | ||
|
|
||
| test('a.cjs this should pass'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| 'use strict'; | ||
| const test = require('node:test'); | ||
|
|
||
| test('b.cjs this should pass'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| 'use strict'; | ||
| const test = require('node:test'); | ||
|
|
||
| test('c.cjs this should pass'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| 'use strict'; | ||
| const test = require('node:test'); | ||
|
|
||
| test('d.cjs this should pass'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| 'use strict'; | ||
| const test = require('node:test'); | ||
|
|
||
| test('e.cjs this should pass'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| 'use strict'; | ||
| const test = require('node:test'); | ||
|
|
||
| test('f.cjs this should pass'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| 'use strict'; | ||
| const test = require('node:test'); | ||
|
|
||
| test('g.cjs this should pass'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| 'use strict'; | ||
| const test = require('node:test'); | ||
|
|
||
| test('h.cjs this should pass'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| 'use strict'; | ||
| const test = require('node:test'); | ||
|
|
||
| test('i.cjs this should pass'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| 'use strict'; | ||
| const test = require('node:test'); | ||
|
|
||
| test('j.cjs this should pass'); |
Uh oh!
There was an error while loading. Please reload this page.