Skip to content

Commit 7b6fe85

Browse files
committed
Fix context passing
1 parent b8776cb commit 7b6fe85

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

coderd/coderdtest/coderdtest.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func newWithCloser(t *testing.T, options *Options) (*codersdk.Client, io.Closer)
115115
return client, closer
116116
}
117117

118-
func NewOptions(t *testing.T, options *Options) (*httptest.Server, *coderd.Options) {
118+
func NewOptions(t *testing.T, options *Options) (*httptest.Server, context.CancelFunc, *coderd.Options) {
119119
if options == nil {
120120
options = &Options{}
121121
}
@@ -194,7 +194,7 @@ func NewOptions(t *testing.T, options *Options) (*httptest.Server, *coderd.Optio
194194
options.SSHKeygenAlgorithm = gitsshkey.AlgorithmEd25519
195195
}
196196

197-
return srv, &coderd.Options{
197+
return srv, cancelFunc, &coderd.Options{
198198
AgentConnectionUpdateFrequency: 150 * time.Millisecond,
199199
// Force a long disconnection timeout to ensure
200200
// agents are not marked as disconnected during slow tests.
@@ -246,10 +246,11 @@ func NewWithAPI(t *testing.T, options *Options) (*codersdk.Client, io.Closer, *c
246246
if options == nil {
247247
options = &Options{}
248248
}
249-
srv, newOptions := NewOptions(t, options)
249+
srv, cancelFunc, newOptions := NewOptions(t, options)
250250
// We set the handler after server creation for the access URL.
251251
coderAPI := coderd.New(newOptions)
252252
t.Cleanup(func() {
253+
cancelFunc()
253254
_ = coderAPI.Close()
254255
})
255256
srv.Config.Handler = coderAPI.RootHandler

enterprise/coderd/coderdenttest/coderdenttest.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func NewWithAPI(t *testing.T, options *Options) (*codersdk.Client, io.Closer, *c
5252
if options.Options == nil {
5353
options.Options = &coderdtest.Options{}
5454
}
55-
srv, oop := coderdtest.NewOptions(t, options.Options)
55+
srv, cancelFunc, oop := coderdtest.NewOptions(t, options.Options)
5656
coderAPI, err := coderd.New(context.Background(), &coderd.Options{
5757
AuditLogging: true,
5858
Options: oop,
@@ -68,6 +68,7 @@ func NewWithAPI(t *testing.T, options *Options) (*codersdk.Client, io.Closer, *c
6868
provisionerCloser = coderdtest.NewProvisionerDaemon(t, coderAPI.AGPL)
6969
}
7070
t.Cleanup(func() {
71+
cancelFunc()
7172
_ = provisionerCloser.Close()
7273
_ = coderAPI.Close()
7374
})

0 commit comments

Comments
 (0)