github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/go/testdata/script/test_race.txt (about) 1 [short] skip 2 [!race] skip 3 4 go test testrace 5 6 ! go test -race testrace 7 stdout 'FAIL: TestRace' 8 ! stdout 'PASS' 9 ! stderr 'PASS' 10 11 ! go test -race testrace -run XXX -bench . 12 stdout 'FAIL: BenchmarkRace' 13 ! stdout 'PASS' 14 ! stderr 'PASS' 15 16 -- testrace/race_test.go -- 17 package testrace 18 19 import "testing" 20 21 func TestRace(t *testing.T) { 22 for i := 0; i < 10; i++ { 23 c := make(chan int) 24 x := 1 25 go func() { 26 x = 2 27 c <- 1 28 }() 29 x = 3 30 <-c 31 _ = x 32 } 33 } 34 35 func BenchmarkRace(b *testing.B) { 36 for i := 0; i < b.N; i++ { 37 c := make(chan int) 38 x := 1 39 go func() { 40 x = 2 41 c <- 1 42 }() 43 x = 3 44 <-c 45 _ = x 46 } 47 }