-
Notifications
You must be signed in to change notification settings - Fork 128
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
Split and group tests to run subsets in parallel #284
Comments
Thanks for opening this issue! I believe #277 may do what you want. That branch still needs some work, primarily some new tests. This new Maybe you can change Option 1 If func TestMain(m *testing.M) {
if !isTestList() {
// do init code here
....
}
os.Exit(m.Run())
}
func isTestList() bool {
for _, arg := range os.Args {
if arg == "-test.list" || strings.HasPrefix(arg, "-test.list") {
return true
}
}
return false
} Option 2 If you have a common setup function for all the tests, you could move the initialization into a function that isn't var initOnce sync.Once
func setup(t *testing.T) {
// do shared setup first
initOnce.Do(func() {
// init logic that used to be in TestMain
...
})
...
} I hope that helps! |
That is very helpful @dnephin thanks! |
Both should be possible. The original feature in #258 splits a test run by package, so each split is a group of packages. |
This feature will greatly help us. Is there anything I can do to help with merging it? |
Thanks for having a look! I think the main thing blocking a merge is some more test coverage. It would be great to understand how you're planning on using this. Would you split by package, or split the tests in one package? Do you use github actions, or would you be looking to use this in a different CI system? I think one of the limitations right now is that we have to run a job first to That first job can easily add 30s+ to the total runtime. It depends on how long it takes to build the project to list the tests. That extra time is probably saved by splitting the test run into parallel batches, but for smaller test suites it might reduce the time saved a bit. |
We would like to run integration tests in batches. But, we want to run all tests in a certain package together since it shares an initialization code (spinning up test-containers) we want to only run once. All of this runs on Github Actions. I didn't test how long will |
I would like to suggest a splitting feature to group tests to subsets and run them separately.
There is this tool: https://github.com/Songmu/gotesplit but I think it will be hard to make it work well with gotestsum.
I also tried working with
go test ./... -list=.
which should list all tests but the issue is that it runsTestMain
and executes our init code for integration tests.I really wish I could use gotestsum like gotesplit.
Something like:
# Run the first subset of three gotestsum --split-subsets=3 --split-index=1
Or:
These could come in really handy to split integration tests to several jobs in the CI and thus shorten the dev cycle.
Thanks.
The text was updated successfully, but these errors were encountered: