MCPcopy
hub / github.com/rclone/rclone / TestCacheExpire

Function TestCacheExpire

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

Source from the content-addressed store, hash-verified

114}
115
116func TestCacheExpire(t *testing.T) {
117 c, create := setup(t)
118
119 c.SetExpireInterval(time.Millisecond)
120 assert.Equal(t, false, c.expireRunning)
121
122 _, err := c.Get("/", create)
123 require.NoError(t, err)
124
125 c.mu.Lock()
126 entry := c.cache["/"]
127 assert.Equal(t, 1, len(c.cache))
128 c.mu.Unlock()
129
130 c.cacheExpire()
131
132 c.mu.Lock()
133 assert.Equal(t, 1, len(c.cache))
134 entry.lastUsed = time.Now().Add(-c.expireDuration - 60*time.Second)
135 assert.Equal(t, true, c.expireRunning)
136 c.mu.Unlock()
137
138 time.Sleep(250 * time.Millisecond)
139
140 c.mu.Lock()
141 assert.Equal(t, false, c.expireRunning)
142 assert.Equal(t, 0, len(c.cache))
143 c.mu.Unlock()
144}
145
146func TestCacheNoExpire(t *testing.T) {
147 c, create := setup(t)

Callers

nothing calls this directly

Calls 8

setupFunction · 0.85
SetExpireIntervalMethod · 0.80
cacheExpireMethod · 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…