9
9
func TestEviction (t * testing.T ) {
10
10
t .Parallel ()
11
11
12
- prepareCache := func () (* Cache , [3 ]* Frontend ) {
12
+ prepareCache := func (memoryLimit uint ) (* Cache , [3 ]* Frontend ) {
13
13
var wg sync.WaitGroup
14
- caches , frontends := prepareRecursion (0 , 0 )
14
+ caches , frontends := prepareRecursion (memoryLimit , 0 )
15
15
testRecursion (t , & wg , caches , frontends )
16
16
wg .Wait ()
17
17
@@ -23,17 +23,18 @@ func TestEviction(t *testing.T) {
23
23
t .Run ("max-memory-based" , func (t * testing.T ) {
24
24
t .Parallel ()
25
25
26
- c , frontends := prepareCache ()
27
- c . memoryLimit = 1
26
+ c , _ := prepareCache (1 )
27
+ assertConsistency ( t , c )
28
28
29
- _ , err := frontends [2 ].Get (recursiveData {
30
- Key : 1 ,
31
- })
32
- if err != nil {
33
- t .Fatal (err )
29
+ recs := 0
30
+ for _ , f := range c .frontends {
31
+ recs += len (f )
32
+ }
33
+ // Because just inserted keys are never evicted, there will be one key
34
+ // per frontend
35
+ if recs > 3 {
36
+ t .Fatalf ("stored record count not minimal: %d" , recs )
34
37
}
35
-
36
- assertConsistency (t , c )
37
38
})
38
39
39
40
cases := [... ]struct {
@@ -59,7 +60,7 @@ func TestEviction(t *testing.T) {
59
60
t .Run ("cache" , func (t * testing.T ) {
60
61
t .Parallel ()
61
62
62
- c , _ := prepareCache ()
63
+ c , _ := prepareCache (0 )
63
64
64
65
c .EvictAll (opts .timer )
65
66
await ()
@@ -78,7 +79,7 @@ func TestEviction(t *testing.T) {
78
79
t .Run ("frontend" , func (t * testing.T ) {
79
80
t .Parallel ()
80
81
81
- c , frontends := prepareCache ()
82
+ c , frontends := prepareCache (0 )
82
83
frontends [2 ].EvictAll (opts .timer )
83
84
await ()
84
85
@@ -138,7 +139,7 @@ func TestEviction(t *testing.T) {
138
139
t .Run ("by key" , func (t * testing.T ) {
139
140
t .Parallel ()
140
141
141
- c , frontends := prepareCache ()
142
+ c , frontends := prepareCache (0 )
142
143
143
144
frontends [0 ].Evict (opts .timer , recursiveData {
144
145
Cache : 0 ,
@@ -156,7 +157,7 @@ func TestEviction(t *testing.T) {
156
157
t .Run ("by function" , func (t * testing.T ) {
157
158
t .Parallel ()
158
159
159
- c , frontends := prepareCache ()
160
+ c , frontends := prepareCache (0 )
160
161
161
162
err := frontends [0 ].EvictByFunc (
162
163
opts .timer ,
@@ -178,7 +179,7 @@ func TestEviction(t *testing.T) {
178
179
t .Run ("by function with error" , func (t * testing.T ) {
179
180
t .Parallel ()
180
181
181
- c , frontends := prepareCache ()
182
+ c , frontends := prepareCache (0 )
182
183
183
184
err := frontends [0 ].EvictByFunc (
184
185
opts .timer ,
@@ -193,20 +194,6 @@ func TestEviction(t *testing.T) {
193
194
assertConsistency (t , c )
194
195
})
195
196
})
196
-
197
- t .Run ("same cache recursion" , func (t * testing.T ) {
198
- t .Parallel ()
199
-
200
- c , frontends := prepareCache ()
201
- c .memoryLimit = 1
202
-
203
- _ , err := frontends [2 ].Get (recursiveData {})
204
- if err != nil {
205
- t .Fatal (err )
206
- }
207
-
208
- assertConsistency (t , c )
209
- })
210
197
})
211
198
}
212
199
}
0 commit comments