-
Notifications
You must be signed in to change notification settings - Fork 79
/
race_test.go
60 lines (50 loc) · 1.03 KB
/
race_test.go
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
49
50
51
52
53
54
55
56
57
58
59
60
package goblin
import (
"sync"
"testing"
"time"
)
func TestG_It_AsyncDone_Race(t *testing.T) {
fakeTest := testing.T{}
g := Goblin(&fakeTest)
g.Describe("Async test", func() {
g.It("Should not create a data race if done() is called multiple times", func(done Done) {
go func() {
time.Sleep(100 * time.Millisecond)
done()
done()
}()
})
})
}
func TestG_It_Fail_Race(t *testing.T) {
g := Goblin(new(testing.T))
g.Describe("Synchronous test", func() {
g.It("Should not create a data race on fail", func() {
g.Fail("Failed")
})
})
}
func TestG_It_Assert_Race(t *testing.T) {
g := Goblin(new(testing.T))
g.SetReporter(Reporter(new(FakeReporter)))
g.Describe("Should not create a data race", func() {
g.It("Should fail", func() {
g.Assert(0).Equal(1)
})
g.It("Should pass", func() {
})
})
}
func TestG_Parallel_New_Goblin(t *testing.T) {
wg := new(sync.WaitGroup)
const cnt = 2
wg.Add(cnt)
for i := 0; i < cnt; i++ {
go func() {
Goblin(new(testing.T))
wg.Done()
}()
}
wg.Wait()
}