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