...

Text file src/cmd/go/testdata/script/test_race_cover_mode_issue20435.txt

Documentation: cmd/go/testdata/script

     1[short] skip
     2[!race] skip
     3
     4# Make sure test is functional.
     5go test testrace
     6
     7# Now, check that -race -covermode=set is not allowed.
     8! go test -race -covermode=set testrace
     9stderr '-covermode must be "atomic", not "set", when -race is enabled'
    10! stdout PASS
    11! stderr PASS
    12
    13-- go.mod --
    14module testrace
    15
    16go 1.16
    17-- race_test.go --
    18package testrace
    19
    20import "testing"
    21
    22func TestRace(t *testing.T) {
    23	for i := 0; i < 10; i++ {
    24		c := make(chan int)
    25		x := 1
    26		go func() {
    27			x = 2
    28			c <- 1
    29		}()
    30		x = 3
    31		<-c
    32		_ = x
    33	}
    34}
    35
    36func BenchmarkRace(b *testing.B) {
    37	for i := 0; i < b.N; i++ {
    38		c := make(chan int)
    39		x := 1
    40		go func() {
    41			x = 2
    42			c <- 1
    43		}()
    44		x = 3
    45		<-c
    46		_ = x
    47	}
    48}

View as plain text