MCPcopy
hub / github.com/rclone/rclone / TestCacheFinalize

Function TestCacheFinalize

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

Source from the content-addressed store, hash-verified

351}
352
353func TestCacheFinalize(t *testing.T) {
354 c := New()
355 numCalled := 0
356 c.SetFinalizer(func(v any) {
357 numCalled++
358 })
359 create := func(path string) (any, bool, error) {
360 return path, true, nil
361 }
362 _, _ = c.Get("ok", create)
363 assert.Equal(t, 0, numCalled)
364 c.Clear()
365 assert.Equal(t, 1, numCalled)
366
367 _, _ = c.Get("ok", create)
368 c.Delete("ok")
369 assert.Equal(t, 2, numCalled)
370
371 _, _ = c.Get("ok", create)
372 c.DeletePrefix("ok")
373 assert.Equal(t, 3, numCalled)
374
375 _, _ = c.Get("old", create)
376 _, _ = c.Get("new", create)
377 c.Rename("old", "new")
378 assert.Equal(t, 4, numCalled)
379
380 c.expireDuration = 1 * time.Millisecond
381 _, _ = c.Get("ok", create)
382 time.Sleep(2 * time.Millisecond)
383 c.cacheExpire() // "ok" and "new" fall out of cache
384 assert.Equal(t, 6, numCalled)
385}

Callers

nothing calls this directly

Calls 9

SetFinalizerMethod · 0.80
DeletePrefixMethod · 0.80
cacheExpireMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
DeleteMethod · 0.65
RenameMethod · 0.65
EqualMethod · 0.45
ClearMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…