差异go test的两个标志-parallel,并-test.parallel和标记被优先?
-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').
Run Code Online (Sandbox Code Playgroud)
上面的文档说明并行运行的测试数量相等,GOMAXPROCS如果没有提供,但行为不像我的那样.因为我在只有4个核心的机器上运行测试.但对我来说,8个测试并行运行,所以行为更像是:
-test.parallel int
maximum test parallelism (default 8)
Run Code Online (Sandbox Code Playgroud)
那两者有什么区别?何时使用哪个标志.
我在一个包含9个测试的软件包上运行所有测试,所有这些测试都是并行运行的,所有这些都存在于单个测试功能中.
该-test.标志是由产生的go test命令.该go test命令动态生成pkg.test二进制文件并使用修改后的参数运行它.传递给所有已识别的参数go test将被转换.所以,在你的情况下:-parallel n成为-test.parallel n.
所以这个命令:
go test -parallel 6
Run Code Online (Sandbox Code Playgroud)
创建:
pkg.test -test.parallel 6
Run Code Online (Sandbox Code Playgroud)