mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
test(coderd): close metricscache and avoid background context (#7996)
This commit is contained in:
@@ -35,7 +35,7 @@ import (
|
||||
// New constructs an Enterprise coderd API instance.
|
||||
// This handler is designed to wrap the AGPL Coder code and
|
||||
// layer Enterprise functionality on top as much as possible.
|
||||
func New(ctx context.Context, options *Options) (*API, error) {
|
||||
func New(ctx context.Context, options *Options) (_ *API, err error) {
|
||||
if options.EntitlementsUpdateInterval == 0 {
|
||||
options.EntitlementsUpdateInterval = 10 * time.Minute
|
||||
}
|
||||
@@ -59,6 +59,11 @@ func New(ctx context.Context, options *Options) (*API, error) {
|
||||
AGPL: coderd.New(options.Options),
|
||||
Options: options,
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
_ = api.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
api.AGPL.Options.SetUserGroups = api.setUserGroups
|
||||
|
||||
@@ -312,8 +317,12 @@ type API struct {
|
||||
|
||||
func (api *API) Close() error {
|
||||
api.cancel()
|
||||
_ = api.replicaManager.Close()
|
||||
_ = api.derpMesh.Close()
|
||||
if api.replicaManager != nil {
|
||||
_ = api.replicaManager.Close()
|
||||
}
|
||||
if api.derpMesh != nil {
|
||||
_ = api.derpMesh.Close()
|
||||
}
|
||||
return api.AGPL.Close()
|
||||
}
|
||||
|
||||
@@ -410,6 +419,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {
|
||||
// is actually changing.
|
||||
changed = false
|
||||
} else {
|
||||
_ = coordinator.Close()
|
||||
coordinator = haCoordinator
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/coder/coder/coderd/coderdtest"
|
||||
@@ -58,6 +57,8 @@ func New(t *testing.T, options *Options) *codersdk.Client {
|
||||
}
|
||||
|
||||
func NewWithAPI(t *testing.T, options *Options) (*codersdk.Client, io.Closer, *coderd.API) {
|
||||
t.Helper()
|
||||
|
||||
if options == nil {
|
||||
options = &Options{}
|
||||
}
|
||||
@@ -77,7 +78,7 @@ func NewWithAPI(t *testing.T, options *Options) (*codersdk.Client, io.Closer, *c
|
||||
Keys: Keys,
|
||||
ProxyHealthInterval: options.ProxyHealthInterval,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
setHandler(coderAPI.AGPL.RootHandler)
|
||||
var provisionerCloser io.Closer = nopcloser{}
|
||||
if options.IncludeProvisionerDaemon {
|
||||
|
||||
Reference in New Issue
Block a user