mirror of
https://github.com/coder/coder.git
synced 2026-09-22 05:05:20 +08:00
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. -->
This commit is contained in:
+11
-2
@@ -10,6 +10,7 @@ import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"crypto/x509/pkix"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
@@ -35,6 +36,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/goleak"
|
||||
"golang.org/x/xerrors"
|
||||
"gopkg.in/yaml.v3"
|
||||
"tailscale.com/derp/derphttp"
|
||||
"tailscale.com/types/key"
|
||||
@@ -1836,7 +1838,7 @@ func TestServer_Logging_NoParallel(t *testing.T) {
|
||||
// fails.
|
||||
pty := ptytest.New(t).Attach(inv)
|
||||
|
||||
clitest.Start(t, inv.WithContext(ctx))
|
||||
startIgnoringPostgresQueryCancel(t, inv.WithContext(ctx))
|
||||
|
||||
// Wait for server to listen on HTTP, this is a good
|
||||
// starting point for expecting logs.
|
||||
@@ -1873,7 +1875,7 @@ func TestServer_Logging_NoParallel(t *testing.T) {
|
||||
// fails.
|
||||
pty := ptytest.New(t).Attach(inv)
|
||||
|
||||
clitest.Start(t, inv)
|
||||
startIgnoringPostgresQueryCancel(t, inv)
|
||||
|
||||
// Wait for server to listen on HTTP, this is a good
|
||||
// starting point for expecting logs.
|
||||
@@ -2397,6 +2399,13 @@ func startIgnoringPostgresQueryCancel(t *testing.T, inv *serpent.Invocation) {
|
||||
if database.IsQueryCanceledError(err) {
|
||||
return
|
||||
}
|
||||
// specifically when making our initial connection to PostgreSQL, we ping the database.
|
||||
// Database driver.Conn instances can return driver.ErrBadConn on ping to remove the connection from the pool.
|
||||
// lib/pq does this no matter what the error is, including context.Canceled.
|
||||
// c.f. https://pkg.go.dev/database/sql/driver#Pinger
|
||||
if xerrors.Is(err, driver.ErrBadConn) {
|
||||
return
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user