-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
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 2 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 |
---|---|---|
|
@@ -13,7 +13,8 @@ const { | |
ERR_INVALID_ARG_VALUE, | ||
}, | ||
} = require('internal/errors'); | ||
const { NumberParseInt } = primordials; | ||
const { NumberParseInt, RegExpPrototypeExec, StringPrototypeSplit } = | ||
primordials; | ||
|
||
prepareMainThreadExecution(false); | ||
markBootstrapComplete(); | ||
|
@@ -31,7 +32,7 @@ if (isUsingInspector()) { | |
let shard; | ||
const shardOption = getOptionValue('--test-shard'); | ||
if (shardOption) { | ||
if (!/^[1-9]([0-9]+)?\/[1-9]([0-9]+)?$/.test(shardOption)) { | ||
if (!RegExpPrototypeExec(/^\d+\/\d+$/, shardOption)) { | ||
process.exitCode = kGenericUserError; | ||
|
||
throw new ERR_INVALID_ARG_VALUE( | ||
|
@@ -41,12 +42,13 @@ if (shardOption) { | |
); | ||
} | ||
|
||
const { 0: indexStr, 1: totalStr } = shardOption.split('/'); | ||
const { 0: indexStr, 1: totalStr } = StringPrototypeSplit(shardOption, '/'); | ||
|
||
const index = NumberParseInt(indexStr); | ||
const total = NumberParseInt(totalStr); | ||
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, | ||
}; | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -49,7 +49,7 @@ const { | |||||
validateBoolean, | ||||||
validateFunction, | ||||||
validateObject, | ||||||
validateNumber, | ||||||
validateInteger, | ||||||
} = require('internal/validators'); | ||||||
const { getInspectPort, isUsingInspector, isInspectorMessage } = require('internal/util/inspector'); | ||||||
const { isRegExp } = require('internal/util/types'); | ||||||
|
@@ -424,8 +424,8 @@ function run(options) { | |||||
if (options === null || typeof options !== 'object') { | ||||||
options = kEmptyObject; | ||||||
} | ||||||
let { testNamePatterns } = options; | ||||||
const { concurrency, timeout, signal, files, inspectPort, watch, setup, shard } = options; | ||||||
let { testNamePatterns, shard } = options; | ||||||
const { concurrency, timeout, signal, files, inspectPort, watch, setup } = options; | ||||||
|
||||||
if (files != null) { | ||||||
validateArray(files, 'options.files'); | ||||||
|
@@ -435,8 +435,11 @@ function run(options) { | |||||
} | ||||||
if (shard != null) { | ||||||
validateObject(shard, 'options.shard'); | ||||||
validateNumber(shard.total, 'options.shard.total', 1); | ||||||
validateNumber(shard.index, 'options.shard.index'); | ||||||
// Avoid re-evaluating the shard object in case it's a getter | ||||||
shard = { index: shard.index, total: shard.total }; | ||||||
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.
Suggested change
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. 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. #48646 need to answer some questions before changing all files |
||||||
|
||||||
validateInteger(shard.total, 'options.shard.total', 1); | ||||||
validateInteger(shard.index, 'options.shard.index'); | ||||||
|
||||||
if (shard.index <= 0 || shard.total < shard.index) { | ||||||
throw new ERR_OUT_OF_RANGE('options.shard.index', `>= 1 && <= ${shard.total} ("options.shard.total")`, shard.index); | ||||||
|
@@ -470,7 +473,7 @@ function run(options) { | |||||
let testFiles = files ?? createTestFileList(); | ||||||
|
||||||
if (shard) { | ||||||
testFiles = testFiles.filter((_, index) => (index % shard.total) === (shard.index - 1)); | ||||||
testFiles = ArrayPrototypeFilter(testFiles, (_, index) => index % shard.total === shard.index - 1); | ||||||
} | ||||||
|
||||||
let postRun = () => root.postRun(); | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.