diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-04-28 13:16:19 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-04-28 13:25:48 +0300 |
commit | 5c596203a72da85c68221c13ab475f27190d66c5 (patch) | |
tree | dcc74b6a51724fe4bf8790488016bb0ab78ef13a | |
parent | 1a48596f6e7257035d854dcfa9e5cc6c55c656ce (diff) |
cache: Fix flaky cache walker test
One of our disk cache walker tests is currently flaky, where it'll try
to write a file into a directory which it has just created, but that
directory has already been removed. This raciness has been introduced
with the introduction of the testcfg builder, which kicks off the walker
via registered config hooks when building the Gitaly config. As a
result, the cache walker is already running concurrently when we're
creating the directory hierarchy, which causes a race between us writing
the file and the walker deleting the directory we just created.
The test has already been aware of this race, which is why the automatic
walker had been disabled. But given that the testcfg already kicks off
the walker, we now need to do this earlier. The fix is thus easy enough:
we just need to move disabling the walker before construction of the
Gitaly configuration.
-rw-r--r-- | internal/cache/walker_test.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/internal/cache/walker_test.go b/internal/cache/walker_test.go index 1c7139ba0..3af0f7c67 100644 --- a/internal/cache/walker_test.go +++ b/internal/cache/walker_test.go @@ -70,6 +70,11 @@ func TestDiskCacheObjectWalker(t *testing.T) { } func TestDiskCacheInitialClear(t *testing.T) { + // disable the background walkers since we are only + // evaluating the initial move-and-clear function + *cache.ExportDisableWalker = true + defer func() { *cache.ExportDisableWalker = false }() + cfg := testcfg.Build(t) cacheDir := tempdir.CacheDir(cfg.Storages[0]) @@ -78,11 +83,6 @@ func TestDiskCacheInitialClear(t *testing.T) { require.NoError(t, os.MkdirAll(filepath.Dir(canary), 0755)) require.NoError(t, ioutil.WriteFile(canary, []byte("chirp chirp"), 0755)) - // disable the background walkers since we are only - // evaluating the initial move-and-clear function - *cache.ExportDisableWalker = true - defer func() { *cache.ExportDisableWalker = false }() - // validation will run cache walker hook which synchronously // runs the move-and-clear function require.NoError(t, cfg.Validate()) |