mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08: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:
@@ -32,9 +32,9 @@ func Test_ProxyServer_Headers(t *testing.T) {
|
||||
// We're not going to actually start a proxy, we're going to point it
|
||||
// towards a fake server that returns an unexpected status code. This'll
|
||||
// cause the proxy to exit with an error that we can check for.
|
||||
var called int64
|
||||
var called atomic.Int64
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
atomic.AddInt64(&called, 1)
|
||||
called.Add(1)
|
||||
assert.Equal(t, headerVal1, r.Header.Get(headerName1))
|
||||
assert.Equal(t, headerVal2, r.Header.Get(headerName2))
|
||||
|
||||
@@ -57,7 +57,7 @@ func Test_ProxyServer_Headers(t *testing.T) {
|
||||
require.ErrorContains(t, err, "unexpected status code 418")
|
||||
require.NoError(t, pty.Close())
|
||||
|
||||
assert.EqualValues(t, 1, atomic.LoadInt64(&called))
|
||||
assert.EqualValues(t, 1, called.Load())
|
||||
}
|
||||
|
||||
//nolint:paralleltest,tparallel // Test uses a static port.
|
||||
|
||||
Reference in New Issue
Block a user