1 [!race] skip
2
3 go test testrace
4
5 [GOARCH:loong64] skip 'broken on loong64: #78219'
6
7 ! go test -race testrace
8 stdout 'FAIL: TestRace'
9 ! stdout 'PASS'
10 ! stderr 'PASS'
11
12 ! go test -race testrace -run XXX -bench .
13 stdout 'FAIL: BenchmarkRace'
14 ! stdout 'PASS'
15 ! stderr 'PASS'
16
17 -- go.mod --
18 module testrace
19
20 go 1.16
21 -- race_test.go --
22 package testrace
23
24 import "testing"
25
26 func TestRace(t *testing.T) {
27 for i := 0; i < 10; i++ {
28 c := make(chan int)
29 x := 1
30 go func() {
31 x = 2
32 c <- 1
33 }()
34 x = 3
35 <-c
36 _ = x
37 }
38 }
39
40 func BenchmarkRace(b *testing.B) {
41 for i := 0; i < b.N; i++ {
42 c := make(chan int)
43 x := 1
44 go func() {
45 x = 2
46 c <- 1
47 }()
48 x = 3
49 <-c
50 _ = x
51 }
52 }
53
View as plain text