(t *testing.T)
| 285 | } |
| 286 | |
| 287 | func TestCacheEviction(t *testing.T) { |
| 288 | repo := repository.CreateGoGitTestRepo(t, false) |
| 289 | repoCache := createTestRepoCacheNoEvents(t, repo) |
| 290 | repoCache.setCacheSize(2) |
| 291 | |
| 292 | require.Equal(t, 2, repoCache.bugs.maxLoaded) |
| 293 | require.Len(t, repoCache.bugs.cached, 0) |
| 294 | require.Equal(t, repoCache.bugs.lru.Len(), 0) |
| 295 | |
| 296 | // Generating some bugs |
| 297 | rene, err := repoCache.Identities().New("René Descartes", "rene@descartes.fr") |
| 298 | require.NoError(t, err) |
| 299 | err = repoCache.SetUserIdentity(rene) |
| 300 | require.NoError(t, err) |
| 301 | |
| 302 | bug1, _, err := repoCache.Bugs().New("title", "message") |
| 303 | require.NoError(t, err) |
| 304 | |
| 305 | checkBugPresence(t, repoCache, bug1, true) |
| 306 | require.Len(t, repoCache.bugs.cached, 1) |
| 307 | require.Equal(t, 1, repoCache.bugs.lru.Len()) |
| 308 | |
| 309 | bug2, _, err := repoCache.Bugs().New("title", "message") |
| 310 | require.NoError(t, err) |
| 311 | |
| 312 | checkBugPresence(t, repoCache, bug1, true) |
| 313 | checkBugPresence(t, repoCache, bug2, true) |
| 314 | require.Len(t, repoCache.bugs.cached, 2) |
| 315 | require.Equal(t, 2, repoCache.bugs.lru.Len()) |
| 316 | |
| 317 | // Number of bugs should not exceed max size of lruCache, oldest one should be evicted |
| 318 | bug3, _, err := repoCache.Bugs().New("title", "message") |
| 319 | require.NoError(t, err) |
| 320 | |
| 321 | require.Len(t, repoCache.bugs.cached, 2) |
| 322 | require.Equal(t, 2, repoCache.bugs.lru.Len()) |
| 323 | checkBugPresence(t, repoCache, bug1, false) |
| 324 | checkBugPresence(t, repoCache, bug2, true) |
| 325 | checkBugPresence(t, repoCache, bug3, true) |
| 326 | |
| 327 | // Accessing bug should update position in lruCache, and therefore it should not be evicted |
| 328 | repoCache.bugs.lru.Get(bug2.Id()) |
| 329 | oldestId, _ := repoCache.bugs.lru.GetOldest() |
| 330 | require.Equal(t, bug3.Id(), oldestId) |
| 331 | |
| 332 | checkBugPresence(t, repoCache, bug1, false) |
| 333 | checkBugPresence(t, repoCache, bug2, true) |
| 334 | checkBugPresence(t, repoCache, bug3, true) |
| 335 | require.Len(t, repoCache.bugs.cached, 2) |
| 336 | require.Equal(t, 2, repoCache.bugs.lru.Len()) |
| 337 | } |
| 338 | |
| 339 | func TestLongDescription(t *testing.T) { |
| 340 | // See https://github.com/git-bug/git-bug/issues/606 |
nothing calls this directly
no test coverage detected