英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论