MCPcopy
hub / github.com/rclone/rclone / TestCachePin

Function TestCachePin

lib/cache/cache_test.go:171–218  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

169}
170
171func TestCachePin(t *testing.T) {
172 c, create := setup(t)
173
174 _, err := c.Get("/", create)
175 require.NoError(t, err)
176
177 // Pin a nonexistent item to show nothing happens
178 c.Pin("notfound")
179
180 c.mu.Lock()
181 entry := c.cache["/"]
182 assert.Equal(t, 1, len(c.cache))
183 c.mu.Unlock()
184
185 c.cacheExpire()
186
187 c.mu.Lock()
188 assert.Equal(t, 1, len(c.cache))
189 c.mu.Unlock()
190
191 // Pin the entry and check it does not get expired
192 c.Pin("/")
193
194 // Reset last used to make the item expirable
195 c.mu.Lock()
196 entry.lastUsed = time.Now().Add(-c.expireDuration - 60*time.Second)
197 c.mu.Unlock()
198
199 c.cacheExpire()
200
201 c.mu.Lock()
202 assert.Equal(t, 1, len(c.cache))
203 c.mu.Unlock()
204
205 // Unpin the entry and check it does get expired now
206 c.Unpin("/")
207
208 // Reset last used
209 c.mu.Lock()
210 entry.lastUsed = time.Now().Add(-c.expireDuration - 60*time.Second)
211 c.mu.Unlock()
212
213 c.cacheExpire()
214
215 c.mu.Lock()
216 assert.Equal(t, 0, len(c.cache))
217 c.mu.Unlock()
218}
219
220func TestClear(t *testing.T) {
221 c, create := setup(t)

Callers

nothing calls this directly

Calls 9

setupFunction · 0.85
PinMethod · 0.80
cacheExpireMethod · 0.80
UnpinMethod · 0.80
GetMethod · 0.65
LockMethod · 0.65
UnlockMethod · 0.65
AddMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…