mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
chore: fix lengthy tests in psql (#7545)
* chore: fix lengthy tests in psql This was adding at a minimum 3mins to our psql tests! * fix: automatically cancel tests on cleanup
This commit is contained in:
@ -137,6 +137,7 @@ func Start(t *testing.T, inv *clibase.Invocation) {
|
|||||||
// before ours.
|
// before ours.
|
||||||
waiter := StartWithWaiter(t, inv)
|
waiter := StartWithWaiter(t, inv)
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
|
waiter.Cancel()
|
||||||
<-closeCh
|
<-closeCh
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -163,11 +164,16 @@ func Run(t *testing.T, inv *clibase.Invocation) {
|
|||||||
type ErrorWaiter struct {
|
type ErrorWaiter struct {
|
||||||
waitOnce sync.Once
|
waitOnce sync.Once
|
||||||
cachedError error
|
cachedError error
|
||||||
|
cancelFunc context.CancelFunc
|
||||||
|
|
||||||
c <-chan error
|
c <-chan error
|
||||||
t *testing.T
|
t *testing.T
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *ErrorWaiter) Cancel() {
|
||||||
|
w.cancelFunc()
|
||||||
|
}
|
||||||
|
|
||||||
func (w *ErrorWaiter) Wait() error {
|
func (w *ErrorWaiter) Wait() error {
|
||||||
w.waitOnce.Do(func() {
|
w.waitOnce.Do(func() {
|
||||||
var ok bool
|
var ok bool
|
||||||
@ -241,5 +247,5 @@ func StartWithWaiter(t *testing.T, inv *clibase.Invocation) *ErrorWaiter {
|
|||||||
cleaningUp.Store(true)
|
cleaningUp.Store(true)
|
||||||
<-doneCh
|
<-doneCh
|
||||||
})
|
})
|
||||||
return &ErrorWaiter{c: errCh, t: t}
|
return &ErrorWaiter{c: errCh, t: t, cancelFunc: cancel}
|
||||||
}
|
}
|
||||||
|
@ -58,9 +58,9 @@ func prepareTestGitSSH(ctx context.Context, t *testing.T) (*codersdk.Client, str
|
|||||||
|
|
||||||
// start workspace agent
|
// start workspace agent
|
||||||
inv, root := clitest.New(t, "agent", "--agent-token", agentToken, "--agent-url", client.URL.String())
|
inv, root := clitest.New(t, "agent", "--agent-token", agentToken, "--agent-url", client.URL.String())
|
||||||
agentClient := client
|
agentClient := codersdk.New(client.URL)
|
||||||
|
agentClient.SetSessionToken(agentToken)
|
||||||
clitest.SetupConfig(t, agentClient, root)
|
clitest.SetupConfig(t, agentClient, root)
|
||||||
|
|
||||||
clitest.Start(t, inv)
|
clitest.Start(t, inv)
|
||||||
|
|
||||||
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
|
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
|
||||||
|
@ -121,7 +121,6 @@ func TestServer(t *testing.T) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const superDuperLong = testutil.WaitSuperLong * 3
|
const superDuperLong = testutil.WaitSuperLong * 3
|
||||||
|
|
||||||
ctx := testutil.Context(t, superDuperLong)
|
ctx := testutil.Context(t, superDuperLong)
|
||||||
clitest.Start(t, inv.WithContext(ctx))
|
clitest.Start(t, inv.WithContext(ctx))
|
||||||
|
|
||||||
@ -1430,6 +1429,7 @@ func TestServer(t *testing.T) {
|
|||||||
wantConfig.Options[i].Name,
|
wantConfig.Options[i].Name,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
w.Cancel()
|
||||||
w.RequireSuccess()
|
w.RequireSuccess()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -1460,8 +1460,8 @@ func TestServer(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:tparallel,paralleltest // This test spawns or connects to an existing PostgreSQL instance.
|
|
||||||
func TestServer_Production(t *testing.T) {
|
func TestServer_Production(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
if runtime.GOOS != "linux" || testing.Short() {
|
if runtime.GOOS != "linux" || testing.Short() {
|
||||||
// Skip on non-Linux because it spawns a PostgreSQL instance.
|
// Skip on non-Linux because it spawns a PostgreSQL instance.
|
||||||
t.SkipNow()
|
t.SkipNow()
|
||||||
@ -1471,7 +1471,8 @@ func TestServer_Production(t *testing.T) {
|
|||||||
defer closeFunc()
|
defer closeFunc()
|
||||||
|
|
||||||
// Postgres + race detector + CI = slow.
|
// Postgres + race detector + CI = slow.
|
||||||
ctx := testutil.Context(t, testutil.WaitSuperLong*3)
|
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitSuperLong*3)
|
||||||
|
defer cancelFunc()
|
||||||
|
|
||||||
inv, cfg := clitest.New(t,
|
inv, cfg := clitest.New(t,
|
||||||
"server",
|
"server",
|
||||||
|
@ -68,6 +68,7 @@ func TestVSCodeSSH(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return len(entries) > 0
|
return len(entries) > 0
|
||||||
}, testutil.WaitLong, testutil.IntervalFast)
|
}, testutil.WaitLong, testutil.IntervalFast)
|
||||||
|
waiter.Cancel()
|
||||||
|
|
||||||
if err := waiter.Wait(); err != nil {
|
if err := waiter.Wait(); err != nil {
|
||||||
waiter.RequireIs(context.Canceled)
|
waiter.RequireIs(context.Canceled)
|
||||||
|
@ -31,7 +31,7 @@ import (
|
|||||||
// forceWorkspaceProxyHealthUpdate forces an update of the proxy health.
|
// forceWorkspaceProxyHealthUpdate forces an update of the proxy health.
|
||||||
// This is useful when a proxy is created or deleted. Errors will be logged.
|
// This is useful when a proxy is created or deleted. Errors will be logged.
|
||||||
func (api *API) forceWorkspaceProxyHealthUpdate(ctx context.Context) {
|
func (api *API) forceWorkspaceProxyHealthUpdate(ctx context.Context) {
|
||||||
if err := api.ProxyHealth.ForceUpdate(ctx); err != nil {
|
if err := api.ProxyHealth.ForceUpdate(ctx); err != nil && !xerrors.Is(err, context.Canceled) {
|
||||||
api.Logger.Error(ctx, "force proxy health update", slog.Error(err))
|
api.Logger.Error(ctx, "force proxy health update", slog.Error(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user