Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Cai <jcai@gitlab.com>2019-08-05 16:44:58 +0300
committerJohn Cai <jcai@gitlab.com>2019-08-05 16:44:58 +0300
commit57a3f368ae95b77afef02148a5d43ce4ece3d99b (patch)
tree69f77bf5063341aa90057c551343591c36db281a
parent940331784ce6bf969be19a710fe9ab7b1bb33011 (diff)
parentc81f9b9a6ac68aa7cfceadb2687c6d3c57bf9674 (diff)
Merge branch 'jv-flaky-catfile-test' into 'master'
Fix flaky cat-file test Closes #1814 See merge request gitlab-org/gitaly!1388
-rw-r--r--internal/git/catfile/batch_cache_test.go21
1 files changed, 14 insertions, 7 deletions
diff --git a/internal/git/catfile/batch_cache_test.go b/internal/git/catfile/batch_cache_test.go
index 0f885d314..510b91a7a 100644
--- a/internal/git/catfile/batch_cache_test.go
+++ b/internal/git/catfile/batch_cache_test.go
@@ -133,24 +133,28 @@ func TestCacheEnforceTTL(t *testing.T) {
func TestAutoExpiry(t *testing.T) {
ttl := 5 * time.Millisecond
- bc := newCacheWithRefresh(ttl, 10, 1*time.Millisecond)
+ refresh := 1 * time.Millisecond
+ bc := newCacheWithRefresh(ttl, 10, refresh)
key0 := testKey(0)
value0 := testValue()
bc.Add(key0, value0)
requireCacheValid(t, bc)
- bc.Lock()
require.Contains(t, keys(bc), key0, "key should still be in map")
require.False(t, value0.isClosed(), "value should not have been closed")
- bc.Unlock()
- time.Sleep(2 * ttl)
+ // Wait for the monitor goroutine to do its thing
+ for i := 0; i < 100; i++ {
+ if len(keys(bc)) == 0 {
+ break
+ }
- bc.Lock()
- require.NotContains(t, keys(bc), key0, "key should no longer be in map")
+ time.Sleep(refresh)
+ }
+
+ require.Empty(t, keys(bc), "key should no longer be in map")
require.True(t, value0.isClosed(), "value should be closed after eviction")
- bc.Unlock()
}
func requireCacheValid(t *testing.T, bc *batchCache) {
@@ -169,6 +173,9 @@ func testValue() *Batch { return &Batch{} }
func testKey(i int) key { return key{sessionID: fmt.Sprintf("key-%d", i)} }
func keys(bc *batchCache) []key {
+ bc.Lock()
+ defer bc.Unlock()
+
var result []key
for _, ent := range bc.entries {
result = append(result, ent.key)