Skip to content
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

chore: enable test parallelism #32766

Merged
merged 2 commits into from Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 29 additions & 18 deletions .circleci/config.yml
Expand Up @@ -63,6 +63,7 @@ aliases:
- /blog.+/

test_template: &test_template
parallelism: 4
parameters:
npm_rebuild:
type: boolean
Expand All @@ -75,11 +76,16 @@ aliases:
condition: << parameters.npm_rebuild >>
steps:
- run: npm rebuild
- run: yarn list react
- run: yarn why lmdb-store
- run:
command: node --max-old-space-size=2048 ./node_modules/.bin/jest -w 1 --ci
name: Step debug info
command: |
yarn list react
yarn why lmdb-store
- run:
name: Run tests
command: yarn jest --ci --runInBand $(yarn jest --listTests | sed 's/\/root\/project//g' | circleci tests split --split-by=timings)
environment:
NODE_OPTIONS: --max-old-space-size=2048
GENERATE_JEST_REPORT: true
JEST_JUNIT_OUTPUT_DIR: ./test-results/jest-node/
JEST_JUNIT_OUTPUT_NAME: results.xml
Expand Down Expand Up @@ -193,7 +199,8 @@ jobs:
- persist_to_workspace:
root: ./
paths:
- "*"
- "packages/"
- "node_modules/"

lint:
executor: node
Expand Down Expand Up @@ -496,6 +503,7 @@ jobs:
working_directory: ~/project/scripts/i18n

windows_unit_tests:
parallelism: 4
executor:
name: win/default
shell: powershell.exe
Expand All @@ -509,28 +517,30 @@ jobs:
# keys:
# - yarn-packages-v2-{{ checksum "yarn.lock" }}
# - yarn-packages-v2-

- <<: *attach_to_bootstrap
- run:
name: Install node 12.13
name: Install node 12.13 and yarn
command: |
nvm install 12.13.0
nvm alias default 12.13.0
nvm use 12.13.0
choco install yarn
- run:
name: Set yarn timeout
command: yarn config set network-timeout 300000
- run:
name: Install node modules
command: yarn --frozen-lockfile
# Caching is slow, so disabling
# - save_cache:
# paths:
# - C:\Users\circleci\AppData\Local\Yarn\Cache
# key: yarn-packages-v2-{{ checksum "yarn.lock" }}
- run: yarn npm-run-all -s check-versions "lerna-prepare --concurrency=4 --stream"
name: Rebuild packages for windows
command: |
Remove-Item -Recurse -Force -Path "node_modules/sharp/"
yarn
- run:
name: "Run Tests"
command: yarn jest -w 1 --ci
name: Run tests
command: yarn jest --ci --runInBand ((yarn jest --listTests) | Foreach-Object {$_ -replace '.*\\packages', 'packages'} | Foreach-Object {$_ -replace '\\', '/'} | circleci tests split --split-by=timings)
environment:
NODE_OPTIONS: --max-old-space-size=2048
GENERATE_JEST_REPORT: true
JEST_JUNIT_OUTPUT_DIR: ./test-results/jest-node/
JEST_JUNIT_OUTPUT_NAME: results.xml
- store_test_results:
path: ./test-results/jest-node/

bootstrap-with-experimental-react:
executor: node
Expand Down Expand Up @@ -617,6 +627,7 @@ workflows:
<<: *ignore_docs
requires:
- lint
- bootstrap
- unit_tests_node12:
<<: *ignore_docs
requires:
Expand Down
@@ -1,5 +1,5 @@
const waitForAPIOptions = {
timeout: 10000,
timeout: 5000,
}

function runTests(testNameSuffix) {
Expand Down
7 changes: 7 additions & 0 deletions packages/gatsby/src/utils/worker/__tests__/config.ts
Expand Up @@ -4,6 +4,13 @@ import * as path from "path"

let worker: GatsbyTestWorkerPool | undefined

jest.mock(`gatsby-telemetry`, () => {
return {
decorateEvent: jest.fn(),
trackCli: jest.fn(),
}
})

beforeEach(() => {
store.dispatch({ type: `DELETE_CACHE` })
})
Expand Down
12 changes: 12 additions & 0 deletions packages/gatsby/src/utils/worker/__tests__/datastore.ts
Expand Up @@ -7,6 +7,18 @@ import { store } from "../../../redux"
import { actions } from "../../../redux/actions"
import { getDataStore } from "../../../datastore"

jest.mock(`gatsby-telemetry`, () => {
return {
decorateEvent: jest.fn(),
trackError: jest.fn(),
trackCli: jest.fn(),
}
})

jest.mock(`gatsby-cli/lib/reporter`, () => {
return {}
})

let worker: GatsbyTestWorkerPool | undefined

beforeEach(() => {
Expand Down
9 changes: 9 additions & 0 deletions packages/gatsby/src/utils/worker/__tests__/jobs.ts
Expand Up @@ -6,6 +6,15 @@ import { waitUntilAllJobsComplete } from "../../jobs/manager"
import type { MessagesFromChild, MessagesFromParent } from "../messaging"
import { getReduxJobs, getJobsMeta } from "./test-helpers/child-for-tests"

jest.mock(`gatsby-telemetry`, () => {
return {
decorateEvent: jest.fn(),
trackCli: jest.fn(),
}
})

// jest.mock(`gatsby-cli/lib/reporter`, () => jest.fn())

let worker: GatsbyTestWorkerPool | undefined

describe(`worker (jobs)`, () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/gatsby/src/utils/worker/__tests__/queries.ts
Expand Up @@ -44,6 +44,14 @@ jest.mock(`chokidar`, () => {
return chokidar
})

jest.mock(`gatsby-telemetry`, () => {
return {
decorateEvent: jest.fn(),
trackError: jest.fn(),
trackCli: jest.fn(),
}
})

const dummyKeys = `a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z`.split(
`,`
)
Expand Down
8 changes: 8 additions & 0 deletions packages/gatsby/src/utils/worker/__tests__/schema.ts
Expand Up @@ -37,6 +37,14 @@ jest.mock(`chokidar`, () => {
return chokidar
})

jest.mock(`gatsby-telemetry`, () => {
return {
decorateEvent: jest.fn(),
trackError: jest.fn(),
trackCli: jest.fn(),
}
})

describeWhenLMDB(`worker (schema)`, () => {
let stateFromWorker: CombinedState<IGatsbyState>

Expand Down
8 changes: 8 additions & 0 deletions packages/gatsby/src/utils/worker/__tests__/share-state.ts
Expand Up @@ -7,6 +7,14 @@ import {
} from "../../../redux"
import { GatsbyStateKeys } from "../../../redux/types"

jest.mock(`gatsby-telemetry`, () => {
return {
decorateEvent: jest.fn(),
trackError: jest.fn(),
trackCli: jest.fn(),
}
})

let worker: GatsbyTestWorkerPool | undefined

const dummyPagePayload = {
Expand Down