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

test(client): add integration runner #13149

Closed
wants to merge 18 commits into from

Conversation

danstarns
Copy link
Contributor

@danstarns danstarns commented May 4, 2022

Why

  1. Slow Tests #13092
  2. I was finding that the integration tests were running all at once and it was hard to tell jest to treat the integration differently without losing potential on the simple tests.

What

This PR excludes all of the tests in ./packages/client/tests/integration from the main test suite and introduces:

integration-runner.test.ts

This new file will readDir both the happy/ and errors/ tests and then perform sequential batching of n amount of tests.

Between each batch, a backoff is added so that we don't completely overwhelm other components such as the database.

How can I run them?

You should not need to change anything in your workflow, however, if you especially want to run the integration test's on their own you can run:

cd ./packages/client && pnpm run test integration

Findings

This shows my recorded stats of the time taken to run the client test suite before, with maxWorkers, and then after this addition.

Before

cd ./packages/client && pnpm run test

Could not run - Timed out!

Time:        560.228 s
Ran all test suites.
 ELIFECYCLE  Test failed. See above for more details.

cd ./packages/client && pnpm run test integration

Could not run - Timed out!

Time:        297.905 s
Ran all test suites matching /integration/i.
 ELIFECYCLE  Test failed. See above for more details.

Using maxWorkers

These run! However, the issue here is now that the entire test suite is running at 50% capacity when in reality we only want to limit the heavy load stuff(the integration tests).

cd ./packages/client && npx jest --maxWorkers="50%"

Pass

Time:        523.493 s, estimated 538 s
Ran all test suites.
cd ./packages/client && npx jest integration --maxWorkers="50%"

Pass

Time:        330.482 s
Ran all test suites matching /integration/i

After

cd ./packages/client && pnpm run test

Pass - 222.898 seconds faster

Time:        300.595 s
Ran all test suites.

cd ./packages/client && pnpm run test integration

Pass - 83.634 seconds faster

integration/integration-runner
    √ happy (243661 ms)
    √ errors

Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        246.848 s
Ran all test suites matching /integration/i.

Regressions

Some things we miss out on in this implementation, this is because we are now spawning Jest using exec. This means that the main Jest process doesn't have a full collective view of how many tests are run for example or the coverage of those files tested on inside the spawned process.

  1. Jest Stats - You can still see all in the console but it won't be in one nice neat place like normal.
  2. Code Coverage? - IDK yet standby

@danstarns danstarns mentioned this pull request May 4, 2022
@danstarns danstarns changed the title test: add int-runner test: add integration runner May 4, 2022
Copy link
Member

@aqrln aqrln left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried limiting maxWorkers in jest.config.js? This is not the same thing as what you're doing in this PR (which is also an interesting idea), but it might've solved the issue.

@danstarns danstarns changed the title test: add integration runner test(client): add integration runner May 4, 2022
@danstarns danstarns marked this pull request as ready for review May 4, 2022 23:06
@danstarns
Copy link
Contributor Author

Have you tried limiting maxWorkers in jest.config.js? This is not the same thing as what you're doing in this PR (which is also an interesting idea), but it might've solved the issue.

Yes, and this does help. I have added a section in the PR description Findings that shares my stats using maxWorkers.

const name = `${options.testType}/${options.dir}`

// Errors inside this child will propagate up
const child = await exec(`jest ${name} --config=${__dirname.replace(/\\\\/g, '/')}/jest.config.js --runInBand`, {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this process errors the entire suite will fail fast, we could catch the error and propagate it like with the logs below. WDYT?

afterAll(() => {
clearTimeout(timeout)

const log = logs
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging all at once so that it eases the load on your terminal and that they are all displayed one after the other. We might want to log errors here too...

@danstarns danstarns closed this May 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants