MCPcopy Create free account
hub / github.com/allegro/bigcache / TestEntriesIteratorWithConcurrentUpdate

Function TestEntriesIteratorWithConcurrentUpdate

iterator_test.go:79–119  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

77}
78
79func TestEntriesIteratorWithConcurrentUpdate(t *testing.T) {
80 t.Parallel()
81
82 // given
83 cache, _ := New(context.Background(), Config{
84 Shards: 1,
85 LifeWindow: time.Second,
86 MaxEntriesInWindow: 1,
87 MaxEntrySize: 256,
88 })
89
90 cache.Set("key", []byte("value"))
91
92 // when
93 iterator := cache.Iterator()
94
95 // then
96 if !iterator.SetNext() {
97 t.Errorf("Iterator should contain at least single element")
98 }
99
100 getOldestEntry := func(s *cacheShard) ([]byte, error) {
101 s.lock.RLock()
102 defer s.lock.RUnlock()
103 return s.entries.Peek()
104 }
105
106 // Quite ugly but works
107 for i := 0; i < cache.config.Shards; i++ {
108 if oldestEntry, err := getOldestEntry(cache.shards[i]); err == nil {
109 cache.onEvict(oldestEntry, 10, cache.shards[i].removeOldestEntry)
110 }
111 }
112
113 current, err := iterator.Value()
114 assertEqual(t, nil, err)
115 assertEqual(t, []byte("value"), current.Value())
116
117 next := iterator.SetNext()
118 assertEqual(t, false, next)
119}
120
121func TestEntriesIteratorWithAllShardsEmpty(t *testing.T) {
122 t.Parallel()

Callers

nothing calls this directly

Calls 8

NewFunction · 0.85
SetMethod · 0.80
IteratorMethod · 0.80
SetNextMethod · 0.80
PeekMethod · 0.80
assertEqualFunction · 0.70
onEvictMethod · 0.45
ValueMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…