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 08:41:17 -06:00
committed by GitHub
parent a1dbd758bc
commit 81e2be69e9
21 changed files with 115 additions and 116 deletions
+4 -4
View File
@@ -745,13 +745,13 @@ func TestServer(t *testing.T) {
var (
expectAddr string
dials int64
dials atomic.Int64
)
client := codersdk.New(accessURL)
client.HTTPClient = &http.Client{
Transport: &http.Transport{
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
atomic.AddInt64(&dials, 1)
dials.Add(1)
assert.Equal(t, expectAddr, addr)
host, _, err := net.SplitHostPort(addr)
@@ -786,14 +786,14 @@ func TestServer(t *testing.T) {
expectAddr = "alpaca.com:443"
_, err := client.HasFirstUser(ctx)
require.NoError(t, err)
require.EqualValues(t, 1, atomic.LoadInt64(&dials))
require.EqualValues(t, 1, dials.Load())
// Use the second certificate (wildcard) and hostname.
client.URL.Host = "hi.llama.com:443"
expectAddr = "hi.llama.com:443"
_, err = client.HasFirstUser(ctx)
require.NoError(t, err)
require.EqualValues(t, 2, atomic.LoadInt64(&dials))
require.EqualValues(t, 2, dials.Load())
})
t.Run("TLSAndHTTP", func(t *testing.T) {