Skip to content

Commit

Permalink
[ci] Improve parallelism of yarn test
Browse files Browse the repository at this point in the history
Changes the `ci` argument to be an enum instead so the tests use all
available workers in GitHub actions.

- When `ci === 'github'` also increase maxConcurrency to 10
- Increase timeout of ReactMultiChildText-test.js
- Chunk test files

ghstack-source-id: cee93fe1531b35ddb309d21865f67cc89a805696
Pull Request resolved: #30033
  • Loading branch information
poteto committed Jun 21, 2024
1 parent 7e2f1d5 commit 1956a99
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ jobs:
steps:
- checkout
- setup_node_modules
- run: yarn test <<parameters.args>> --ci
- run: yarn test <<parameters.args>> --ci=circleci

yarn_test_build:
docker: *docker
Expand Down
101 changes: 74 additions & 27 deletions .github/workflows/runtime_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,81 @@ on:
- 'compiler/**'

jobs:
test:
name: yarn test
build_test_params:
name: Build test params
runs-on: ubuntu-latest
outputs:
params: ${{ steps.define-params.outputs.result }}
steps:
- uses: actions/github-script@v7
id: define-params
with:
script: |
return [
"-r=stable --env=development",
"-r=stable --env=production",
"-r=experimental --env=development",
"-r=experimental --env=production",
"-r=www-classic --env=development --variant=false",
"-r=www-classic --env=production --variant=false",
"-r=www-classic --env=development --variant=true",
"-r=www-classic --env=production --variant=true",
"-r=www-modern --env=development --variant=false",
"-r=www-modern --env=production --variant=false",
"-r=www-modern --env=development --variant=true",
"-r=www-modern --env=production --variant=true",
"-r=xplat --env=development --variant=false",
"-r=xplat --env=development --variant=true",
"-r=xplat --env=production --variant=false",
"-r=xplat --env=production --variant=true",
// TODO: Test more persistent configurations?
"-r=stable --env=development --persistent",
"-r=experimental --env=development --persistent"
];
chunk_tests:
name: Chunk tests
runs-on: ubuntu-latest
needs: build_test_params
strategy:
matrix:
params: ${{ fromJSON(needs.build_test_params.outputs.params) }}
continue-on-error: true
outputs:
chunks: ${{ steps.chunks.outputs }}
chunk_ids: ${{ steps.chunk_ids.outputs }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: yarn.lock
- name: Restore cached node_modules
uses: actions/cache@v4
id: node_modules
with:
path: "**/node_modules"
key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
- run: yarn install --frozen-lockfile
- id: chunks
name: Set chunks
run: echo "chunks=$(yarn --silent test ${{ matrix.params }} --listTests --json --ci=github | jq -cM '[_nwise(length / 2 | ceil)]')" >> $GITHUB_OUTPUT
- id: chunk_ids
name: Set chunk IDs
run: echo "$chunk_ids=$(echo $CHUNKS | jq -cM 'to_entries | map(.key)')" >> $GITHUB_OUTPUT
env:
CHUNKS: ${{ steps.chunks.outputs }}

test:
name: yarn test ${{ matrix.params }} (${{ matrix.chunk_ids }})
runs-on: ubuntu-latest
needs: [build_test_params, chunk_tests]
strategy:
matrix:
# Intentionally passing these as strings instead of creating a
# separate parameter per CLI argument, since it's easier to
# control/see which combinations we want to run.
params: [
"-r=stable --env=development",
"-r=stable --env=production",
"-r=experimental --env=development",
"-r=experimental --env=production",
"-r=www-classic --env=development --variant=false",
"-r=www-classic --env=production --variant=false",
"-r=www-classic --env=development --variant=true",
"-r=www-classic --env=production --variant=true",
"-r=www-modern --env=development --variant=false",
"-r=www-modern --env=production --variant=false",
"-r=www-modern --env=development --variant=true",
"-r=www-modern --env=production --variant=true",
"-r=xplat --env=development --variant=false",
"-r=xplat --env=development --variant=true",
"-r=xplat --env=production --variant=false",
"-r=xplat --env=production --variant=true",
# TODO: Test more persistent configurations?
"-r=stable --env=development --persistent",
"-r=experimental --env=development --persistent"
]
params: ${{ fromJSON(needs.build_test_params.outputs.params) }}
chunk_ids: ${{ fromJSON(needs.chunk_tests.outputs.chunk_ids) }}
continue-on-error: true
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand All @@ -52,4 +97,6 @@ jobs:
path: "**/node_modules"
key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
- run: yarn install --frozen-lockfile
- run: yarn test ${{ matrix.params }} --ci
- run: echo $CHUNKS | jq '.[${{ matrix.chunk_ids }}] | .[] | @text' | xargs yarn test ${{ matrix.params }} --ci=github
env:
CHUNKS: ${{ needs.chunk_tests.outputs.chunks }}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const expectChildren = function (container, children) {
* faster to render and update.
*/
describe('ReactMultiChildText', () => {
jest.setTimeout(20000);
jest.setTimeout(30000);

it('should correctly handle all possible children for render and update', async () => {
await expect(async () => {
Expand Down
30 changes: 18 additions & 12 deletions scripts/jest/jest-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ const argv = yargs
ci: {
describe: 'Run tests in CI',
requiresArg: false,
type: 'boolean',
default: false,
type: 'choices',
choices: ['circleci', 'github'],
},
compactConsole: {
alias: 'c',
Expand Down Expand Up @@ -309,10 +309,14 @@ function getCommandArgs() {
}

// CI Environments have limited workers.
if (argv.ci) {
if (argv.ci === 'circleci') {
args.push('--maxWorkers=2');
}

if (argv.ci === 'github') {
args.push('--maxConcurrency=10 --workerThreads=true');
}

// Push the remaining args onto the command.
// This will send args like `--watch` to Jest.
args.push(...argv._);
Expand Down Expand Up @@ -364,16 +368,18 @@ function main() {
const envars = getEnvars();
const env = Object.entries(envars).map(([k, v]) => `${k}=${v}`);

// Print the full command we're actually running.
const command = `$ ${env.join(' ')} node ${args.join(' ')}`;
console.log(chalk.dim(command));
if (argv.ci !== 'github') {
// Print the full command we're actually running.
const command = `$ ${env.join(' ')} node ${args.join(' ')}`;
console.log(chalk.dim(command));

// Print the release channel and project we're running for quick confirmation.
console.log(
chalk.blue(
`\nRunning tests for ${argv.project} (${argv.releaseChannel})...`
)
);
// Print the release channel and project we're running for quick confirmation.
console.log(
chalk.blue(
`\nRunning tests for ${argv.project} (${argv.releaseChannel})...`
)
);
}

// Print a message that the debugger is starting just
// for some extra feedback when running the debugger.
Expand Down

0 comments on commit 1956a99

Please sign in to comment.