Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7cc8a74

Browse files
committed
test: fix TestServer cases that cancel before PostgreSQL work is done
1 parent6238937 commit7cc8a74

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

‎cli/server_test.go‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import (
5656
"github.com/coder/coder/v2/pty/ptytest"
5757
"github.com/coder/coder/v2/tailnet/tailnettest"
5858
"github.com/coder/coder/v2/testutil"
59+
"github.com/coder/serpent"
5960
)
6061

6162
funcdbArg(t*testing.T)string {
@@ -1015,7 +1016,9 @@ func TestServer(t *testing.T) {
10151016
)
10161017

10171018
pty:=ptytest.New(t).Attach(inv)
1018-
clitest.Start(t,inv)
1019+
// Since we end the test after seeing the log lines about the HTTP listener, we could cancel the test before
1020+
// our initial interactions with PostgreSQL are complete. So, ignore errors of that type for this test.
1021+
startIgnoringPostgresQueryCancel(t,inv)
10191022

10201023
pty.ExpectMatch("Started HTTP listener")
10211024
pty.ExpectMatch("http://0.0.0.0:")
@@ -1032,7 +1035,9 @@ func TestServer(t *testing.T) {
10321035
)
10331036

10341037
pty:=ptytest.New(t).Attach(inv)
1035-
clitest.Start(t,inv)
1038+
// Since we end the test after seeing the log lines about the HTTP listener, we could cancel the test before
1039+
// our initial interactions with PostgreSQL are complete. So, ignore errors of that type for this test.
1040+
startIgnoringPostgresQueryCancel(t,inv)
10361041

10371042
pty.ExpectMatch("Started HTTP listener at")
10381043
pty.ExpectMatch("http://[::]:")
@@ -1157,7 +1162,10 @@ func TestServer(t *testing.T) {
11571162
)
11581163
ctx,cancel:=context.WithCancel(context.Background())
11591164
defercancel()
1160-
clitest.Start(t,inv.WithContext(ctx))
1165+
// Since we cancel the context before our initial interactions with PostgreSQL are complete, we need to ignore
1166+
// errors about queries being cancelled.
1167+
startIgnoringPostgresQueryCancel(t,inv.WithContext(ctx))
1168+
11611169
cancel()
11621170
require.Error(t,goleak.Find())
11631171
})
@@ -2370,3 +2378,16 @@ func mockTelemetryServer(t *testing.T) (*url.URL, chan *telemetry.Deployment, ch
23702378

23712379
returnserverURL,deployment,snapshot
23722380
}
2381+
2382+
// startIgnoringPostgresQueryCancel starts the Invocation, but excludes PostgreSQL query canceled and context
2383+
// cancellation errors. This prevents flakes in tests that only assert things that happen before PostgreSQL is fully
2384+
// initialized in the server.
2385+
funcstartIgnoringPostgresQueryCancel(t*testing.T,inv*serpent.Invocation) {
2386+
t.Helper()
2387+
clitest.StartWithAssert(t,inv,func(t*testing.T,errerror) {
2388+
ifdatabase.IsQueryCanceledError(err) {
2389+
return
2390+
}
2391+
assert.NoError(t,err)
2392+
})
2393+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp