在使用竞争检测器时,我可以跳过特定的测试吗?

huangapple go评论67阅读模式
英文:

Can I skip a specific test when using the race detector?

问题

Go Race Detector的goroutine限制是8192(至少在我的系统上是这样)。我运行的一个测试是查看我的服务器代码如何处理大量同时打开的连接(现在我正在尝试> 15000)。因此,当我运行go test --race时,该特定测试失败。我希望在使用-race运行时跳过它,而不是直接失败。我该如何做到这一点?

英文:

The Go Race Detector has a goroutine limit of 8192 (at least on my system). One test I run is to see how my server code handles a large number of simultaneous open connections (right now I'm trying out > 15000). When I run go test --race, therefore, that particular test fails. I'd rather it be skipped when run using -race instead of failing directly. How can I do that?

答案1

得分: 15

构建标签race在使用-race标志进行构建时定义。

将要排除的测试移动到带有构建约束注释的文件中:

//go:build !race

如果您使用的是Go 1.17或更早版本,则还需要使用旧的构建约束语法添加额外的注释:

//go:build !race
// +build !race
英文:

The build tag race is defined when building with the -race flag.

Move the tests you want to exclude to a file with the build constraint comment:

//go:build !race

If you are using Go 1.17 or earlier, then include an additional comment with the old build constraint syntax:

//go:build !race
// +build !race

huangapple
  • 本文由 发表于 2016年1月22日 07:45:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/34936571.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定