-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfuse_test.go
56 lines (52 loc) · 920 Bytes
/
fuse_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
package core
import (
"testing"
"time"
)
func TestFuse(t *testing.T) {
runOnce := func(f *Fuse) <-chan struct{} {
onceStarted := make(chan struct{})
onceFinished := make(chan struct{})
if f.IsBroken() {
t.Fail()
}
go func() {
f.Once(func() {
close(onceStarted)
time.Sleep(time.Second / 2)
close(onceFinished)
})
}()
<-onceStarted
if f.IsBroken() {
t.Fail()
}
return onceFinished
}
t.Run("break waits for once", func(t *testing.T) {
var f Fuse
onceFinished := runOnce(&f)
f.Break()
if !f.IsBroken() {
t.Fail()
}
select {
case <-onceFinished:
default:
t.Fatal("break doest wait for once to complete")
}
})
t.Run("can get channel early", func(t *testing.T) {
var f Fuse
done := f.Watch()
<-runOnce(&f)
if !f.IsBroken() {
t.Fail()
}
select {
case <-done:
default:
t.Fatal("watched channel not closed after once")
}
})
}