gpt4 book ai didi

testing - go test `-parallel` vs `-test.parallel` 哪个标志优先?

转载 作者:IT王子 更新时间:2023-10-29 01:26:25 31 4
gpt4 key购买 nike

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').

上面的文档说,如果没有提供任何内容,并行运行的测试数等于 GOMAXPROCS,但对我而言,行为并非如此。因为我在只有 4 个内核的机器上运行测试。但对我而言,8 个测试并行运行,因此行为更像是以下内容:

-test.parallel int
maximum test parallelism (default 8)

那么两者有什么区别呢?什么时候使用哪个标志。

更多信息

我在一个包含 9 个测试的包上运行所有测试,所有测试都是并行运行的,并且所有这些都存在于单个测试函数中。

最佳答案

-test. 标志由 go test 命令生成。 go test 命令即时生成一个 pkg.test 二进制文件并使用修改后的参数运行它。传递给 go test 的所有可识别参数都将被转换。因此,在您的情况下:-parallel n 变为 -test.parallel n

所以这个命令:

go test -parallel 6

创造:

pkg.test -test.parallel 6

关于testing - go test `-parallel` vs `-test.parallel` 哪个标志优先?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45974414/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com