英文:
go test `-parallel` vs `-test.parallel` which flag gets precedence?
问题
go test
命令的两个标志-parallel
和-test.parallel
之间的区别是什么?哪个标志优先级更高?
-parallel n
标志允许并行执行调用了t.Parallel
的测试函数。该标志的值是同时运行的最大测试数;默认情况下,它设置为GOMAXPROCS
的值。需要注意的是,-parallel
仅适用于单个测试二进制文件。根据-p
标志的设置(参见go help build
),go test
命令也可以并行运行不同包的测试。
上述文档说明,如果未提供任何值,则并行运行的测试数等于GOMAXPROCS
的值,但对于我来说,行为并非如此。因为我在一台只有4个核心的机器上运行测试。但是对我来说,有8个测试并行运行,所以行为更像是以下内容:
-test.parallel int
标志表示最大测试并行性(默认值为8)。
所以这两者之间有什么区别?何时使用哪个标志。
更多信息
我正在对一个单独的包运行所有测试,该包有9个测试,所有这些测试都在单个测试函数中并行运行。
英文:
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.
More Information
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.
答案1
得分: 10
-test.
标志是由 go test
命令生成的。go test
命令会即时生成一个 pkg.test
二进制文件,并使用修改后的参数运行它。所有被识别的传递给 go test
的参数都会被转换。所以,在你的情况下:-parallel n
会变成 -test.parallel n
。
因此,这个命令:
go test -parallel 6
会生成:
pkg.test -test.parallel 6
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论