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:
@@ -536,7 +536,7 @@ func TestAgent(t *testing.T) {
|
||||
|
||||
t.Run("NotInfinite", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
var fetchCalled uint64
|
||||
var fetchCalled atomic.Uint64
|
||||
|
||||
cmd := &serpent.Command{
|
||||
Handler: func(inv *serpent.Invocation) error {
|
||||
@@ -544,7 +544,7 @@ func TestAgent(t *testing.T) {
|
||||
err := cliui.Agent(inv.Context(), &buf, uuid.Nil, cliui.AgentOptions{
|
||||
FetchInterval: 10 * time.Millisecond,
|
||||
Fetch: func(ctx context.Context, agentID uuid.UUID) (codersdk.WorkspaceAgent, error) {
|
||||
atomic.AddUint64(&fetchCalled, 1)
|
||||
fetchCalled.Add(1)
|
||||
|
||||
return codersdk.WorkspaceAgent{
|
||||
Status: codersdk.WorkspaceAgentConnected,
|
||||
@@ -557,7 +557,7 @@ func TestAgent(t *testing.T) {
|
||||
}
|
||||
|
||||
require.Never(t, func() bool {
|
||||
called := atomic.LoadUint64(&fetchCalled)
|
||||
called := fetchCalled.Load()
|
||||
return called > 5 || called == 0
|
||||
}, time.Second, 100*time.Millisecond)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user