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:
@@ -24,7 +24,7 @@ type noopTracer = noop.Tracer
|
||||
type fakeTracer struct {
|
||||
noop.TracerProvider
|
||||
noopTracer
|
||||
startCalled int64
|
||||
startCalled atomic.Int64
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -39,7 +39,7 @@ func (f *fakeTracer) Tracer(_ string, _ ...trace.TracerOption) trace.Tracer {
|
||||
|
||||
// Start implements trace.Tracer.
|
||||
func (f *fakeTracer) Start(ctx context.Context, _ string, _ ...trace.SpanStartOption) (context.Context, trace.Span) {
|
||||
atomic.AddInt64(&f.startCalled, 1)
|
||||
f.startCalled.Add(1)
|
||||
return ctx, tracing.NoopSpan
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ func Test_Middleware(t *testing.T) {
|
||||
rw.WriteHeader(http.StatusNoContent)
|
||||
})).ServeHTTP(rw, r)
|
||||
|
||||
didRun := atomic.LoadInt64(&fake.startCalled) == 1
|
||||
didRun := fake.startCalled.Load() == 1
|
||||
require.Equal(t, c.runs, didRun, "expected middleware to run/not run")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user