fix(cli): fix flakes related to context cancellation when establishing pg connections (#18246)

Since https://github.com/coder/coder/pull/18195 was merged, we started
running CLI tests with postgres instead of just dbmem. This surfaced
errors related to context cancellation while establishing postgres
connections.

This PR should fix https://github.com/coder/internal/issues/672. Related
to https://github.com/coder/coder/issues/15109.
This commit is contained in:
Hugo Dutka
2025-06-05 15:54:13 +02:00
committed by GitHub
parent b5fd3dd855
commit 623dcd97dc
3 changed files with 17 additions and 9 deletions
+6
View File
@@ -168,6 +168,12 @@ func StartWithAssert(t *testing.T, inv *serpent.Invocation, assertCallback func(
switch {
case errors.Is(err, context.Canceled):
return
case err != nil && strings.Contains(err.Error(), "driver: bad connection"):
// When we cancel the context on a query that's being executed within
// a transaction, sometimes, instead of a context.Canceled error we get
// a "driver: bad connection" error.
// https://github.com/lib/pq/issues/1137
return
default:
assert.NoError(t, err)
}