mirror of
https://github.com/coder/coder.git
synced 2026-09-21 20:51:01 +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:
@@ -311,7 +311,7 @@ func TestUpdateLifecycle(t *testing.T) {
|
||||
|
||||
dbM := dbmock.NewMockStore(gomock.NewController(t))
|
||||
|
||||
var publishCalled int64
|
||||
var publishCalled atomic.Int64
|
||||
reg := prometheus.NewRegistry()
|
||||
metrics := agentapi.NewLifecycleMetrics(reg)
|
||||
|
||||
@@ -324,7 +324,7 @@ func TestUpdateLifecycle(t *testing.T) {
|
||||
Log: testutil.Logger(t),
|
||||
Metrics: metrics,
|
||||
PublishWorkspaceUpdateFn: func(ctx context.Context, _ uuid.UUID, kind wspubsub.WorkspaceEventKind) error {
|
||||
atomic.AddInt64(&publishCalled, 1)
|
||||
publishCalled.Add(1)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@@ -384,7 +384,7 @@ func TestUpdateLifecycle(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, lifecycle, resp)
|
||||
require.Equal(t, int64(i+1), atomic.LoadInt64(&publishCalled))
|
||||
require.Equal(t, int64(i+1), publishCalled.Load())
|
||||
|
||||
// For future iterations:
|
||||
agent.StartedAt = expectedStartedAt
|
||||
|
||||
Reference in New Issue
Block a user