-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcancelable_test.go
48 lines (34 loc) · 1.08 KB
/
cancelable_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
package multilimiter_test
import (
"testing"
"time"
"github.com/jrboelens/multilimiter"
. "github.com/smartystreets/goconvey/convey"
)
func TestCancelableSpec(t *testing.T) {
Convey("Cancelable tests ", t, func() {
Convey("Cancel is idempotent", func() {
canceler := multilimiter.NewCanceler()
So(canceler.IsCanceled(), ShouldEqual, false)
alreadyCanceled := canceler.Cancel()
// ensure we're now stopped and that we've flipped to a stopped state
So(alreadyCanceled, ShouldEqual, false)
So(canceler.IsCanceled(), ShouldEqual, true)
alreadyCanceled = canceler.Cancel()
// ensure we were already stopped
So(alreadyCanceled, ShouldEqual, true)
So(canceler.IsCanceled(), ShouldEqual, true)
})
Convey("The Done() channel is closed after Cancel is called", func() {
canceler := multilimiter.NewCanceler()
So(canceler.IsCanceled(), ShouldEqual, false)
canceler.Cancel()
select {
case <-canceler.Done():
case <-time.After(50 * time.Millisecond):
// if we found ourselves here, we've failed
So(false, ShouldEqual, true)
}
})
})
}