Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

testing

go

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?

like image 509
muru Avatar asked Dec 15 '22 09:12

muru


1 Answers

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
like image 140
Bayta Darell Avatar answered Dec 29 '22 00:12

Bayta Darell