diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-12-02 15:13:00 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-12-10 14:48:29 +0300 |
commit | 24d0db28d5b8dce9e0204020b52b16e2efa8f167 (patch) | |
tree | 87ee151e4c8065cbed7f7733d2943b92eb2f9f6c | |
parent | 4bf6dbc3d7f815d453033c21e4d4554c61c4c881 (diff) |
cache: Get rid of short timeouts
Refactor the code to avoid timeouts. Unfortunately, there is no way
right now to verify that the cache walker did its thing, so we still
have to use a timeout there. We hopefully avoid any flakiness though by
setting a high timeout value.
-rw-r--r-- | internal/cache/diskcache_test.go | 3 | ||||
-rw-r--r-- | internal/cache/walker_test.go | 26 |
2 files changed, 5 insertions, 24 deletions
diff --git a/internal/cache/diskcache_test.go b/internal/cache/diskcache_test.go index d977fbda8..497b89dee 100644 --- a/internal/cache/diskcache_test.go +++ b/internal/cache/diskcache_test.go @@ -6,7 +6,6 @@ import ( "strings" "sync" "testing" - "time" promtest "github.com/prometheus/client_golang/prometheus/testutil" "github.com/stretchr/testify/require" @@ -26,7 +25,7 @@ func TestStreamDBNaiveKeyer(t *testing.T) { locator := config.NewLocator(cfg) - ctx, cancel := context.WithTimeout(context.Background(), time.Second) + ctx, cancel := context.WithCancel(context.Background()) defer cancel() ctx = testhelper.SetCtxGrpcMethod(ctx, "InfoRefsUploadPack") diff --git a/internal/cache/walker_test.go b/internal/cache/walker_test.go index 727e93d04..ca08001b4 100644 --- a/internal/cache/walker_test.go +++ b/internal/cache/walker_test.go @@ -55,7 +55,10 @@ func TestDiskCacheObjectWalker(t *testing.T) { require.NoError(t, cache.StartWalkers()) defer cache.StopWalkers() - pollCountersUntil(t, cache, 4) + require.Eventually(t, func() bool { + count := int(promtest.ToFloat64(cache.walkerRemovalTotal)) + return count == 4 + }, time.Minute, time.Millisecond) for _, p := range shouldExist { assert.FileExists(t, p) @@ -84,27 +87,6 @@ func TestDiskCacheInitialClear(t *testing.T) { require.NoFileExists(t, canary) } -func pollCountersUntil(t testing.TB, cache *DiskCache, expectRemovals int) { - // poll injected mock prometheus counters until expected events occur - timeout := time.After(time.Second) - for { - count := int(promtest.ToFloat64(cache.walkerRemovalTotal)) - select { - case <-timeout: - t.Fatalf( - "timed out polling prometheus stats; removals: %d", - count, - ) - default: - // keep on truckin' - } - if count == expectRemovals { - break - } - time.Sleep(time.Millisecond) - } -} - func TestCleanWalkDirNotExists(t *testing.T) { cfg := testcfg.Build(t) |