Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
contents: read
services:
cockroach:
image: cockroachdb/cockroach:v25.1.4
image: cockroachdb/cockroach:v26.4.0
env:
COCKROACH_ARGS: >-
start-single-node --insecure
Expand Down
19 changes: 12 additions & 7 deletions pool_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"crypto/rand"
"os"
"strconv"
"strings"
"testing"
"time"
Expand All @@ -17,7 +18,7 @@ import (
"github.com/stretchr/testify/require"
)

func newIntegrationPool(t *testing.T, maxConns int32, opts ...Option) *Pool {
func newIntegrationPool(t testing.TB, maxConns int32, opts ...Option) *Pool {
t.Helper()

url := os.Getenv("CRDB_TEST_DATABASE_URL")
Expand Down Expand Up @@ -74,17 +75,21 @@ func TestIntegrationPool_InTx(t *testing.T) {
var attempts int
err := pool.InTx(ctx, pgx.TxOptions{}, func(db Runner) error {
attempts++

// Set session variable to enable/disable failures
shouldFail := attempts == 1 || tc.alwaysRetry
require.NoError(t, db.ExecFunc(
ctx,
func(_ context.Context, _ pgconn.CommandTag, err error) error { return err },
"SET inject_retry_errors_enabled = "+strconv.FormatBool(shouldFail),
))

if err := db.ExecFunc(ctx, func(_ context.Context, _ pgconn.CommandTag, err error) error {
return err
}, "INSERT INTO "+table+" VALUES (1)"); err != nil {
return err
}
if attempts == 1 || tc.alwaysRetry {
// Returning a real serialization failure also aborts the server-side transaction.
return db.ExecFunc(ctx, func(_ context.Context, _ pgconn.CommandTag, err error) error {
return err
}, "SELECT crdb_internal.force_retry('1s'::INTERVAL)")
}

return nil
})
if tc.wantRows == 1 {
Expand Down
Loading