Skip to content

Commit

Permalink
[jest] automatically determine run order (elastic#130857)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer authored Apr 27, 2022
1 parent ac560f3 commit 1a05ce5
Show file tree
Hide file tree
Showing 38 changed files with 1,005 additions and 715 deletions.
915 changes: 915 additions & 0 deletions .buildkite/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .buildkite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"version": "1.0.0",
"private": true,
"dependencies": {
"kibana-buildkite-library": "elastic/kibana-buildkite-library"
"kibana-buildkite-library": "git+https://[email protected]/elastic/kibana-buildkite-library#0c02e8e8461f3bd5b6d686efe401d579d622395d"
}
}
25 changes: 5 additions & 20 deletions .buildkite/pipelines/pull_request/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,29 +123,14 @@ steps:
- exit_status: '*'
limit: 1

- command: .buildkite/scripts/steps/test/jest.sh
label: 'Jest Tests'
parallelism: 8
- command: .buildkite/scripts/steps/test/pick_jest_config_run_order.sh
label: 'Pick Jest Config Run Order'
agents:
queue: n2-4-spot
timeout_in_minutes: 90
key: jest
retry:
automatic:
- exit_status: '-1'
limit: 3

- command: .buildkite/scripts/steps/test/jest_integration.sh
label: 'Jest Integration Tests'
parallelism: 3
agents:
queue: n2-4-spot
timeout_in_minutes: 120
key: jest-integration
queue: kibana-default
retry:
automatic:
- exit_status: '-1'
limit: 3
- exit_status: '*'
limit: 1

- command: .buildkite/scripts/steps/test/api_integration.sh
label: 'API Integration Tests'
Expand Down
16 changes: 1 addition & 15 deletions .buildkite/scripts/lifecycle/pre_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,7 @@ export BUILDKITE_TOKEN

echo '--- Install buildkite dependencies'
cd '.buildkite'

# If this yarn install is terminated early, e.g. if the build is cancelled in buildkite,
# A node module could end up in a bad state that can cause all future builds to fail
# So, let's cache clean and try again to make sure that's not what caused the error
install_deps() {
yarn install --production --pure-lockfile
EXIT=$?
if [[ "$EXIT" != "0" ]]; then
yarn cache clean
fi
return $EXIT
}

retry 5 15 install_deps

retry 5 15 npm ci
cd ..

echo '--- Agent Debug/SSH Info'
Expand Down
7 changes: 7 additions & 0 deletions .buildkite/scripts/steps/test/jest_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -euo pipefail

# keys used to associate test group data in ci-stats with Jest execution order
export TEST_GROUP_TYPE_UNIT="Jest Unit Tests"
export TEST_GROUP_TYPE_INTEGRATION="Jest Integration Tests"
40 changes: 21 additions & 19 deletions .buildkite/scripts/steps/test/jest_parallel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,38 @@

set -uo pipefail

JOB=$BUILDKITE_PARALLEL_JOB
JOB_COUNT=$BUILDKITE_PARALLEL_JOB_COUNT
source .buildkite/scripts/steps/test/jest_env.sh

# a jest failure will result in the script returning an exit code of 10
export JOB=$BUILDKITE_PARALLEL_JOB

i=0
# a jest failure will result in the script returning an exit code of 10
exitCode=0

# run unit tests in parallel
if [[ "$1" == 'jest.config.js' ]]; then
# run unit tests in parallel
parallelism="-w2"
TEST_TYPE="unit"
else
# run integration tests in-band
parallelism="--runInBand"
TEST_TYPE="integration"
fi

export TEST_TYPE
echo "--- downloading integration test run order"
buildkite-agent artifact download jest_run_order.json .
configs=$(jq -r 'getpath([env.TEST_TYPE]) | .groups[env.JOB | tonumber].names | .[]' jest_run_order.json)

while read -r config; do
if [ "$((i % JOB_COUNT))" -eq "$JOB" ]; then
echo "--- $ node scripts/jest --config $config"
node --max-old-space-size=14336 ./scripts/jest --config="$config" "$parallelism" --coverage=false --passWithNoTests
lastCode=$?

if [ $lastCode -ne 0 ]; then
exitCode=10
echo "Jest exited with code $lastCode"
echo "^^^ +++"
fi
echo "--- $ node scripts/jest --config $config"
NODE_OPTIONS="--max-old-space-size=14336" node ./scripts/jest --config="$config" "$parallelism" --coverage=false --passWithNoTests
lastCode=$?

