Skip to content

Commit acece7f

Browse files
SimplyLizclaude
andcommitted
fix(test): mutex-protect request recorder in outgoing impact fake
The test fake daemon recorded incoming requests via a goroutine appending to a shared []map[string]any while the test main goroutine read it through the snap() closure. Race detector caught this on CI (TestAnalyzeOutgoingImpact_HappyPath). Wrap append and read with sync.Mutex; snap() takes the lock around its copy. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent f63ed9a commit acece7f

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

internal/query/impact_outgoing_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"path/filepath"
1111
"strings"
12+
"sync"
1213
"testing"
1314
"time"
1415

@@ -35,13 +36,18 @@ func startOutgoingImpactDaemon(t *testing.T, payload map[string]any) func() []ma
3536
prev := os.Getenv("LIP_SOCKET")
3637
os.Setenv("LIP_SOCKET", sockPath)
3738

38-
var reqs []map[string]any
39+
var (
40+
reqsMu sync.Mutex
41+
reqs []map[string]any
42+
)
3943
reqC := make(chan map[string]any, 16)
4044
done := make(chan struct{})
4145
go func() {
4246
defer close(done)
4347
for r := range reqC {
48+
reqsMu.Lock()
4449
reqs = append(reqs, r)
50+
reqsMu.Unlock()
4551
}
4652
}()
4753

@@ -88,6 +94,8 @@ func startOutgoingImpactDaemon(t *testing.T, payload map[string]any) func() []ma
8894
os.Setenv("LIP_SOCKET", prev)
8995
})
9096
return func() []map[string]any {
97+
reqsMu.Lock()
98+
defer reqsMu.Unlock()
9199
out := make([]map[string]any, len(reqs))
92100
copy(out, reqs)
93101
return out

0 commit comments

Comments
 (0)