mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user