Files
ai/controllers/file_cache_race_test.go
zeekayandHanzo Dev 0c08bd1d94 Go 1.27.1, and the code it can say more simply
Modules declare go 1.27.1 and the build images follow. go fix applied the
modernizers; omitzero is not applied, since it changes what the JSON says.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-17 01:01:10 -07:00

35 lines
889 B
Go

// Copyright 2026 Hanzo AI Inc. All Rights Reserved.
package controllers
import (
"fmt"
"sync"
"testing"
)
// Both surfaces share the file cache, so concurrent readers and writers are the
// ordinary case. This holds the map's guard honest: a Go map without one is a
// runtime fatal error under concurrency, which no recover() can answer for.
func TestTheFileCacheIsReachedFromBothDoorsAtOnce(t *testing.T) {
var wg sync.WaitGroup
for i := range 64 {
wg.Add(1)
go func(i int) {
defer wg.Done()
prefix := fmt.Sprintf("prefix-%d", i%8)
rememberPath(prefix, fmt.Sprintf("/cache/%d", i))
if _, ok := cachedPath(prefix); !ok {
t.Errorf("%s was remembered and then not found", prefix)
}
}(i)
}
wg.Wait()
for i := range 8 {
if _, ok := cachedPath(fmt.Sprintf("prefix-%d", i)); !ok {
t.Errorf("prefix-%d is missing after the writes settled", i)
}
}
}