Skip to content

Commit efb9985

Browse files
kylecarbsammario
authored andcommitted
chore: Close idle connections on test cleanup
It's possible that this was the source of a leak on Windows...
1 parent 0d547df commit efb9985

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ test: test-clean
465465
test-postgres: test-clean test-postgres-docker
466466
DB=ci DB_FROM=$(shell go run scripts/migrate-ci/main.go) gotestsum --junitfile="gotests.xml" --packages="./..." -- \
467467
-covermode=atomic -coverprofile="gotests.coverage" -timeout=20m \
468+
-parallel=4 \
468469
-coverpkg=./... \
469470
-count=1 -race -failfast
470471
.PHONY: test-postgres

cli/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
566566
InsecureSkipVerify: true,
567567
},
568568
}
569+
defer client.HTTPClient.CloseIdleConnections()
569570
}
570571

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

cli/server_test.go

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,14 @@ func NewWithAPI(t *testing.T, options *Options) (*codersdk.Client, io.Closer, *c
298298
if options.IncludeProvisionerDaemon {
299299
provisionerCloser = NewProvisionerDaemon(t, coderAPI)
300300
}
301+
client := codersdk.New(coderAPI.AccessURL)
301302
t.Cleanup(func() {
302303
cancelFunc()
303304
_ = provisionerCloser.Close()
304305
_ = coderAPI.Close()
306+
client.HTTPClient.CloseIdleConnections()
305307
})
306-
return codersdk.New(coderAPI.AccessURL), provisionerCloser, coderAPI
308+
return client, provisionerCloser, coderAPI
307309
}
308310

309311
// NewProvisionerDaemon launches a provisionerd instance configured to work

coderd/workspaceapps_test.go

Lines changed: 9 additions & 0 deletions
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)