Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

vfs: fix race in cache tests

Nick Craig-Wood9b800d7184a4
diff --git a/vfs/cache_test.go b/vfs/cache_test.go
index 6ef959862..bda264ab4 100644
--- a/vfs/cache_test.go
+++ b/vfs/cache_test.go
@@ -133,14 +133,18 @@ name="potato" isFile=true opens=1`, itemAsString(c))
// updateAtimes - not in the cache
oldItem := item
+ c.itemMu.Lock()
delete(c.item, "potato") // remove from cache
+ c.itemMu.Unlock()
err = c.updateAtimes()
require.NoError(t, err)
assert.Equal(t, `name="" isFile=false opens=1
name="potato" isFile=true opens=0`, itemAsString(c))
item = c.get("potato")
assert.Equal(t, atime, item.atime)
+ c.itemMu.Lock()
c.item["potato"] = oldItem // restore to cache
+ c.itemMu.Unlock()
// try purging with file open
c.purgeOld(10 * time.Second)