Reputation: 1755
Difference between go test
's two flags -parallel
and -test.parallel
and which flag gets precedence?
-parallel n
Allow parallel execution of test functions that call t.Parallel.
The value of this flag is the maximum number of tests to run
simultaneously; by default, it is set to the value of GOMAXPROCS.
Note that -parallel only applies within a single test binary.
The 'go test' command may run tests for different packages
in parallel as well, according to the setting of the -p flag
(see 'go help build').
Above documentation says that the number of tests that are run in parallel are equal to GOMAXPROCS
if nothing is provided, but the behavior is not like that for me. Because I am running tests on a machine that has only 4 cores. But for me 8 tests run in parallel, so the behavior is more like following:
-test.parallel int
maximum test parallelism (default 8)
So what is the difference between the two? When to use which flag.
I am running all tests on a single package which has 9 tests, all of them are run parallely and all those exist in single test function.
Upvotes: 4
Views: 5457
Reputation: 1649
The -test.
flags are generated by go test
command. The go test
command produces a pkg.test
binary on the fly and runs it with modified arguments. All the recognized arguments passed to go test
will be converted. So, in your case: -parallel n
becomes -test.parallel n
.
So this command:
go test -parallel 6
creates:
pkg.test -test.parallel 6
Upvotes: 11