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

Commit904a308

Browse files
authored
test: ignore bad connection errors for TestServer cases that don't use the db (#19957)
<!--If you have used AI to produce some or all of this PR, please ensure you have read our [AI Contribution guidelines](https://coder.com/docs/about/contributing/AI_CONTRIBUTING) before submitting.-->
1 parent659f237 commit904a308

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

‎cli/server_test.go‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"crypto/tls"
1111
"crypto/x509"
1212
"crypto/x509/pkix"
13+
"database/sql/driver"
1314
"encoding/json"
1415
"encoding/pem"
1516
"fmt"
@@ -35,6 +36,7 @@ import (
3536
"github.com/stretchr/testify/assert"
3637
"github.com/stretchr/testify/require"
3738
"go.uber.org/goleak"
39+
"golang.org/x/xerrors"
3840
"gopkg.in/yaml.v3"
3941
"tailscale.com/derp/derphttp"
4042
"tailscale.com/types/key"
@@ -1836,7 +1838,7 @@ func TestServer_Logging_NoParallel(t *testing.T) {
18361838
// fails.
18371839
pty:=ptytest.New(t).Attach(inv)
18381840

1839-
clitest.Start(t,inv.WithContext(ctx))
1841+
startIgnoringPostgresQueryCancel(t,inv.WithContext(ctx))
18401842

18411843
// Wait for server to listen on HTTP, this is a good
18421844
// starting point for expecting logs.
@@ -1873,7 +1875,7 @@ func TestServer_Logging_NoParallel(t *testing.T) {
18731875
// fails.
18741876
pty:=ptytest.New(t).Attach(inv)
18751877

1876-
clitest.Start(t,inv)
1878+
startIgnoringPostgresQueryCancel(t,inv)
18771879

18781880
// Wait for server to listen on HTTP, this is a good
18791881
// starting point for expecting logs.
@@ -2397,6 +2399,13 @@ func startIgnoringPostgresQueryCancel(t *testing.T, inv *serpent.Invocation) {
23972399
ifdatabase.IsQueryCanceledError(err) {
23982400
return
23992401
}
2402+
// specifically when making our initial connection to PostgreSQL, we ping the database.
2403+
// Database driver.Conn instances can return driver.ErrBadConn on ping to remove the connection from the pool.
2404+
// lib/pq does this no matter what the error is, including context.Canceled.
2405+
// c.f. https://pkg.go.dev/database/sql/driver#Pinger
2406+
ifxerrors.Is(err,driver.ErrBadConn) {
2407+
return
2408+
}
24002409
assert.NoError(t,err)
24012410
})
24022411
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp