(t *testing.T)
| 114 | } |
| 115 | |
| 116 | func 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 | |
| 146 | func TestCacheNoExpire(t *testing.T) { |
| 147 | c, create := setup(t) |
nothing calls this directly
no test coverage detected
searching dependent graphs…