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

test: fix TestServer cases that cancel before PostgreSQL work is done#19872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
spikecurtis merged 1 commit intomainfromspike/internal-946-ignore-query-cancel
Sep 19, 2025
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletionscli/server_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,6 +56,7 @@ import (
"github.com/coder/coder/v2/pty/ptytest"
"github.com/coder/coder/v2/tailnet/tailnettest"
"github.com/coder/coder/v2/testutil"
"github.com/coder/serpent"
)

func dbArg(t *testing.T) string {
Expand DownExpand Up@@ -486,7 +487,9 @@ func TestServer(t *testing.T) {
"--cache-dir", t.TempDir(),
)
pty := ptytest.New(t).Attach(inv)
clitest.Start(t, inv)
// Since we end the test after seeing the log lines about the access url, we could cancel the test before
// our initial interactions with PostgreSQL are complete. So, ignore errors of that type for this test.
startIgnoringPostgresQueryCancel(t, inv)

// Just wait for startup
_ = waitAccessURL(t, cfg)
Expand All@@ -510,7 +513,9 @@ func TestServer(t *testing.T) {
)
pty := ptytest.New(t).Attach(inv)

clitest.Start(t, inv)
// Since we end the test after seeing the log lines about the access url, we could cancel the test before
// our initial interactions with PostgreSQL are complete. So, ignore errors of that type for this test.
startIgnoringPostgresQueryCancel(t, inv)

// Just wait for startup
_ = waitAccessURL(t, cfg)
Expand All@@ -530,7 +535,9 @@ func TestServer(t *testing.T) {
"--cache-dir", t.TempDir(),
)
pty := ptytest.New(t).Attach(inv)
clitest.Start(t, inv)
// Since we end the test after seeing the log lines about the access url, we could cancel the test before
// our initial interactions with PostgreSQL are complete. So, ignore errors of that type for this test.
startIgnoringPostgresQueryCancel(t, inv)

// Just wait for startup
_ = waitAccessURL(t, cfg)
Expand DownExpand Up@@ -1015,7 +1022,9 @@ func TestServer(t *testing.T) {
)

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

pty.ExpectMatch("Started HTTP listener")
pty.ExpectMatch("http://0.0.0.0:")
Expand All@@ -1032,7 +1041,9 @@ func TestServer(t *testing.T) {
)

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

pty.ExpectMatch("Started HTTP listener at")
pty.ExpectMatch("http://[::]:")
Expand DownExpand Up@@ -1157,7 +1168,10 @@ func TestServer(t *testing.T) {
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
clitest.Start(t, inv.WithContext(ctx))
// Since we cancel the context before our initial interactions with PostgreSQL are complete, we need to ignore
// errors about queries being canceled.
startIgnoringPostgresQueryCancel(t, inv.WithContext(ctx))

cancel()
require.Error(t, goleak.Find())
})
Expand DownExpand Up@@ -2370,3 +2384,16 @@ func mockTelemetryServer(t *testing.T) (*url.URL, chan *telemetry.Deployment, ch

return serverURL, deployment, snapshot
}

// startIgnoringPostgresQueryCancel starts the Invocation, but excludes PostgreSQL query canceled and context
// cancellation errors. This prevents flakes in tests that only assert things that happen before PostgreSQL is fully
// initialized in the server.
func startIgnoringPostgresQueryCancel(t *testing.T, inv *serpent.Invocation) {
t.Helper()
clitest.StartWithAssert(t, inv, func(t *testing.T, err error) {
if database.IsQueryCanceledError(err) {
return
}
assert.NoError(t, err)
})
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp