Skip to content

Commit 6e7175b

Browse files
authored
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
1 parent d1b1122 commit 6e7175b

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

cli/clitest/clitest.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ func Start(t *testing.T, inv *clibase.Invocation) {
137137
// before ours.
138138
waiter := StartWithWaiter(t, inv)
139139
t.Cleanup(func() {
140+
waiter.Cancel()
140141
<-closeCh
141142
})
142143

@@ -163,11 +164,16 @@ func Run(t *testing.T, inv *clibase.Invocation) {
163164
type ErrorWaiter struct {
164165
waitOnce sync.Once
165166
cachedError error
167+
cancelFunc context.CancelFunc
166168

167169
c <-chan error
168170
t *testing.T
169171
}
170172

173+
func (w *ErrorWaiter) Cancel() {
174+
w.cancelFunc()
175+
}
176+
171177
func (w *ErrorWaiter) Wait() error {
172178
w.waitOnce.Do(func() {
173179
var ok bool
@@ -241,5 +247,5 @@ func StartWithWaiter(t *testing.T, inv *clibase.Invocation) *ErrorWaiter {
241247
cleaningUp.Store(true)
242248
<-doneCh
243249
})
244-
return &ErrorWaiter{c: errCh, t: t}
250+
return &ErrorWaiter{c: errCh, t: t, cancelFunc: cancel}
245251
}

cli/gitssh_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ func prepareTestGitSSH(ctx context.Context, t *testing.T) (*codersdk.Client, str
5858

5959
// start workspace agent
6060
inv, root := clitest.New(t, "agent", "--agent-token", agentToken, "--agent-url", client.URL.String())
61-
agentClient := client
61+
agentClient := codersdk.New(client.URL)
62+
agentClient.SetSessionToken(agentToken)
6263
clitest.SetupConfig(t, agentClient, root)
63-
6464
clitest.Start(t, inv)
6565

6666
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)

cli/server_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ func TestServer(t *testing.T) {
121121
)
122122

123123
const superDuperLong = testutil.WaitSuperLong * 3
124-
125124
ctx := testutil.Context(t, superDuperLong)
126125
clitest.Start(t, inv.WithContext(ctx))
127126

@@ -1430,6 +1429,7 @@ func TestServer(t *testing.T) {
14301429
wantConfig.Options[i].Name,
14311430
)
14321431
}
1432+
w.Cancel()
14331433
w.RequireSuccess()
14341434
})
14351435
})
@@ -1460,8 +1460,8 @@ func TestServer(t *testing.T) {
14601460
})
14611461
}
14621462

1463-
//nolint:tparallel,paralleltest // This test spawns or connects to an existing PostgreSQL instance.
14641463
func TestServer_Production(t *testing.T) {
1464+
t.Parallel()
14651465
if runtime.GOOS != "linux" || testing.Short() {
14661466
// Skip on non-Linux because it spawns a PostgreSQL instance.
14671467
t.SkipNow()
@@ -1471,7 +1471,8 @@ func TestServer_Production(t *testing.T) {
14711471
defer closeFunc()
14721472

14731473
// Postgres + race detector + CI = slow.
1474-
ctx := testutil.Context(t, testutil.WaitSuperLong*3)
1474+
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitSuperLong*3)
1475+
defer cancelFunc()
14751476

14761477
inv, cfg := clitest.New(t,
14771478
"server",

cli/vscodessh_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func TestVSCodeSSH(t *testing.T) {
6868
}
6969
return len(entries) > 0
7070
}, testutil.WaitLong, testutil.IntervalFast)
71+
waiter.Cancel()
7172

7273
if err := waiter.Wait(); err != nil {
7374
waiter.RequireIs(context.Canceled)

enterprise/coderd/workspaceproxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
// forceWorkspaceProxyHealthUpdate forces an update of the proxy health.
3232
// This is useful when a proxy is created or deleted. Errors will be logged.
3333
func (api *API) forceWorkspaceProxyHealthUpdate(ctx context.Context) {
34-
if err := api.ProxyHealth.ForceUpdate(ctx); err != nil {
34+
if err := api.ProxyHealth.ForceUpdate(ctx); err != nil && !xerrors.Is(err, context.Canceled) {
3535
api.Logger.Error(ctx, "force proxy health update", slog.Error(err))
3636
}
3737
}

0 commit comments

Comments
 (0)