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

Custom slicing of tests #7672

Closed
tusharmath opened this issue Jan 21, 2019 · 5 comments
Closed

Custom slicing of tests #7672

tusharmath opened this issue Jan 21, 2019 · 5 comments

Comments

@tusharmath
Copy link

I posted the question on Stackoverflow here — https://stackoverflow.com/questions/54122568/custom-slicing-of-tests-in-jest

Since no one has responded I thought I will repost the question here —


We recently migrated all our tests to Jest and have seen a significant improvement in performance. Because we had too many tests it would still take a lot of time to run them on one server.

We decided to run tests on multiple servers in parallel by writing a custom sed command and slicing the test files based on the machine the jest command is running on.

The problem is that all test files don't have equal distribution of tests. Some files may have more tests than others.

We want to now slice tests based on some custom logic so that each machine runs the same number of tests.

Is there a way I can provide a filter function that can decide if the test needs to be executed on that machine or not?

@jeysal
Copy link
Contributor

jeysal commented Jan 21, 2019

Are you actually trying to run the same number of tests on each machine, or just to distribute the execution time as uniformly as possible (i.e. avoiding one machine idling for a long time in the end)?
It may not be an ideal solution, but for the latter one thing that I could quickly come up with is using --listTests and then distributing the tests round-robin, e.g.

/a.test.js 0
/b.test.js 1
/c.test.js 2
/d.test.js 0
/e.test.js 1
/f.test.js 2
/g.test.js 0

Because Jest will print the tests in descending order of expected duration, this should achieve a somewhat uniform distribution.

@tusharmath
Copy link
Author

tusharmath commented Jan 21, 2019

Are you actually trying to run the same number of tests on each machine, or just to distribute the execution time as uniformly as possible (i.e. avoiding one machine idling for a long time in the end)?

I need to distribute work uniformly amongst multiple test servers.

It may not be an ideal solution

Why would it not be an ideal solution? Is there a better way to do this?

It may not be an ideal solution, but for the latter one thing that I could quickly come up with is using --listTests and then distributing the tests round-robin,

This would only print out the test files. I want to have more granular control over the test cases themselves.

Because Jest will print the tests in descending order of expected duration, this should achieve a somewhat uniform distribution.

On the CI server im guessing Jest would not have any historical data.

@jeysal
Copy link
Contributor

jeysal commented Jan 21, 2019

Why would it not be an ideal solution? Is there a better way to do this?

None that I could think of right now, sorry.

On the CI server im guessing Jest would not have any historical data.

Unless you tell it to preserve the cacheDirectory (/tmp/jest_rs). Without historical data, we try to make a best guess how long tests might take, one that might get more elaborate in the future.

Without knowing your setup in great detail, maybe try to preserve the cache and see if round robin distribution of test files is good enough?

@SimenB
Copy link
Member

SimenB commented Jan 21, 2019

Duplicate of #6270

@SimenB SimenB marked this as a duplicate of #6270 Jan 21, 2019
@SimenB SimenB closed this as completed Jan 21, 2019
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants