Skip to content
This repository was archived by the owner on Oct 3, 2022. It is now read-only.

Commit f8d57d3

Browse files
committed
test: extend memory-based eviction test
1 parent 0ea222f commit f8d57d3

File tree

1 file changed

+17
-30
lines changed

1 file changed

+17
-30
lines changed

eviction_test.go

+17-30
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
func TestEviction(t *testing.T) {
1010
t.Parallel()
1111

12-
prepareCache := func() (*Cache, [3]*Frontend) {
12+
prepareCache := func(memoryLimit uint) (*Cache, [3]*Frontend) {
1313
var wg sync.WaitGroup
14-
caches, frontends := prepareRecursion(0, 0)
14+
caches, frontends := prepareRecursion(memoryLimit, 0)
1515
testRecursion(t, &wg, caches, frontends)
1616
wg.Wait()
1717

@@ -23,17 +23,18 @@ func TestEviction(t *testing.T) {
2323
t.Run("max-memory-based", func(t *testing.T) {
2424
t.Parallel()
2525

26-
c, frontends := prepareCache()
27-
c.memoryLimit = 1
26+
c, _ := prepareCache(1)
27+
assertConsistency(t, c)
2828

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)
3437
}
35-
36-
assertConsistency(t, c)
3738
})
3839

3940
cases := [...]struct {
@@ -59,7 +60,7 @@ func TestEviction(t *testing.T) {
5960
t.Run("cache", func(t *testing.T) {
6061
t.Parallel()
6162

62-
c, _ := prepareCache()
63+
c, _ := prepareCache(0)
6364

6465
c.EvictAll(opts.timer)
6566
await()
@@ -78,7 +79,7 @@ func TestEviction(t *testing.T) {
7879
t.Run("frontend", func(t *testing.T) {
7980
t.Parallel()
8081

81-
c, frontends := prepareCache()
82+
c, frontends := prepareCache(0)
8283
frontends[2].EvictAll(opts.timer)
8384
await()
8485

@@ -138,7 +139,7 @@ func TestEviction(t *testing.T) {
138139
t.Run("by key", func(t *testing.T) {
139140
t.Parallel()
140141

141-
c, frontends := prepareCache()
142+
c, frontends := prepareCache(0)
142143

143144
frontends[0].Evict(opts.timer, recursiveData{
144145
Cache: 0,
@@ -156,7 +157,7 @@ func TestEviction(t *testing.T) {
156157
t.Run("by function", func(t *testing.T) {
157158
t.Parallel()
158159

159-
c, frontends := prepareCache()
160+
c, frontends := prepareCache(0)
160161

161162
err := frontends[0].EvictByFunc(
162163
opts.timer,
@@ -178,7 +179,7 @@ func TestEviction(t *testing.T) {
178179
t.Run("by function with error", func(t *testing.T) {
179180
t.Parallel()
180181

181-
c, frontends := prepareCache()
182+
c, frontends := prepareCache(0)
182183

183184
err := frontends[0].EvictByFunc(
184185
opts.timer,
@@ -193,20 +194,6 @@ func TestEviction(t *testing.T) {
193194
assertConsistency(t, c)
194195
})
195196
})
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-
})
210197
})
211198
}
212199
}

0 commit comments

Comments
 (0)