mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-11-27 18:45:04 -05:00
test(webdav): fix a data race in the thumbnail cache test
The test "should use atomic write via temp file + rename" set sawTempFile in a watcher goroutine and read it after close(done), without waiting for the goroutine to stop, so the race detector failed TestCache. Make sawTempFile an atomic.Bool and wait for the watcher to return before reading it. Fixes #4010 Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
1 parent
2ff7018524
commit
41196f511e
1 file changed
+7
-3
+7
-3
@@ -9,6 +9,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
@@ -495,8 +496,10 @@ var _ = Describe("FileCache", func() {
|
||||
Expect(os.MkdirAll(watchDir, 0700)).To(Succeed())
|
||||
|
||||
done := make(chan struct{})
|
||||
sawTempFile := false
|
||||
watcherStopped := make(chan struct{})
|
||||
var sawTempFile atomic.Bool
|
||||
go func() {
|
||||
defer close(watcherStopped)
|
||||
for {
|
||||
select {
|
||||
case <-done:
|
||||
@@ -505,7 +508,7 @@ var _ = Describe("FileCache", func() {
|
||||
entries, _ := os.ReadDir(watchDir)
|
||||
for _, e := range entries {
|
||||
if strings.HasPrefix(e.Name(), "tmpthumb") {
|
||||
sawTempFile = true
|
||||
sawTempFile.Store(true)
|
||||
}
|
||||
}
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
@@ -517,11 +520,12 @@ var _ = Describe("FileCache", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
close(done)
|
||||
<-watcherStopped
|
||||
|
||||
data, err := cache.Get(key)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(len(data)).To(Equal(1024 * 1024))
|
||||
_ = sawTempFile
|
||||
_ = sawTempFile.Load()
|
||||
})
|
||||
|
||||
It("should handle disk write error gracefully", func() {
|
||||
|
||||
Reference in new issue
Block a user