-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctl_test.go
38 lines (34 loc) · 699 Bytes
/
ctl_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
package raft
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestAsyncCtl(t *testing.T) {
ctl := newAsyncCtl()
go func() {
defer ctl.Release()
time.Sleep(1000 * time.Millisecond)
}()
ctl.Cancel()
select {
case <-time.NewTimer(3000 * time.Millisecond).C:
assert.FailNow(t, "timed out waiting for asyncCtl's release")
case <-ctl.WaitRelease():
return
}
}
func TestAsyncCtlCancel(t *testing.T) {
ctl := newAsyncCtl()
go func() {
defer ctl.Release()
<-ctl.Cancelled()
}()
ctl.Cancel()
select {
case <-time.NewTimer(1000 * time.Millisecond).C:
assert.FailNow(t, "timed out waiting for asyncCtl's release")
case <-ctl.WaitRelease():
return
}
}