Skip to content

Commit 49c7648

Browse files
authored
chore: Close idle connections on test cleanup (#4993)
It's possible that this was the source of a leak on Windows...
1 parent 30e9ecb commit 49c7648

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

cli/server.go

+1
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
568568
InsecureSkipVerify: true,
569569
},
570570
}
571+
defer client.HTTPClient.CloseIdleConnections()
571572
}
572573

573574
// Since errCh only has one buffered slot, all routines

cli/server_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ func TestServer(t *testing.T) {
425425
},
426426
},
427427
}
428+
defer client.HTTPClient.CloseIdleConnections()
428429

429430
// Use the first certificate and hostname.
430431
client.URL.Host = "alpaca.com:443"

coderd/coderdtest/coderdtest.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,14 @@ func NewWithAPI(t *testing.T, options *Options) (*codersdk.Client, io.Closer, *c
299299
if options.IncludeProvisionerDaemon {
300300
provisionerCloser = NewProvisionerDaemon(t, coderAPI)
301301
}
302+
client := codersdk.New(coderAPI.AccessURL)
302303
t.Cleanup(func() {
303304
cancelFunc()
304305
_ = provisionerCloser.Close()
305306
_ = coderAPI.Close()
307+
client.HTTPClient.CloseIdleConnections()
306308
})
307-
return codersdk.New(coderAPI.AccessURL), provisionerCloser, coderAPI
309+
return client, provisionerCloser, coderAPI
308310
}
309311

310312
// NewProvisionerDaemon launches a provisionerd instance configured to work

coderd/workspaceapps_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ func setupProxyTest(t *testing.T, customAppHost ...string) (*codersdk.Client, co
135135
return (&net.Dialer{}).DialContext(ctx, network, client.URL.Host)
136136
}
137137
client.HTTPClient.Transport = transport
138+
t.Cleanup(func() {
139+
transport.CloseIdleConnections()
140+
})
138141

139142
return client, user, workspace, uint16(tcpAddr.Port)
140143
}
@@ -540,6 +543,9 @@ func TestWorkspaceAppsProxySubdomainPassthrough(t *testing.T) {
540543
return (&net.Dialer{}).DialContext(ctx, network, client.URL.Host)
541544
}
542545
client.HTTPClient.Transport = transport
546+
t.Cleanup(func() {
547+
transport.CloseIdleConnections()
548+
})
543549

544550
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
545551
defer cancel()
@@ -579,6 +585,9 @@ func TestWorkspaceAppsProxySubdomainBlocked(t *testing.T) {
579585
return (&net.Dialer{}).DialContext(ctx, network, client.URL.Host)
580586
}
581587
client.HTTPClient.Transport = transport
588+
t.Cleanup(func() {
589+
transport.CloseIdleConnections()
590+
})
582591

583592
return client
584593
}

0 commit comments

Comments
 (0)