test: use typed atomics in test files (#25071)

Use typed atomics (atomic.Int64, atomic.Int32, etc.) in test files to prevent
mixing atomic and non-atomic access on the same value, guarantee 64-bit
alignment on 32-bit platforms, and provide a cleaner API.
This commit is contained in:
Zach
2026-05-11 07:41:17 -07:00
committed by GitHub
parent a1dbd758bc
commit 81e2be69e9
21 changed files with 115 additions and 116 deletions
+3 -5
View File
@@ -264,14 +264,12 @@ func setupRunnerTest(t *testing.T) (client *codersdk.Client, agentID uuid.UUID)
func testServer(t *testing.T) (string, func() int64) {
t.Helper()
var count int64
var count atomic.Int64
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
atomic.AddInt64(&count, 1)
count.Add(1)
w.WriteHeader(http.StatusOK)
}))
t.Cleanup(srv.Close)
return srv.URL, func() int64 {
return atomic.LoadInt64(&count)
}
return srv.URL, count.Load
}