forked from viccon/sturdyc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions_test.go
154 lines (130 loc) · 3.4 KB
/
options_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package sturdyc_test
import (
"testing"
"time"
"github.com/viccon/sturdyc"
)
func TestPanicsIfCapacityIsLessThanZero(t *testing.T) {
t.Parallel()
defer func() {
err := recover()
if err == nil {
t.Error("expected a panic when capacity is less than zero")
}
}()
sturdyc.New[string](-1, 1, time.Hour, 5)
}
func TestPanicsIfTheNumberOfShardsIsLessThanOne(t *testing.T) {
t.Parallel()
defer func() {
err := recover()
if err == nil {
t.Error("expected a panic when trying to use zero shards")
}
}()
sturdyc.New[string](100, 0, time.Hour, 5)
}
func TestPanicsIfTTLIsLessThanOne(t *testing.T) {
t.Parallel()
defer func() {
err := recover()
if err == nil {
t.Error("expected a panic when trying to use zero as TTL")
}
}()
sturdyc.New[string](100, 2, 0, 5)
}
func TestPanicsIfEvictionPercentageIsLessThanZero(t *testing.T) {
t.Parallel()
defer func() {
err := recover()
if err == nil {
t.Error("expected a panic when trying to use -1 as eviction percentage")
}
}()
sturdyc.New[string](100, 10, time.Minute, -1)
}
func TestPanicsIfEvictionPercentageIsGreaterThanOneHundred(t *testing.T) {
t.Parallel()
defer func() {
err := recover()
if err == nil {
t.Error("expected a panic when trying to use 101 as eviction percentage")
}
}()
sturdyc.New[string](100, 10, time.Minute, 101)
}
func TestPanicsIfRefreshBufferingIsEnabledWithoutStampedeProtection(t *testing.T) {
t.Parallel()
defer func() {
err := recover()
if err == nil {
t.Error("expected a panic when trying to use buffered refreshes without stampede protection")
}
}()
sturdyc.New[string](100, 10, time.Minute, 5,
sturdyc.WithRefreshCoalescing(10, time.Minute),
)
}
func TestPanicsIfTheRefreshBufferSizeIsLessThanOne(t *testing.T) {
t.Parallel()
defer func() {
err := recover()
if err == nil {
t.Error("expected a panic when trying to use buffered refreshes with zero as size")
}
}()
sturdyc.New[string](100, 10, time.Minute, 5,
sturdyc.WithEarlyRefreshes(time.Minute, time.Hour, time.Second),
sturdyc.WithRefreshCoalescing(0, time.Minute),
)
}
func TestPanicsIfTheRefreshBufferTimeoutIsLessThanOne(t *testing.T) {
t.Parallel()
defer func() {
err := recover()
if err == nil {
t.Error("expected a panic when trying to use 0 as buffer timeout")
}
}()
sturdyc.New[string](100, 10, time.Minute, 5,
sturdyc.WithEarlyRefreshes(time.Minute, time.Hour, time.Second),
sturdyc.WithRefreshCoalescing(10, 0),
)
}
func TestPanicsIfTheEvictionIntervalIsSetToLessThanOne(t *testing.T) {
t.Parallel()
defer func() {
err := recover()
if err == nil {
t.Error("expected a panic when trying to use 0 as eviction interval")
}
}()
sturdyc.New[string](100, 10, time.Minute, 5,
sturdyc.WithEvictionInterval(0),
)
}
func TestPanicsIfTheMinRefreshTimeIsGreaterThanTheMaxRefreshTime(t *testing.T) {
t.Parallel()
defer func() {
err := recover()
if err == nil {
t.Error("expected a panic when trying to use hour as min refresh time and minute as max")
}
}()
sturdyc.New[string](100, 10, time.Minute, 5,
sturdyc.WithEarlyRefreshes(time.Hour, time.Minute, time.Second),
)
}
func TestPanicsIfTheRetryBaseDelayIsLessThanZero(t *testing.T) {
t.Parallel()
defer func() {
err := recover()
if err == nil {
t.Error("expected a panic when trying to use -1 as retry base delay")
}
}()
sturdyc.New[string](100, 10, time.Minute, 5,
sturdyc.WithEarlyRefreshes(time.Minute, time.Hour, -1),
)
}