Skip to content

Commit 1fa151c

Browse files
committed
fix: Run ctx cancel first in t.Cleanup
1 parent 648b7eb commit 1fa151c

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

coderd/coderd_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func TestAuthorizeAllEndpoints(t *testing.T) {
9494
t.Cleanup(func() { close(tickerCh) })
9595

9696
ctx, cancelFunc := context.WithCancel(context.Background())
97-
t.Cleanup(cancelFunc)
97+
defer t.Cleanup(cancelFunc) // Defer to ensure cancelFunc is executed first.
9898

9999
lifecycleExecutor := executor.New(
100100
ctx,

coderd/coderdtest/coderdtest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func newWithCloser(t *testing.T, options *Options) (*codersdk.Client, io.Closer)
143143
}
144144

145145
ctx, cancelFunc := context.WithCancel(context.Background())
146-
t.Cleanup(cancelFunc)
146+
defer t.Cleanup(cancelFunc) // Defer to ensure cancelFunc is executed first.
147147

148148
lifecycleExecutor := executor.New(
149149
ctx,

0 commit comments

Comments
 (0)