forked from googlearchive/go-gcm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
backoff_test.go
69 lines (58 loc) · 1.55 KB
/
backoff_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
61
62
63
64
65
66
67
68
69
package gcm
import (
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Backoff Provider", func() {
Context("initializing", func() {
It("should init successfully", func() {
p := newExponentialBackoff()
Expect(p).To(BeAssignableToTypeOf(&exponentialBackoff{}))
bp := p.(*exponentialBackoff)
Expect(bp.b).NotTo(BeZero())
Expect(bp.b.Min).To(Equal(DefaultMinBackoff))
Expect(bp.b.Max).To(Equal(DefaultMaxBackoff))
Expect(bp.b.Jitter).To(BeTrue())
Expect(bp.currentDelay).To(Equal(time.Second))
})
})
Context("initialized", func() {
var (
b backoffProvider
bp *exponentialBackoff
)
BeforeEach(func() {
b = newExponentialBackoff()
bp = b.(*exponentialBackoff)
})
It("should get minimum duration", func() {
Expect(b.getMin()).To(Equal(b.(*exponentialBackoff).b.Min))
})
It("should decrease minimum duration", func() {
delay := 100 * time.Millisecond
b.setMin(delay)
Expect(bp.b.Min).To(Equal(delay))
})
It("should increase minimum duration", func() {
delay := 2 * time.Second
b.setMin(delay)
Expect(bp.b.Min).To(Equal(delay))
Expect(bp.currentDelay).To(Equal(delay))
})
It("should send another", func() {
s := b.sendAnother()
Expect(s).To(BeTrue())
})
It("should not send another", func() {
bp.currentDelay = DefaultMaxBackoff + time.Millisecond
s := b.sendAnother()
Expect(s).To(BeFalse())
})
It("should wait", func() {
bp.currentDelay = time.Millisecond
b.wait()
Expect(bp.currentDelay).NotTo(Equal(time.Millisecond))
})
})
})