MCPcopy
hub / github.com/grpc/grpc-go / TestDataCache_AddForcesResize

Method TestDataCache_AddForcesResize

balancer/rls/cache_test.go:134–161  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

132}
133
134func (s) TestDataCache_AddForcesResize(t *testing.T) {
135 initCacheEntries()
136 dc := newDataCache(1, nil, "")
137
138 // The first entry in cacheEntries has a minimum expiry time in the future.
139 // This entry would stop the resize operation since we do not evict entries
140 // whose minimum expiration time is in the future. So, we do not use that
141 // entry in this test. The entry being added has a running backoff timer.
142 evicted, ok := dc.addEntry(cacheKeys[1], cacheEntries[1])
143 if evicted || !ok {
144 t.Fatalf("dataCache.addEntry() returned (%v, %v) want (false, true)", evicted, ok)
145 }
146
147 // Add another entry leading to the eviction of the above entry which has a
148 // running backoff timer. The first return value is expected to be true.
149 backoffCancelled, ok := dc.addEntry(cacheKeys[2], cacheEntries[2])
150 if !backoffCancelled || !ok {
151 t.Fatalf("dataCache.addEntry() returned (%v, %v) want (true, true)", backoffCancelled, ok)
152 }
153
154 // Add another entry leading to the eviction of the above entry which does not
155 // have a running backoff timer. This should evict the above entry, but the
156 // first return value is expected to be false.
157 backoffCancelled, ok = dc.addEntry(cacheKeys[3], cacheEntries[3])
158 if backoffCancelled || !ok {
159 t.Fatalf("dataCache.addEntry() returned (%v, %v) want (false, true)", backoffCancelled, ok)
160 }
161}
162
163func (s) TestDataCache_Resize(t *testing.T) {
164 initCacheEntries()

Callers

nothing calls this directly

Calls 4

initCacheEntriesFunction · 0.85
newDataCacheFunction · 0.85
FatalfMethod · 0.65
addEntryMethod · 0.45

Tested by

no test coverage detected