if [ $lastCode -ne 0 ]; then
exitCode=10
echo "Jest exited with code $lastCode"
echo "^^^ +++"
fi

((i=i+1))
# uses heredoc to avoid the while loop being in a sub-shell thus unable to overwrite exitCode
done <<< "$(find src x-pack packages -name "$1" -not -path "*/__fixtures__/*" | sort)"
done <<< "$configs"

exit $exitCode
22 changes: 22 additions & 0 deletions .buildkite/scripts/steps/test/pick_jest_config_run_order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

const { CiStats } = require('kibana-buildkite-library');

(async () => {
try {
await CiStats.pickTestGroupRunOrder();
} catch (ex) {
console.error('CI Stats Error', ex.message);
if (ex.response) {
console.error('HTTP Error Response Status', ex.response.status);
console.error('HTTP Error Response Body', ex.response.data);
}
process.exit(1);
}
})();
9 changes: 9 additions & 0 deletions .buildkite/scripts/steps/test/pick_jest_config_run_order.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -euo pipefail

source .buildkite/scripts/common/util.sh
source .buildkite/scripts/steps/test/jest_env.sh

echo '--- Pick Jest Config Run Order'
node "$(dirname "${0}")/pick_jest_config_run_order.js"
180 changes: 0 additions & 180 deletions .buildkite/yarn.lock

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ selenium
*.swo
*.out
package-lock.json
!/.buildkite/package-lock.json
.yo-rc.json
.vscode
*.sublime-*
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@
"@kbn/babel-preset": "link:bazel-bin/packages/kbn-babel-preset",
"@kbn/bazel-packages": "link:bazel-bin/packages/kbn-bazel-packages",
"@kbn/bazel-runner": "link:bazel-bin/packages/kbn-bazel-runner",
"@kbn/ci-stats-client": "link:bazel-bin/packages/kbn-ci-stats-client",
"@kbn/ci-stats-core": "link:bazel-bin/packages/kbn-ci-stats-core",
"@kbn/ci-stats-reporter": "link:bazel-bin/packages/kbn-ci-stats-reporter",
"@kbn/cli-dev-mode": "link:bazel-bin/packages/kbn-cli-dev-mode",
Expand Down Expand Up @@ -613,7 +612,6 @@
"@types/kbn__axe-config": "link:bazel-bin/packages/kbn-axe-config/npm_module_types",
"@types/kbn__bazel-packages": "link:bazel-bin/packages/kbn-bazel-packages/npm_module_types",
"@types/kbn__bazel-runner": "link:bazel-bin/packages/kbn-bazel-runner/npm_module_types",
"@types/kbn__ci-stats-client": "link:bazel-bin/packages/kbn-ci-stats-client/npm_module_types",
"@types/kbn__ci-stats-core": "link:bazel-bin/packages/kbn-ci-stats-core/npm_module_types",
"@types/kbn__ci-stats-reporter": "link:bazel-bin/packages/kbn-ci-stats-reporter/npm_module_types",
"@types/kbn__cli-dev-mode": "link:bazel-bin/packages/kbn-cli-dev-mode/npm_module_types",
Expand Down
2 changes: 0 additions & 2 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ filegroup(
"//packages/kbn-babel-preset:build",
"//packages/kbn-bazel-packages:build",
"//packages/kbn-bazel-runner:build",
"//packages/kbn-ci-stats-client:build",
"//packages/kbn-ci-stats-core:build",
"//packages/kbn-ci-stats-reporter:build",
"//packages/kbn-cli-dev-mode:build",
Expand Down Expand Up @@ -126,7 +125,6 @@ filegroup(
"//packages/kbn-axe-config:build_types",
"//packages/kbn-bazel-packages:build_types",
"//packages/kbn-bazel-runner:build_types",
"//packages/kbn-ci-stats-client:build_types",
"//packages/kbn-ci-stats-core:build_types",
"//packages/kbn-ci-stats-reporter:build_types",
"//packages/kbn-cli-dev-mode:build_types",
Expand Down
13 changes: 0 additions & 13 deletions packages/kbn-bazel-runner/jest.config.js

This file was deleted.

Loading

0 comments on commit 1a05ce5

Please sign in to comment.