Skip to content

Commit ccea407

Browse files
committed
test(coderd): Close metricscache and avoid background context
1 parent c916a9e commit ccea407

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

coderd/coderdtest/coderdtest.go

+4
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ func newWithCloser(t testing.TB, options *Options) (*codersdk.Client, io.Closer)
169169
}
170170

171171
func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.CancelFunc, *url.URL, *coderd.Options) {
172+
t.Helper()
173+
172174
if options == nil {
173175
options = &Options{}
174176
}
@@ -402,6 +404,8 @@ func NewWithAPI(t testing.TB, options *Options) (*codersdk.Client, io.Closer, *c
402404
// well with coderd testing. It registers the "echo" provisioner for
403405
// quick testing.
404406
func NewProvisionerDaemon(t testing.TB, coderAPI *coderd.API) io.Closer {
407+
t.Helper()
408+
405409
echoClient, echoServer := provisionersdk.MemTransportPipe()
406410
ctx, cancelFunc := context.WithCancel(context.Background())
407411
t.Cleanup(func() {

coderd/metricscache/metricscache_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ func TestCache_DeploymentStats(t *testing.T) {
435435
cache := metricscache.New(db, slogtest.Make(t, nil), metricscache.Intervals{
436436
DeploymentStats: testutil.IntervalFast,
437437
})
438+
defer cache.Close()
438439

439440
_, err := db.InsertWorkspaceAgentStat(context.Background(), database.InsertWorkspaceAgentStatParams{
440441
ID: uuid.New(),

coderd/workspaceapps/apptest/setup.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ func createWorkspaceWithApps(t *testing.T, client *codersdk.Client, orgID uuid.U
347347
primaryAppHost, err := client.AppHost(appHostCtx)
348348
require.NoError(t, err)
349349
if primaryAppHost.Host != "" {
350-
manifest, err := agentClient.Manifest(context.Background())
350+
manifest, err := agentClient.Manifest(appHostCtx)
351351
require.NoError(t, err)
352352
proxyURL := fmt.Sprintf(
353353
"http://{{port}}--%s--%s--%s%s",

enterprise/coderd/coderdenttest/coderdenttest.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
"github.com/golang-jwt/jwt/v4"
1414
"github.com/google/uuid"
15-
"github.com/stretchr/testify/assert"
1615
"github.com/stretchr/testify/require"
1716

1817
"github.com/coder/coder/coderd/coderdtest"
@@ -58,6 +57,8 @@ func New(t *testing.T, options *Options) *codersdk.Client {
5857
}
5958

6059
func NewWithAPI(t *testing.T, options *Options) (*codersdk.Client, io.Closer, *coderd.API) {
60+
t.Helper()
61+
6162
if options == nil {
6263
options = &Options{}
6364
}
@@ -77,7 +78,7 @@ func NewWithAPI(t *testing.T, options *Options) (*codersdk.Client, io.Closer, *c
7778
Keys: Keys,
7879
ProxyHealthInterval: options.ProxyHealthInterval,
7980
})
80-
assert.NoError(t, err)
81+
require.NoError(t, err)
8182
setHandler(coderAPI.AGPL.RootHandler)
8283
var provisionerCloser io.Closer = nopcloser{}
8384
if options.IncludeProvisionerDaemon {

0 commit comments

Comments
 (0)