aboutsummaryrefslogtreecommitdiffstats
path: root/cache/repo_cache_test.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-08-25 15:26:23 +0200
committerMichael Muré <batolettre@gmail.com>2020-08-25 15:26:23 +0200
commit4d678f3e057aea30d1396240d88e622c833a177f (patch)
treea895db664b6af7d676b6cfd59e001a54e8eae35b /cache/repo_cache_test.go
parent4b065029af63c16ffd754ac28190ba4b3125c494 (diff)
downloadgit-bug-4d678f3e057aea30d1396240d88e622c833a177f.tar.gz
cache: simplify cache eviction
Diffstat (limited to 'cache/repo_cache_test.go')
-rw-r--r--cache/repo_cache_test.go27
1 files changed, 10 insertions, 17 deletions
diff --git a/cache/repo_cache_test.go b/cache/repo_cache_test.go
index 426279e1..c0f7f189 100644
--- a/cache/repo_cache_test.go
+++ b/cache/repo_cache_test.go
@@ -214,12 +214,11 @@ func TestCacheEviction(t *testing.T) {
repo := repository.CreateTestRepo(false)
repoCache, err := NewRepoCache(repo)
require.NoError(t, err)
- repoCache.presentBugs.Resize(2)
+ repoCache.setCacheSize(2)
- require.Equal(t, 2, repoCache.presentBugs.maxSize)
- require.Equal(t, 0, repoCache.presentBugs.Len())
+ require.Equal(t, 2, repoCache.maxLoadedBugs)
+ require.Equal(t, 0, repoCache.loadedBugs.Len())
require.Equal(t, 0, len(repoCache.bugs))
- require.Equal(t, 0, len(repoCache.bugExcerpts))
// Generating some bugs
rene, err := repoCache.NewIdentity("René Descartes", "rene@descartes.fr")
@@ -231,51 +230,45 @@ func TestCacheEviction(t *testing.T) {
require.NoError(t, err)
checkBugPresence(t, repoCache, bug1, true)
- require.Equal(t, 1, repoCache.presentBugs.Len())
+ require.Equal(t, 1, repoCache.loadedBugs.Len())
require.Equal(t, 1, len(repoCache.bugs))
- require.Equal(t, 1, len(repoCache.bugExcerpts))
bug2, _, err := repoCache.NewBug("title", "message")
require.NoError(t, err)
checkBugPresence(t, repoCache, bug1, true)
checkBugPresence(t, repoCache, bug2, true)
- require.Equal(t, 2, repoCache.presentBugs.Len())
+ require.Equal(t, 2, repoCache.loadedBugs.Len())
require.Equal(t, 2, len(repoCache.bugs))
- require.Equal(t, 2, len(repoCache.bugExcerpts))
// Number of bugs should not exceed max size of lruCache, oldest one should be evicted
bug3, _, err := repoCache.NewBug("title", "message")
require.NoError(t, err)
- require.Equal(t, 2, repoCache.presentBugs.Len())
+ require.Equal(t, 2, repoCache.loadedBugs.Len())
require.Equal(t, 2, len(repoCache.bugs))
- require.Equal(t, 2, len(repoCache.bugExcerpts))
checkBugPresence(t, repoCache, bug1, false)
checkBugPresence(t, repoCache, bug2, true)
checkBugPresence(t, repoCache, bug3, true)
// Accessing bug should update position in lruCache and therefore it should not be evicted
- repoCache.presentBugs.Get(bug2.Id())
- oldestId, _ := repoCache.presentBugs.GetOldest()
+ repoCache.loadedBugs.Get(bug2.Id())
+ oldestId, _ := repoCache.loadedBugs.GetOldest()
require.Equal(t, bug3.Id(), oldestId)
checkBugPresence(t, repoCache, bug1, false)
checkBugPresence(t, repoCache, bug2, true)
checkBugPresence(t, repoCache, bug3, true)
- require.Equal(t, 2, repoCache.presentBugs.Len())
+ require.Equal(t, 2, repoCache.loadedBugs.Len())
require.Equal(t, 2, len(repoCache.bugs))
- require.Equal(t, 2, len(repoCache.bugExcerpts))
}
func checkBugPresence(t *testing.T, cache *RepoCache, bug *BugCache, presence bool) {
id := bug.Id()
- require.Equal(t, presence, cache.presentBugs.Contains(id))
+ require.Equal(t, presence, cache.loadedBugs.Contains(id))
b, ok := cache.bugs[id]
require.Equal(t, presence, ok)
if ok {
require.Equal(t, bug, b)
}
- _, ok = cache.bugExcerpts[id]
- require.Equal(t, presence, ok)
}