sessions: TestManageReadsOnlyTheAgentsItShows counts parses without a data race
Its parseHook did parsed++ while refresh's readers called it from several
goroutines at once, so `go test -race ./internal/sessions/` was red on
origin/main a9304efe0 (3 of 3 runs: "race detected during execution of
test", manage_read_test.go:30 written by two refresh workers). The count is
an atomic.Int64 now. Its sibling in hermes_fingerprint_test.go refreshes one
file, so one reader, and is left as it is.
Run: go test -race -count=20 -run TestManageReadsOnlyTheAgentsItShows
./internal/sessions/ ok; go test -race ./internal/sessions/ ok (44.5s), in
a sandbox HOME with Go's caches pinned.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -26,13 +27,14 @@ func TestManageReadsOnlyTheAgentsItShows(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
parsed := 0
|
||||
parseHook = func() { parsed++ }
|
||||
// refresh's readers each call it, at once
|
||||
var parsed atomic.Int64
|
||||
parseHook = func() { parsed.Add(1) }
|
||||
t.Cleanup(func() { parseHook = nil })
|
||||
|
||||
v := Manage(map[string]bool{}, claude)
|
||||
if parsed != 0 {
|
||||
t.Fatalf("Codex's files changed and Claude Code's page read %d of them", parsed)
|
||||
if n := parsed.Load(); n != 0 {
|
||||
t.Fatalf("Codex's files changed and Claude Code's page read %d of them", n)
|
||||
}
|
||||
if v.Agent != "claude" || len(v.Sessions) == 0 {
|
||||
t.Fatalf("listed %q with %d sessions", v.Agent, len(v.Sessions))
|
||||
@@ -47,7 +49,7 @@ func TestManageReadsOnlyTheAgentsItShows(t *testing.T) {
|
||||
|
||||
// asked for Codex's ids: its changed files are read, as the id is in them
|
||||
v = Manage(map[string]bool{"codex": true, "claude": true}, claude)
|
||||
if parsed == 0 {
|
||||
if parsed.Load() == 0 {
|
||||
t.Fatal("Codex's ids were asked for and its changed files not read")
|
||||
}
|
||||
if !v.Native["codex"]["01a0bdc9-b5fd-7e63-9658-68bc8dce5ecd"] {
|
||||
|
||||
Reference in New Issue
Block a user