@@ -28,27 +28,27 @@ const (
2828// go test -v -cover -run=^TestCacheType$
2929func TestCacheType (t * testing.T ) {
3030 if standard .String () != string (standard ) {
31- t .Errorf ("standard.String() %s is wrong" , standard .String ())
31+ t .Fatalf ("standard.String() %s is wrong" , standard .String ())
3232 }
3333
3434 if lru .String () != string (lru ) {
35- t .Errorf ("lru.String() %s is wrong" , lru .String ())
35+ t .Fatalf ("lru.String() %s is wrong" , lru .String ())
3636 }
3737
3838 if lfu .String () != string (lfu ) {
39- t .Errorf ("lfu.String() %s is wrong" , lfu .String ())
39+ t .Fatalf ("lfu.String() %s is wrong" , lfu .String ())
4040 }
4141
4242 if ! standard .IsStandard () {
43- t .Error ("!standard.IsStandard()" )
43+ t .Fatal ("!standard.IsStandard()" )
4444 }
4545
4646 if ! lru .IsLRU () {
47- t .Error ("!standard.IsLRU()" )
47+ t .Fatal ("!standard.IsLRU()" )
4848 }
4949
5050 if ! lfu .IsLFU () {
51- t .Error ("!standard.IsLFU()" )
51+ t .Fatal ("!standard.IsLFU()" )
5252 }
5353}
5454
@@ -87,97 +87,97 @@ func (tc *testCache) Reset() {}
8787func testCacheGet (t * testing.T , cache Cache ) {
8888 value , found := cache .Get ("key" )
8989 if found {
90- t .Errorf ("get %+v should be not found" , value )
90+ t .Fatalf ("get %+v should be not found" , value )
9191 }
9292
9393 cache .Set ("key" , "value" , time .Millisecond )
9494
9595 value , found = cache .Get ("key" )
9696 if ! found {
97- t .Error ("get should be found" )
97+ t .Fatal ("get should be found" )
9898 }
9999
100100 if value .(string ) != "value" {
101- t .Errorf ("value %+v is wrong" , value )
101+ t .Fatalf ("value %+v is wrong" , value )
102102 }
103103
104104 time .Sleep (2 * time .Millisecond )
105105
106106 value , found = cache .Get ("key" )
107107 if found {
108- t .Errorf ("get %+v should be not found" , value )
108+ t .Fatalf ("get %+v should be not found" , value )
109109 }
110110}
111111
112112func testCacheSet (t * testing.T , cache Cache ) {
113113 value , found := cache .Get ("key" )
114114 if found {
115- t .Errorf ("get %+v should be not found" , value )
115+ t .Fatalf ("get %+v should be not found" , value )
116116 }
117117
118118 cache .Set ("key" , "value" , time .Millisecond )
119119
120120 value , found = cache .Get ("key" )
121121 if ! found {
122- t .Error ("get should be found" )
122+ t .Fatal ("get should be found" )
123123 }
124124
125125 if value .(string ) != "value" {
126- t .Errorf ("value %+v is wrong" , value )
126+ t .Fatalf ("value %+v is wrong" , value )
127127 }
128128
129129 time .Sleep (2 * time .Millisecond )
130130
131131 value , found = cache .Get ("key" )
132132 if found {
133- t .Errorf ("get %+v should be not found" , value )
133+ t .Fatalf ("get %+v should be not found" , value )
134134 }
135135
136136 cache .Set ("key" , "value" , NoTTL )
137137
138138 value , found = cache .Get ("key" )
139139 if ! found {
140- t .Error ("get should be found" )
140+ t .Fatal ("get should be found" )
141141 }
142142
143143 if value .(string ) != "value" {
144- t .Errorf ("value %+v is wrong" , value )
144+ t .Fatalf ("value %+v is wrong" , value )
145145 }
146146
147147 time .Sleep (2 * time .Millisecond )
148148
149149 value , found = cache .Get ("key" )
150150 if ! found {
151- t .Error ("get should be found" )
151+ t .Fatal ("get should be found" )
152152 }
153153}
154154
155155func testCacheRemove (t * testing.T , cache Cache ) {
156156 removedValue := cache .Remove ("key" )
157157 if removedValue != nil {
158- t .Errorf ("removedValue %+v is wrong" , removedValue )
158+ t .Fatalf ("removedValue %+v is wrong" , removedValue )
159159 }
160160
161161 cache .Set ("key" , "value" , NoTTL )
162162
163163 removedValue = cache .Remove ("key" )
164164 if removedValue .(string ) != "value" {
165- t .Errorf ("removedValue %+v is wrong" , removedValue )
165+ t .Fatalf ("removedValue %+v is wrong" , removedValue )
166166 }
167167
168168 cache .Set ("key" , "value" , time .Millisecond )
169169 time .Sleep (2 * time .Millisecond )
170170
171171 removedValue = cache .Remove ("key" )
172172 if removedValue == nil {
173- t .Error ("removedValue == nil" )
173+ t .Fatal ("removedValue == nil" )
174174 }
175175}
176176
177177func testCacheSize (t * testing.T , cache Cache ) {
178178 size := cache .Size ()
179179 if size != 0 {
180- t .Errorf ("size %d is wrong" , size )
180+ t .Fatalf ("size %d is wrong" , size )
181181 }
182182
183183 for i := int64 (0 ); i < maxTestEntries ; i ++ {
@@ -186,14 +186,14 @@ func testCacheSize(t *testing.T, cache Cache) {
186186
187187 size = cache .Size ()
188188 if size != maxTestEntries {
189- t .Errorf ("size %d is wrong" , size )
189+ t .Fatalf ("size %d is wrong" , size )
190190 }
191191}
192192
193193func testCacheGC (t * testing.T , cache Cache ) {
194194 size := cache .Size ()
195195 if size != 0 {
196- t .Errorf ("size %d is wrong" , size )
196+ t .Fatalf ("size %d is wrong" , size )
197197 }
198198
199199 for i := int64 (0 ); i < maxTestEntries ; i ++ {
@@ -206,14 +206,14 @@ func testCacheGC(t *testing.T, cache Cache) {
206206
207207 size = cache .Size ()
208208 if size != maxTestEntries {
209- t .Errorf ("size %d is wrong" , size )
209+ t .Fatalf ("size %d is wrong" , size )
210210 }
211211
212212 cache .GC ()
213213
214214 size = cache .Size ()
215215 if size != maxTestEntries {
216- t .Errorf ("size %d is wrong" , size )
216+ t .Fatalf ("size %d is wrong" , size )
217217 }
218218
219219 time .Sleep (2 * time .Millisecond )
@@ -222,7 +222,7 @@ func testCacheGC(t *testing.T, cache Cache) {
222222
223223 size = cache .Size ()
224224 if size != maxTestEntries / 2 {
225- t .Errorf ("size %d is wrong" , size )
225+ t .Fatalf ("size %d is wrong" , size )
226226 }
227227}
228228
@@ -234,31 +234,31 @@ func testCacheReset(t *testing.T, cache Cache) {
234234 for i := int64 (0 ); i < maxTestEntries ; i ++ {
235235 value , found := cache .Get (strconv .FormatInt (i , 10 ))
236236 if ! found {
237- t .Errorf ("get %d should be found" , i )
237+ t .Fatalf ("get %d should be found" , i )
238238 }
239239
240240 if value .(int64 ) != i {
241- t .Errorf ("value %+v is wrong" , value )
241+ t .Fatalf ("value %+v is wrong" , value )
242242 }
243243 }
244244
245245 size := cache .Size ()
246246 if size != maxTestEntries {
247- t .Errorf ("size %d is wrong" , size )
247+ t .Fatalf ("size %d is wrong" , size )
248248 }
249249
250250 cache .Reset ()
251251
252252 for i := int64 (0 ); i < maxTestEntries ; i ++ {
253253 value , found := cache .Get (strconv .FormatInt (i , 10 ))
254254 if found {
255- t .Errorf ("get %d, %+v should be not found" , i , value )
255+ t .Fatalf ("get %d, %+v should be not found" , i , value )
256256 }
257257 }
258258
259259 size = cache .Size ()
260260 if size != 0 {
261- t .Errorf ("size %d is wrong" , size )
261+ t .Fatalf ("size %d is wrong" , size )
262262 }
263263}
264264
@@ -279,38 +279,38 @@ func TestNewCache(t *testing.T) {
279279
280280 sc1 , ok := cache .(* standardCache )
281281 if ! ok {
282- t .Errorf ("cache.(*standardCache) %T not ok" , cache )
282+ t .Fatalf ("cache.(*standardCache) %T not ok" , cache )
283283 }
284284
285285 if sc1 == nil {
286- t .Error ("sc1 == nil" )
286+ t .Fatal ("sc1 == nil" )
287287 }
288288
289289 cache = NewCache (WithLRU (16 ))
290290
291291 sc2 , ok := cache .(* lruCache )
292292 if ! ok {
293- t .Errorf ("cache.(*lruCache) %T not ok" , cache )
293+ t .Fatalf ("cache.(*lruCache) %T not ok" , cache )
294294 }
295295
296296 if sc2 == nil {
297- t .Error ("sc2 == nil" )
297+ t .Fatal ("sc2 == nil" )
298298 }
299299
300300 cache = NewCache (WithShardings (64 ))
301301
302302 sc , ok := cache .(* shardingCache )
303303 if ! ok {
304- t .Errorf ("cache.(*shardingCache) %T not ok" , cache )
304+ t .Fatalf ("cache.(*shardingCache) %T not ok" , cache )
305305 }
306306
307307 if sc == nil {
308- t .Error ("sc == nil" )
308+ t .Fatal ("sc == nil" )
309309 }
310310
311311 defer func () {
312312 if r := recover (); r == nil {
313- t .Error ("new should panic" )
313+ t .Fatal ("new should panic" )
314314 }
315315 }()
316316
@@ -323,15 +323,15 @@ func TestNewCacheWithReport(t *testing.T) {
323323
324324 sc1 , ok := cache .(* reportableCache )
325325 if ! ok {
326- t .Errorf ("cache.(*reportableCache) %T not ok" , cache )
326+ t .Fatalf ("cache.(*reportableCache) %T not ok" , cache )
327327 }
328328
329329 if sc1 == nil {
330- t .Error ("sc1 == nil" )
330+ t .Fatal ("sc1 == nil" )
331331 }
332332
333333 if reporter == nil {
334- t .Error ("reporter == nil" )
334+ t .Fatal ("reporter == nil" )
335335 }
336336}
337337
@@ -341,7 +341,7 @@ func TestRunGCTask(t *testing.T) {
341341
342342 count := cache .currentCount ()
343343 if count != 0 {
344- t .Errorf ("cache.currentCount() %d is wrong" , count )
344+ t .Fatalf ("cache.currentCount() %d is wrong" , count )
345345 }
346346
347347 cancel := RunGCTask (cache , 10 * time .Millisecond )
@@ -350,21 +350,21 @@ func TestRunGCTask(t *testing.T) {
350350
351351 count = cache .currentCount ()
352352 if count != 10 {
353- t .Errorf ("cache.currentCount() %d is wrong" , count )
353+ t .Fatalf ("cache.currentCount() %d is wrong" , count )
354354 }
355355
356356 time .Sleep (80 * time .Millisecond )
357357 cancel ()
358358
359359 count = cache .currentCount ()
360360 if count != 18 {
361- t .Errorf ("cache.currentCount() %d is wrong" , count )
361+ t .Fatalf ("cache.currentCount() %d is wrong" , count )
362362 }
363363
364364 time .Sleep (time .Second )
365365
366366 count = cache .currentCount ()
367367 if count != 18 {
368- t .Errorf ("cache.currentCount() %d is wrong" , count )
368+ t .Fatalf ("cache.currentCount() %d is wrong" , count )
369369 }
370370}
0 commit comments