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:
+6
-6
@@ -122,8 +122,8 @@ func TestWorkspaceAgent(t *testing.T) {
|
||||
var (
|
||||
admin = coderdtest.CreateFirstUser(t, client)
|
||||
member, memberUser = coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
|
||||
called int64
|
||||
derpCalled int64
|
||||
called atomic.Int64
|
||||
derpCalled atomic.Int64
|
||||
)
|
||||
|
||||
setHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -133,9 +133,9 @@ func TestWorkspaceAgent(t *testing.T) {
|
||||
assert.Equal(t, "very-wow-"+client.URL.String(), r.Header.Get("X-Process-Testing"))
|
||||
assert.Equal(t, "more-wow", r.Header.Get("X-Process-Testing2"))
|
||||
if strings.HasPrefix(r.URL.Path, "/derp") {
|
||||
atomic.AddInt64(&derpCalled, 1)
|
||||
derpCalled.Add(1)
|
||||
} else {
|
||||
atomic.AddInt64(&called, 1)
|
||||
called.Add(1)
|
||||
}
|
||||
}
|
||||
coderAPI.RootHandler.ServeHTTP(w, r)
|
||||
@@ -178,8 +178,8 @@ func TestWorkspaceAgent(t *testing.T) {
|
||||
err := clientInv.WithContext(ctx).Run()
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Greater(t, atomic.LoadInt64(&called), int64(0), "expected coderd to be reached with custom headers")
|
||||
require.Greater(t, atomic.LoadInt64(&derpCalled), int64(0), "expected /derp to be called with custom headers")
|
||||
require.Greater(t, called.Load(), int64(0), "expected coderd to be reached with custom headers")
|
||||
require.Greater(t, derpCalled.Load(), int64(0), "expected /derp to be called with custom headers")
|
||||
})
|
||||
|
||||
t.Run("DisabledServers", func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user