mirror of https://github.com/jackc/pgx.git
Use context timeouts in more tests
Tests should timeout in a reasonable time if something is stuck. In particular this is important when testing deadlock conditions such as can occur with the copy protocol if both the client and the server are blocked writing until the other side does a read.pull/1624/head
parent
4b9aa7c4f2
commit
9f00b6f750
155
batch_test.go
155
batch_test.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
"github.com/jackc/pgx/v5/pgconn"
|
"github.com/jackc/pgx/v5/pgconn"
|
||||||
|
@ -17,7 +18,10 @@ import (
|
||||||
func TestConnSendBatch(t *testing.T) {
|
func TestConnSendBatch(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
pgxtest.SkipCockroachDB(t, conn, "Server serial type is incompatible with test")
|
pgxtest.SkipCockroachDB(t, conn, "Server serial type is incompatible with test")
|
||||||
|
|
||||||
sql := `create temporary table ledger(
|
sql := `create temporary table ledger(
|
||||||
|
@ -36,7 +40,7 @@ func TestConnSendBatch(t *testing.T) {
|
||||||
batch.Queue("select * from ledger where false")
|
batch.Queue("select * from ledger where false")
|
||||||
batch.Queue("select sum(amount) from ledger")
|
batch.Queue("select sum(amount) from ledger")
|
||||||
|
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(ctx, batch)
|
||||||
|
|
||||||
ct, err := br.Exec()
|
ct, err := br.Exec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -152,7 +156,10 @@ func TestConnSendBatch(t *testing.T) {
|
||||||
func TestConnSendBatchQueuedQuery(t *testing.T) {
|
func TestConnSendBatchQueuedQuery(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
pgxtest.SkipCockroachDB(t, conn, "Server serial type is incompatible with test")
|
pgxtest.SkipCockroachDB(t, conn, "Server serial type is incompatible with test")
|
||||||
|
|
||||||
sql := `create temporary table ledger(
|
sql := `create temporary table ledger(
|
||||||
|
@ -237,7 +244,7 @@ func TestConnSendBatchQueuedQuery(t *testing.T) {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
err := conn.SendBatch(context.Background(), batch).Close()
|
err := conn.SendBatch(ctx, batch).Close()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -245,7 +252,10 @@ func TestConnSendBatchQueuedQuery(t *testing.T) {
|
||||||
func TestConnSendBatchMany(t *testing.T) {
|
func TestConnSendBatchMany(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
sql := `create temporary table ledger(
|
sql := `create temporary table ledger(
|
||||||
id serial primary key,
|
id serial primary key,
|
||||||
description varchar not null,
|
description varchar not null,
|
||||||
|
@ -262,7 +272,7 @@ func TestConnSendBatchMany(t *testing.T) {
|
||||||
}
|
}
|
||||||
batch.Queue("select count(*) from ledger")
|
batch.Queue("select count(*) from ledger")
|
||||||
|
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(ctx, batch)
|
||||||
|
|
||||||
for i := 0; i < numInserts; i++ {
|
for i := 0; i < numInserts; i++ {
|
||||||
ct, err := br.Exec()
|
ct, err := br.Exec()
|
||||||
|
@ -290,9 +300,12 @@ func TestConnSendBatchWithPreparedStatement(t *testing.T) {
|
||||||
pgx.QueryExecModeExec,
|
pgx.QueryExecModeExec,
|
||||||
// Don't test simple mode with prepared statements.
|
// Don't test simple mode with prepared statements.
|
||||||
}
|
}
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, modes, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, modes, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
pgxtest.SkipCockroachDB(t, conn, "Server issues incorrect ParameterDescription (https://github.com/cockroachdb/cockroach/issues/60907)")
|
pgxtest.SkipCockroachDB(t, conn, "Server issues incorrect ParameterDescription (https://github.com/cockroachdb/cockroach/issues/60907)")
|
||||||
_, err := conn.Prepare(context.Background(), "ps1", "select n from generate_series(0,$1::int) n")
|
_, err := conn.Prepare(ctx, "ps1", "select n from generate_series(0,$1::int) n")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -304,7 +317,7 @@ func TestConnSendBatchWithPreparedStatement(t *testing.T) {
|
||||||
batch.Queue("ps1", 5)
|
batch.Queue("ps1", 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(ctx, batch)
|
||||||
|
|
||||||
for i := 0; i < queryCount; i++ {
|
for i := 0; i < queryCount; i++ {
|
||||||
rows, err := br.Query()
|
rows, err := br.Query()
|
||||||
|
@ -337,13 +350,16 @@ func TestConnSendBatchWithPreparedStatement(t *testing.T) {
|
||||||
func TestConnSendBatchWithQueryRewriter(t *testing.T) {
|
func TestConnSendBatchWithQueryRewriter(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
batch := &pgx.Batch{}
|
batch := &pgx.Batch{}
|
||||||
batch.Queue("something to be replaced", &testQueryRewriter{sql: "select $1::int", args: []any{1}})
|
batch.Queue("something to be replaced", &testQueryRewriter{sql: "select $1::int", args: []any{1}})
|
||||||
batch.Queue("something else to be replaced", &testQueryRewriter{sql: "select $1::text", args: []any{"hello"}})
|
batch.Queue("something else to be replaced", &testQueryRewriter{sql: "select $1::text", args: []any{"hello"}})
|
||||||
batch.Queue("more to be replaced", &testQueryRewriter{sql: "select $1::int", args: []any{3}})
|
batch.Queue("more to be replaced", &testQueryRewriter{sql: "select $1::int", args: []any{3}})
|
||||||
|
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(ctx, batch)
|
||||||
|
|
||||||
var n int32
|
var n int32
|
||||||
err := br.QueryRow().Scan(&n)
|
err := br.QueryRow().Scan(&n)
|
||||||
|
@ -368,6 +384,9 @@ func TestConnSendBatchWithQueryRewriter(t *testing.T) {
|
||||||
func TestConnSendBatchWithPreparedStatementAndStatementCacheDisabled(t *testing.T) {
|
func TestConnSendBatchWithPreparedStatementAndStatementCacheDisabled(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
config, err := pgx.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
|
config, err := pgx.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -380,7 +399,7 @@ func TestConnSendBatchWithPreparedStatementAndStatementCacheDisabled(t *testing.
|
||||||
|
|
||||||
pgxtest.SkipCockroachDB(t, conn, "Server issues incorrect ParameterDescription (https://github.com/cockroachdb/cockroach/issues/60907)")
|
pgxtest.SkipCockroachDB(t, conn, "Server issues incorrect ParameterDescription (https://github.com/cockroachdb/cockroach/issues/60907)")
|
||||||
|
|
||||||
_, err = conn.Prepare(context.Background(), "ps1", "select n from generate_series(0,$1::int) n")
|
_, err = conn.Prepare(ctx, "ps1", "select n from generate_series(0,$1::int) n")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -392,7 +411,7 @@ func TestConnSendBatchWithPreparedStatementAndStatementCacheDisabled(t *testing.
|
||||||
batch.Queue("ps1", 5)
|
batch.Queue("ps1", 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(ctx, batch)
|
||||||
|
|
||||||
for i := 0; i < queryCount; i++ {
|
for i := 0; i < queryCount; i++ {
|
||||||
rows, err := br.Query()
|
rows, err := br.Query()
|
||||||
|
@ -426,13 +445,16 @@ func TestConnSendBatchWithPreparedStatementAndStatementCacheDisabled(t *testing.
|
||||||
func TestConnSendBatchCloseRowsPartiallyRead(t *testing.T) {
|
func TestConnSendBatchCloseRowsPartiallyRead(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
|
|
||||||
batch := &pgx.Batch{}
|
batch := &pgx.Batch{}
|
||||||
batch.Queue("select n from generate_series(0,5) n")
|
batch.Queue("select n from generate_series(0,5) n")
|
||||||
batch.Queue("select n from generate_series(0,5) n")
|
batch.Queue("select n from generate_series(0,5) n")
|
||||||
|
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(ctx, batch)
|
||||||
|
|
||||||
rows, err := br.Query()
|
rows, err := br.Query()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -485,13 +507,16 @@ func TestConnSendBatchCloseRowsPartiallyRead(t *testing.T) {
|
||||||
func TestConnSendBatchQueryError(t *testing.T) {
|
func TestConnSendBatchQueryError(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
|
|
||||||
batch := &pgx.Batch{}
|
batch := &pgx.Batch{}
|
||||||
batch.Queue("select n from generate_series(0,5) n where 100/(5-n) > 0")
|
batch.Queue("select n from generate_series(0,5) n where 100/(5-n) > 0")
|
||||||
batch.Queue("select n from generate_series(0,5) n")
|
batch.Queue("select n from generate_series(0,5) n")
|
||||||
|
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(ctx, batch)
|
||||||
|
|
||||||
rows, err := br.Query()
|
rows, err := br.Query()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -523,12 +548,15 @@ func TestConnSendBatchQueryError(t *testing.T) {
|
||||||
func TestConnSendBatchQuerySyntaxError(t *testing.T) {
|
func TestConnSendBatchQuerySyntaxError(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
|
|
||||||
batch := &pgx.Batch{}
|
batch := &pgx.Batch{}
|
||||||
batch.Queue("select 1 1")
|
batch.Queue("select 1 1")
|
||||||
|
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(ctx, batch)
|
||||||
|
|
||||||
var n int32
|
var n int32
|
||||||
err := br.QueryRow().Scan(&n)
|
err := br.QueryRow().Scan(&n)
|
||||||
|
@ -547,7 +575,10 @@ func TestConnSendBatchQuerySyntaxError(t *testing.T) {
|
||||||
func TestConnSendBatchQueryRowInsert(t *testing.T) {
|
func TestConnSendBatchQueryRowInsert(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
|
|
||||||
sql := `create temporary table ledger(
|
sql := `create temporary table ledger(
|
||||||
id serial primary key,
|
id serial primary key,
|
||||||
|
@ -560,7 +591,7 @@ func TestConnSendBatchQueryRowInsert(t *testing.T) {
|
||||||
batch.Queue("select 1")
|
batch.Queue("select 1")
|
||||||
batch.Queue("insert into ledger(description, amount) values($1, $2),($1, $2)", "q1", 1)
|
batch.Queue("insert into ledger(description, amount) values($1, $2),($1, $2)", "q1", 1)
|
||||||
|
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(ctx, batch)
|
||||||
|
|
||||||
var value int
|
var value int
|
||||||
err := br.QueryRow().Scan(&value)
|
err := br.QueryRow().Scan(&value)
|
||||||
|
@ -584,7 +615,10 @@ func TestConnSendBatchQueryRowInsert(t *testing.T) {
|
||||||
func TestConnSendBatchQueryPartialReadInsert(t *testing.T) {
|
func TestConnSendBatchQueryPartialReadInsert(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
|
|
||||||
sql := `create temporary table ledger(
|
sql := `create temporary table ledger(
|
||||||
id serial primary key,
|
id serial primary key,
|
||||||
|
@ -597,7 +631,7 @@ func TestConnSendBatchQueryPartialReadInsert(t *testing.T) {
|
||||||
batch.Queue("select 1 union all select 2 union all select 3")
|
batch.Queue("select 1 union all select 2 union all select 3")
|
||||||
batch.Queue("insert into ledger(description, amount) values($1, $2),($1, $2)", "q1", 1)
|
batch.Queue("insert into ledger(description, amount) values($1, $2),($1, $2)", "q1", 1)
|
||||||
|
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(ctx, batch)
|
||||||
|
|
||||||
rows, err := br.Query()
|
rows, err := br.Query()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -621,7 +655,10 @@ func TestConnSendBatchQueryPartialReadInsert(t *testing.T) {
|
||||||
func TestTxSendBatch(t *testing.T) {
|
func TestTxSendBatch(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
|
|
||||||
sql := `create temporary table ledger1(
|
sql := `create temporary table ledger1(
|
||||||
id serial primary key,
|
id serial primary key,
|
||||||
|
@ -635,7 +672,7 @@ func TestTxSendBatch(t *testing.T) {
|
||||||
);`
|
);`
|
||||||
mustExec(t, conn, sql)
|
mustExec(t, conn, sql)
|
||||||
|
|
||||||
tx, _ := conn.Begin(context.Background())
|
tx, _ := conn.Begin(ctx)
|
||||||
batch := &pgx.Batch{}
|
batch := &pgx.Batch{}
|
||||||
batch.Queue("insert into ledger1(description) values($1) returning id", "q1")
|
batch.Queue("insert into ledger1(description) values($1) returning id", "q1")
|
||||||
|
|
||||||
|
@ -652,7 +689,7 @@ func TestTxSendBatch(t *testing.T) {
|
||||||
batch.Queue("insert into ledger2(id,amount) values($1, $2)", id, 2)
|
batch.Queue("insert into ledger2(id,amount) values($1, $2)", id, 2)
|
||||||
batch.Queue("select amount from ledger2 where id = $1", id)
|
batch.Queue("select amount from ledger2 where id = $1", id)
|
||||||
|
|
||||||
br = tx.SendBatch(context.Background(), batch)
|
br = tx.SendBatch(ctx, batch)
|
||||||
|
|
||||||
ct, err := br.Exec()
|
ct, err := br.Exec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -669,10 +706,10 @@ func TestTxSendBatch(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
br.Close()
|
br.Close()
|
||||||
tx.Commit(context.Background())
|
tx.Commit(ctx)
|
||||||
|
|
||||||
var count int
|
var count int
|
||||||
conn.QueryRow(context.Background(), "select count(1) from ledger1 where id = $1", id).Scan(&count)
|
conn.QueryRow(ctx, "select count(1) from ledger1 where id = $1", id).Scan(&count)
|
||||||
if count != 1 {
|
if count != 1 {
|
||||||
t.Errorf("count => %v, want %v", count, 1)
|
t.Errorf("count => %v, want %v", count, 1)
|
||||||
}
|
}
|
||||||
|
@ -688,7 +725,10 @@ func TestTxSendBatch(t *testing.T) {
|
||||||
func TestTxSendBatchRollback(t *testing.T) {
|
func TestTxSendBatchRollback(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
|
|
||||||
sql := `create temporary table ledger1(
|
sql := `create temporary table ledger1(
|
||||||
id serial primary key,
|
id serial primary key,
|
||||||
|
@ -696,11 +736,11 @@ func TestTxSendBatchRollback(t *testing.T) {
|
||||||
);`
|
);`
|
||||||
mustExec(t, conn, sql)
|
mustExec(t, conn, sql)
|
||||||
|
|
||||||
tx, _ := conn.Begin(context.Background())
|
tx, _ := conn.Begin(ctx)
|
||||||
batch := &pgx.Batch{}
|
batch := &pgx.Batch{}
|
||||||
batch.Queue("insert into ledger1(description) values($1) returning id", "q1")
|
batch.Queue("insert into ledger1(description) values($1) returning id", "q1")
|
||||||
|
|
||||||
br := tx.SendBatch(context.Background(), batch)
|
br := tx.SendBatch(ctx, batch)
|
||||||
|
|
||||||
var id int
|
var id int
|
||||||
err := br.QueryRow().Scan(&id)
|
err := br.QueryRow().Scan(&id)
|
||||||
|
@ -708,9 +748,9 @@ func TestTxSendBatchRollback(t *testing.T) {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
br.Close()
|
br.Close()
|
||||||
tx.Rollback(context.Background())
|
tx.Rollback(ctx)
|
||||||
|
|
||||||
row := conn.QueryRow(context.Background(), "select count(1) from ledger1 where id = $1", id)
|
row := conn.QueryRow(ctx, "select count(1) from ledger1 where id = $1", id)
|
||||||
var count int
|
var count int
|
||||||
row.Scan(&count)
|
row.Scan(&count)
|
||||||
if count != 0 {
|
if count != 0 {
|
||||||
|
@ -724,7 +764,10 @@ func TestTxSendBatchRollback(t *testing.T) {
|
||||||
func TestSendBatchErrorWhileReadingResultsWithoutCallback(t *testing.T) {
|
func TestSendBatchErrorWhileReadingResultsWithoutCallback(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
batch := &pgx.Batch{}
|
batch := &pgx.Batch{}
|
||||||
batch.Queue("select 4 / $1::int", 0)
|
batch.Queue("select 4 / $1::int", 0)
|
||||||
|
|
||||||
|
@ -745,7 +788,10 @@ func TestSendBatchErrorWhileReadingResultsWithoutCallback(t *testing.T) {
|
||||||
func TestSendBatchErrorWhileReadingResultsWithExecWhereSomeRowsAreReturned(t *testing.T) {
|
func TestSendBatchErrorWhileReadingResultsWithExecWhereSomeRowsAreReturned(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
batch := &pgx.Batch{}
|
batch := &pgx.Batch{}
|
||||||
batch.Queue("select 4 / n from generate_series(-2, 2) n")
|
batch.Queue("select 4 / n from generate_series(-2, 2) n")
|
||||||
|
|
||||||
|
@ -766,7 +812,10 @@ func TestSendBatchErrorWhileReadingResultsWithExecWhereSomeRowsAreReturned(t *te
|
||||||
func TestConnBeginBatchDeferredError(t *testing.T) {
|
func TestConnBeginBatchDeferredError(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
|
|
||||||
pgxtest.SkipCockroachDB(t, conn, "Server does not support deferred constraint (https://github.com/cockroachdb/cockroach/issues/31632)")
|
pgxtest.SkipCockroachDB(t, conn, "Server does not support deferred constraint (https://github.com/cockroachdb/cockroach/issues/31632)")
|
||||||
|
|
||||||
|
@ -782,7 +831,7 @@ func TestConnBeginBatchDeferredError(t *testing.T) {
|
||||||
|
|
||||||
batch.Queue(`update t set n=n+1 where id='b' returning *`)
|
batch.Queue(`update t set n=n+1 where id='b' returning *`)
|
||||||
|
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(ctx, batch)
|
||||||
|
|
||||||
rows, err := br.Query()
|
rows, err := br.Query()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -811,6 +860,9 @@ func TestConnBeginBatchDeferredError(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnSendBatchNoStatementCache(t *testing.T) {
|
func TestConnSendBatchNoStatementCache(t *testing.T) {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
config := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE"))
|
config := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
config.DefaultQueryExecMode = pgx.QueryExecModeDescribeExec
|
config.DefaultQueryExecMode = pgx.QueryExecModeDescribeExec
|
||||||
config.StatementCacheCapacity = 0
|
config.StatementCacheCapacity = 0
|
||||||
|
@ -819,10 +871,13 @@ func TestConnSendBatchNoStatementCache(t *testing.T) {
|
||||||
conn := mustConnect(t, config)
|
conn := mustConnect(t, config)
|
||||||
defer closeConn(t, conn)
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
testConnSendBatch(t, conn, 3)
|
testConnSendBatch(t, ctx, conn, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnSendBatchPrepareStatementCache(t *testing.T) {
|
func TestConnSendBatchPrepareStatementCache(t *testing.T) {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
config := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE"))
|
config := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
config.DefaultQueryExecMode = pgx.QueryExecModeCacheStatement
|
config.DefaultQueryExecMode = pgx.QueryExecModeCacheStatement
|
||||||
config.StatementCacheCapacity = 32
|
config.StatementCacheCapacity = 32
|
||||||
|
@ -830,10 +885,13 @@ func TestConnSendBatchPrepareStatementCache(t *testing.T) {
|
||||||
conn := mustConnect(t, config)
|
conn := mustConnect(t, config)
|
||||||
defer closeConn(t, conn)
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
testConnSendBatch(t, conn, 3)
|
testConnSendBatch(t, ctx, conn, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnSendBatchDescribeStatementCache(t *testing.T) {
|
func TestConnSendBatchDescribeStatementCache(t *testing.T) {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
config := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE"))
|
config := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
config.DefaultQueryExecMode = pgx.QueryExecModeCacheDescribe
|
config.DefaultQueryExecMode = pgx.QueryExecModeCacheDescribe
|
||||||
config.DescriptionCacheCapacity = 32
|
config.DescriptionCacheCapacity = 32
|
||||||
|
@ -841,16 +899,16 @@ func TestConnSendBatchDescribeStatementCache(t *testing.T) {
|
||||||
conn := mustConnect(t, config)
|
conn := mustConnect(t, config)
|
||||||
defer closeConn(t, conn)
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
testConnSendBatch(t, conn, 3)
|
testConnSendBatch(t, ctx, conn, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testConnSendBatch(t *testing.T, conn *pgx.Conn, queryCount int) {
|
func testConnSendBatch(t *testing.T, ctx context.Context, conn *pgx.Conn, queryCount int) {
|
||||||
batch := &pgx.Batch{}
|
batch := &pgx.Batch{}
|
||||||
for j := 0; j < queryCount; j++ {
|
for j := 0; j < queryCount; j++ {
|
||||||
batch.Queue("select n from generate_series(0,5) n")
|
batch.Queue("select n from generate_series(0,5) n")
|
||||||
}
|
}
|
||||||
|
|
||||||
br := conn.SendBatch(context.Background(), batch)
|
br := conn.SendBatch(ctx, batch)
|
||||||
|
|
||||||
for j := 0; j < queryCount; j++ {
|
for j := 0; j < queryCount; j++ {
|
||||||
rows, err := br.Query()
|
rows, err := br.Query()
|
||||||
|
@ -873,12 +931,12 @@ func testConnSendBatch(t *testing.T, conn *pgx.Conn, queryCount int) {
|
||||||
func TestSendBatchSimpleProtocol(t *testing.T) {
|
func TestSendBatchSimpleProtocol(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
config := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE"))
|
config := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
config.DefaultQueryExecMode = pgx.QueryExecModeSimpleProtocol
|
config.DefaultQueryExecMode = pgx.QueryExecModeSimpleProtocol
|
||||||
|
|
||||||
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
||||||
defer cancelFunc()
|
|
||||||
|
|
||||||
conn := mustConnect(t, config)
|
conn := mustConnect(t, config)
|
||||||
defer closeConn(t, conn)
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
|
@ -912,7 +970,10 @@ func TestSendBatchSimpleProtocol(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleConn_SendBatch() {
|
func ExampleConn_SendBatch() {
|
||||||
conn, err := pgx.Connect(context.Background(), os.Getenv("PGX_TEST_DATABASE"))
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
conn, err := pgx.Connect(ctx, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Unable to establish connection: %v", err)
|
fmt.Printf("Unable to establish connection: %v", err)
|
||||||
return
|
return
|
||||||
|
@ -955,7 +1016,7 @@ func ExampleConn_SendBatch() {
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
|
||||||
err = conn.SendBatch(context.Background(), batch).Close()
|
err = conn.SendBatch(ctx, batch).Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("SendBatch error: %v", err)
|
fmt.Printf("SendBatch error: %v", err)
|
||||||
return
|
return
|
||||||
|
|
85
conn_test.go
85
conn_test.go
|
@ -215,7 +215,10 @@ func TestParseConfigErrors(t *testing.T) {
|
||||||
func TestExec(t *testing.T) {
|
func TestExec(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
if results := mustExec(t, conn, "create temporary table foo(id integer primary key);"); results.String() != "CREATE TABLE" {
|
if results := mustExec(t, conn, "create temporary table foo(id integer primary key);"); results.String() != "CREATE TABLE" {
|
||||||
t.Error("Unexpected results from Exec")
|
t.Error("Unexpected results from Exec")
|
||||||
}
|
}
|
||||||
|
@ -258,7 +261,10 @@ func (qr *testQueryRewriter) RewriteQuery(ctx context.Context, conn *pgx.Conn, s
|
||||||
func TestExecWithQueryRewriter(t *testing.T) {
|
func TestExecWithQueryRewriter(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
qr := testQueryRewriter{sql: "select $1::int", args: []any{42}}
|
qr := testQueryRewriter{sql: "select $1::int", args: []any{42}}
|
||||||
_, err := conn.Exec(ctx, "should be replaced", &qr)
|
_, err := conn.Exec(ctx, "should be replaced", &qr)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -268,7 +274,10 @@ func TestExecWithQueryRewriter(t *testing.T) {
|
||||||
func TestExecFailure(t *testing.T) {
|
func TestExecFailure(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
if _, err := conn.Exec(context.Background(), "selct;"); err == nil {
|
if _, err := conn.Exec(context.Background(), "selct;"); err == nil {
|
||||||
t.Fatal("Expected SQL syntax error")
|
t.Fatal("Expected SQL syntax error")
|
||||||
}
|
}
|
||||||
|
@ -284,7 +293,10 @@ func TestExecFailure(t *testing.T) {
|
||||||
func TestExecFailureWithArguments(t *testing.T) {
|
func TestExecFailureWithArguments(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
_, err := conn.Exec(context.Background(), "selct $1;", 1)
|
_, err := conn.Exec(context.Background(), "selct $1;", 1)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Expected SQL syntax error")
|
t.Fatal("Expected SQL syntax error")
|
||||||
|
@ -299,7 +311,10 @@ func TestExecFailureWithArguments(t *testing.T) {
|
||||||
func TestExecContextWithoutCancelation(t *testing.T) {
|
func TestExecContextWithoutCancelation(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
ctx, cancelFunc := context.WithCancel(context.Background())
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
||||||
defer cancelFunc()
|
defer cancelFunc()
|
||||||
|
|
||||||
|
@ -317,7 +332,10 @@ func TestExecContextWithoutCancelation(t *testing.T) {
|
||||||
func TestExecContextFailureWithoutCancelation(t *testing.T) {
|
func TestExecContextFailureWithoutCancelation(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
ctx, cancelFunc := context.WithCancel(context.Background())
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
||||||
defer cancelFunc()
|
defer cancelFunc()
|
||||||
|
|
||||||
|
@ -339,7 +357,10 @@ func TestExecContextFailureWithoutCancelation(t *testing.T) {
|
||||||
func TestExecContextFailureWithoutCancelationWithArguments(t *testing.T) {
|
func TestExecContextFailureWithoutCancelationWithArguments(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
ctx, cancelFunc := context.WithCancel(context.Background())
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
||||||
defer cancelFunc()
|
defer cancelFunc()
|
||||||
|
|
||||||
|
@ -491,7 +512,10 @@ func TestPrepareIdempotency(t *testing.T) {
|
||||||
func TestPrepareStatementCacheModes(t *testing.T) {
|
func TestPrepareStatementCacheModes(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
_, err := conn.Prepare(context.Background(), "test", "select $1::text")
|
_, err := conn.Prepare(context.Background(), "test", "select $1::text")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -731,7 +755,10 @@ func TestFatalTxError(t *testing.T) {
|
||||||
func TestInsertBoolArray(t *testing.T) {
|
func TestInsertBoolArray(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
if results := mustExec(t, conn, "create temporary table foo(spice bool[]);"); results.String() != "CREATE TABLE" {
|
if results := mustExec(t, conn, "create temporary table foo(spice bool[]);"); results.String() != "CREATE TABLE" {
|
||||||
t.Error("Unexpected results from Exec")
|
t.Error("Unexpected results from Exec")
|
||||||
}
|
}
|
||||||
|
@ -746,7 +773,10 @@ func TestInsertBoolArray(t *testing.T) {
|
||||||
func TestInsertTimestampArray(t *testing.T) {
|
func TestInsertTimestampArray(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
if results := mustExec(t, conn, "create temporary table foo(spice timestamp[]);"); results.String() != "CREATE TABLE" {
|
if results := mustExec(t, conn, "create temporary table foo(spice timestamp[]);"); results.String() != "CREATE TABLE" {
|
||||||
t.Error("Unexpected results from Exec")
|
t.Error("Unexpected results from Exec")
|
||||||
}
|
}
|
||||||
|
@ -828,7 +858,10 @@ func TestConnInitTypeMap(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnregisteredTypeUsableAsStringArgumentAndBaseResult(t *testing.T) {
|
func TestUnregisteredTypeUsableAsStringArgumentAndBaseResult(t *testing.T) {
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
pgxtest.SkipCockroachDB(t, conn, "Server does support domain types (https://github.com/cockroachdb/cockroach/issues/27796)")
|
pgxtest.SkipCockroachDB(t, conn, "Server does support domain types (https://github.com/cockroachdb/cockroach/issues/27796)")
|
||||||
|
|
||||||
var n uint64
|
var n uint64
|
||||||
|
@ -844,7 +877,10 @@ func TestUnregisteredTypeUsableAsStringArgumentAndBaseResult(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDomainType(t *testing.T) {
|
func TestDomainType(t *testing.T) {
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
pgxtest.SkipCockroachDB(t, conn, "Server does support domain types (https://github.com/cockroachdb/cockroach/issues/27796)")
|
pgxtest.SkipCockroachDB(t, conn, "Server does support domain types (https://github.com/cockroachdb/cockroach/issues/27796)")
|
||||||
|
|
||||||
// Domain type uint64 is a PostgreSQL domain of underlying type numeric.
|
// Domain type uint64 is a PostgreSQL domain of underlying type numeric.
|
||||||
|
@ -878,7 +914,10 @@ func TestDomainType(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadTypeSameNameInDifferentSchemas(t *testing.T) {
|
func TestLoadTypeSameNameInDifferentSchemas(t *testing.T) {
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
pgxtest.SkipCockroachDB(t, conn, "Server does support composite types (https://github.com/cockroachdb/cockroach/issues/27792)")
|
pgxtest.SkipCockroachDB(t, conn, "Server does support composite types (https://github.com/cockroachdb/cockroach/issues/27792)")
|
||||||
|
|
||||||
tx, err := conn.Begin(ctx)
|
tx, err := conn.Begin(ctx)
|
||||||
|
@ -920,7 +959,10 @@ create type pgx_b.point as (c text);
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadCompositeType(t *testing.T) {
|
func TestLoadCompositeType(t *testing.T) {
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
pgxtest.SkipCockroachDB(t, conn, "Server does support composite types (https://github.com/cockroachdb/cockroach/issues/27792)")
|
pgxtest.SkipCockroachDB(t, conn, "Server does support composite types (https://github.com/cockroachdb/cockroach/issues/27792)")
|
||||||
|
|
||||||
tx, err := conn.Begin(ctx)
|
tx, err := conn.Begin(ctx)
|
||||||
|
@ -939,7 +981,10 @@ func TestLoadCompositeType(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadRangeType(t *testing.T) {
|
func TestLoadRangeType(t *testing.T) {
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
pgxtest.SkipCockroachDB(t, conn, "Server does support range types")
|
pgxtest.SkipCockroachDB(t, conn, "Server does support range types")
|
||||||
|
|
||||||
tx, err := conn.Begin(ctx)
|
tx, err := conn.Begin(ctx)
|
||||||
|
@ -970,7 +1015,10 @@ func TestLoadRangeType(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadMultiRangeType(t *testing.T) {
|
func TestLoadMultiRangeType(t *testing.T) {
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
pgxtest.SkipCockroachDB(t, conn, "Server does support range types")
|
pgxtest.SkipCockroachDB(t, conn, "Server does support range types")
|
||||||
pgxtest.SkipPostgreSQLVersionLessThan(t, conn, 14) // multirange data type was added in 14 postgresql
|
pgxtest.SkipPostgreSQLVersionLessThan(t, conn, 14) // multirange data type was added in 14 postgresql
|
||||||
|
|
||||||
|
@ -1157,7 +1205,10 @@ func TestStmtCacheInvalidationTx(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInsertDurationInterval(t *testing.T) {
|
func TestInsertDurationInterval(t *testing.T) {
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
_, err := conn.Exec(context.Background(), "create temporary table t(duration INTERVAL(0) NOT NULL)")
|
_, err := conn.Exec(context.Background(), "create temporary table t(duration INTERVAL(0) NOT NULL)")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,9 @@ func TestConnCopyWithAllQueryExecModes(t *testing.T) {
|
||||||
t.Run(mode.String(), func(t *testing.T) {
|
t.Run(mode.String(), func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
cfg := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE"))
|
cfg := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
cfg.DefaultQueryExecMode = mode
|
cfg.DefaultQueryExecMode = mode
|
||||||
conn := mustConnect(t, cfg)
|
conn := mustConnect(t, cfg)
|
||||||
|
@ -39,7 +42,7 @@ func TestConnCopyWithAllQueryExecModes(t *testing.T) {
|
||||||
{nil, nil, nil, nil, nil},
|
{nil, nil, nil, nil, nil},
|
||||||
}
|
}
|
||||||
|
|
||||||
copyCount, err := conn.CopyFrom(context.Background(), pgx.Identifier{"foo"}, []string{"a", "b", "c", "d", "e"}, pgx.CopyFromRows(inputRows))
|
copyCount, err := conn.CopyFrom(ctx, pgx.Identifier{"foo"}, []string{"a", "b", "c", "d", "e"}, pgx.CopyFromRows(inputRows))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error for CopyFrom: %v", err)
|
t.Errorf("Unexpected error for CopyFrom: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -47,7 +50,7 @@ func TestConnCopyWithAllQueryExecModes(t *testing.T) {
|
||||||
t.Errorf("Expected CopyFrom to return %d copied rows, but got %d", len(inputRows), copyCount)
|
t.Errorf("Expected CopyFrom to return %d copied rows, but got %d", len(inputRows), copyCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := conn.Query(context.Background(), "select * from foo")
|
rows, err := conn.Query(ctx, "select * from foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error for Query: %v", err)
|
t.Errorf("Unexpected error for Query: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -80,6 +83,9 @@ func TestConnCopyWithKnownOIDQueryExecModes(t *testing.T) {
|
||||||
t.Run(mode.String(), func(t *testing.T) {
|
t.Run(mode.String(), func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
cfg := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE"))
|
cfg := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
cfg.DefaultQueryExecMode = mode
|
cfg.DefaultQueryExecMode = mode
|
||||||
conn := mustConnect(t, cfg)
|
conn := mustConnect(t, cfg)
|
||||||
|
@ -102,7 +108,7 @@ func TestConnCopyWithKnownOIDQueryExecModes(t *testing.T) {
|
||||||
{nil, nil, nil, nil, nil, nil, nil},
|
{nil, nil, nil, nil, nil, nil, nil},
|
||||||
}
|
}
|
||||||
|
|
||||||
copyCount, err := conn.CopyFrom(context.Background(), pgx.Identifier{"foo"}, []string{"a", "b", "c", "d", "e", "f", "g"}, pgx.CopyFromRows(inputRows))
|
copyCount, err := conn.CopyFrom(ctx, pgx.Identifier{"foo"}, []string{"a", "b", "c", "d", "e", "f", "g"}, pgx.CopyFromRows(inputRows))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error for CopyFrom: %v", err)
|
t.Errorf("Unexpected error for CopyFrom: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -110,7 +116,7 @@ func TestConnCopyWithKnownOIDQueryExecModes(t *testing.T) {
|
||||||
t.Errorf("Expected CopyFrom to return %d copied rows, but got %d", len(inputRows), copyCount)
|
t.Errorf("Expected CopyFrom to return %d copied rows, but got %d", len(inputRows), copyCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := conn.Query(context.Background(), "select * from foo")
|
rows, err := conn.Query(ctx, "select * from foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error for Query: %v", err)
|
t.Errorf("Unexpected error for Query: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -140,6 +146,9 @@ func TestConnCopyWithKnownOIDQueryExecModes(t *testing.T) {
|
||||||
func TestConnCopyFromSmall(t *testing.T) {
|
func TestConnCopyFromSmall(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
defer closeConn(t, conn)
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
|
@ -160,7 +169,7 @@ func TestConnCopyFromSmall(t *testing.T) {
|
||||||
{nil, nil, nil, nil, nil, nil, nil},
|
{nil, nil, nil, nil, nil, nil, nil},
|
||||||
}
|
}
|
||||||
|
|
||||||
copyCount, err := conn.CopyFrom(context.Background(), pgx.Identifier{"foo"}, []string{"a", "b", "c", "d", "e", "f", "g"}, pgx.CopyFromRows(inputRows))
|
copyCount, err := conn.CopyFrom(ctx, pgx.Identifier{"foo"}, []string{"a", "b", "c", "d", "e", "f", "g"}, pgx.CopyFromRows(inputRows))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error for CopyFrom: %v", err)
|
t.Errorf("Unexpected error for CopyFrom: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -168,7 +177,7 @@ func TestConnCopyFromSmall(t *testing.T) {
|
||||||
t.Errorf("Expected CopyFrom to return %d copied rows, but got %d", len(inputRows), copyCount)
|
t.Errorf("Expected CopyFrom to return %d copied rows, but got %d", len(inputRows), copyCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := conn.Query(context.Background(), "select * from foo")
|
rows, err := conn.Query(ctx, "select * from foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error for Query: %v", err)
|
t.Errorf("Unexpected error for Query: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -196,6 +205,9 @@ func TestConnCopyFromSmall(t *testing.T) {
|
||||||
func TestConnCopyFromSliceSmall(t *testing.T) {
|
func TestConnCopyFromSliceSmall(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
defer closeConn(t, conn)
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
|
@ -216,7 +228,7 @@ func TestConnCopyFromSliceSmall(t *testing.T) {
|
||||||
{nil, nil, nil, nil, nil, nil, nil},
|
{nil, nil, nil, nil, nil, nil, nil},
|
||||||
}
|
}
|
||||||
|
|
||||||
copyCount, err := conn.CopyFrom(context.Background(), pgx.Identifier{"foo"}, []string{"a", "b", "c", "d", "e", "f", "g"},
|
copyCount, err := conn.CopyFrom(ctx, pgx.Identifier{"foo"}, []string{"a", "b", "c", "d", "e", "f", "g"},
|
||||||
pgx.CopyFromSlice(len(inputRows), func(i int) ([]any, error) {
|
pgx.CopyFromSlice(len(inputRows), func(i int) ([]any, error) {
|
||||||
return inputRows[i], nil
|
return inputRows[i], nil
|
||||||
}))
|
}))
|
||||||
|
@ -227,7 +239,7 @@ func TestConnCopyFromSliceSmall(t *testing.T) {
|
||||||
t.Errorf("Expected CopyFrom to return %d copied rows, but got %d", len(inputRows), copyCount)
|
t.Errorf("Expected CopyFrom to return %d copied rows, but got %d", len(inputRows), copyCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := conn.Query(context.Background(), "select * from foo")
|
rows, err := conn.Query(ctx, "select * from foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error for Query: %v", err)
|
t.Errorf("Unexpected error for Query: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -255,6 +267,9 @@ func TestConnCopyFromSliceSmall(t *testing.T) {
|
||||||
func TestConnCopyFromLarge(t *testing.T) {
|
func TestConnCopyFromLarge(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
defer closeConn(t, conn)
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
|
@ -279,7 +294,7 @@ func TestConnCopyFromLarge(t *testing.T) {
|
||||||
inputRows = append(inputRows, []any{int16(0), int32(1), int64(2), "abc", "efg", time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), tzedTime, []byte{111, 111, 111, 111}})
|
inputRows = append(inputRows, []any{int16(0), int32(1), int64(2), "abc", "efg", time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), tzedTime, []byte{111, 111, 111, 111}})
|
||||||
}
|
}
|
||||||
|
|
||||||
copyCount, err := conn.CopyFrom(context.Background(), pgx.Identifier{"foo"}, []string{"a", "b", "c", "d", "e", "f", "g", "h"}, pgx.CopyFromRows(inputRows))
|
copyCount, err := conn.CopyFrom(ctx, pgx.Identifier{"foo"}, []string{"a", "b", "c", "d", "e", "f", "g", "h"}, pgx.CopyFromRows(inputRows))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error for CopyFrom: %v", err)
|
t.Errorf("Unexpected error for CopyFrom: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -287,7 +302,7 @@ func TestConnCopyFromLarge(t *testing.T) {
|
||||||
t.Errorf("Expected CopyFrom to return %d copied rows, but got %d", len(inputRows), copyCount)
|
t.Errorf("Expected CopyFrom to return %d copied rows, but got %d", len(inputRows), copyCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := conn.Query(context.Background(), "select * from foo")
|
rows, err := conn.Query(ctx, "select * from foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error for Query: %v", err)
|
t.Errorf("Unexpected error for Query: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -315,10 +330,12 @@ func TestConnCopyFromLarge(t *testing.T) {
|
||||||
func TestConnCopyFromEnum(t *testing.T) {
|
func TestConnCopyFromEnum(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
defer closeConn(t, conn)
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
ctx := context.Background()
|
|
||||||
tx, err := conn.Begin(ctx)
|
tx, err := conn.Begin(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer tx.Rollback(ctx)
|
defer tx.Rollback(ctx)
|
||||||
|
@ -384,6 +401,9 @@ func TestConnCopyFromEnum(t *testing.T) {
|
||||||
func TestConnCopyFromJSON(t *testing.T) {
|
func TestConnCopyFromJSON(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
defer closeConn(t, conn)
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
|
@ -403,7 +423,7 @@ func TestConnCopyFromJSON(t *testing.T) {
|
||||||
{nil, nil},
|
{nil, nil},
|
||||||
}
|
}
|
||||||
|
|
||||||
copyCount, err := conn.CopyFrom(context.Background(), pgx.Identifier{"foo"}, []string{"a", "b"}, pgx.CopyFromRows(inputRows))
|
copyCount, err := conn.CopyFrom(ctx, pgx.Identifier{"foo"}, []string{"a", "b"}, pgx.CopyFromRows(inputRows))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error for CopyFrom: %v", err)
|
t.Errorf("Unexpected error for CopyFrom: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -411,7 +431,7 @@ func TestConnCopyFromJSON(t *testing.T) {
|
||||||
t.Errorf("Expected CopyFrom to return %d copied rows, but got %d", len(inputRows), copyCount)
|
t.Errorf("Expected CopyFrom to return %d copied rows, but got %d", len(inputRows), copyCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := conn.Query(context.Background(), "select * from foo")
|
rows, err := conn.Query(ctx, "select * from foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error for Query: %v", err)
|
t.Errorf("Unexpected error for Query: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -461,6 +481,9 @@ func (cfs *clientFailSource) Err() error {
|
||||||
func TestConnCopyFromFailServerSideMidway(t *testing.T) {
|
func TestConnCopyFromFailServerSideMidway(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
defer closeConn(t, conn)
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
|
@ -475,7 +498,7 @@ func TestConnCopyFromFailServerSideMidway(t *testing.T) {
|
||||||
{int32(3), "def"},
|
{int32(3), "def"},
|
||||||
}
|
}
|
||||||
|
|
||||||
copyCount, err := conn.CopyFrom(context.Background(), pgx.Identifier{"foo"}, []string{"a", "b"}, pgx.CopyFromRows(inputRows))
|
copyCount, err := conn.CopyFrom(ctx, pgx.Identifier{"foo"}, []string{"a", "b"}, pgx.CopyFromRows(inputRows))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Expected CopyFrom return error, but it did not")
|
t.Errorf("Expected CopyFrom return error, but it did not")
|
||||||
}
|
}
|
||||||
|
@ -486,7 +509,7 @@ func TestConnCopyFromFailServerSideMidway(t *testing.T) {
|
||||||
t.Errorf("Expected CopyFrom to return 0 copied rows, but got %d", copyCount)
|
t.Errorf("Expected CopyFrom to return 0 copied rows, but got %d", copyCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := conn.Query(context.Background(), "select * from foo")
|
rows, err := conn.Query(ctx, "select * from foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error for Query: %v", err)
|
t.Errorf("Unexpected error for Query: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -537,6 +560,9 @@ func (fs *failSource) Err() error {
|
||||||
func TestConnCopyFromFailServerSideMidwayAbortsWithoutWaiting(t *testing.T) {
|
func TestConnCopyFromFailServerSideMidwayAbortsWithoutWaiting(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
defer closeConn(t, conn)
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
|
@ -548,7 +574,7 @@ func TestConnCopyFromFailServerSideMidwayAbortsWithoutWaiting(t *testing.T) {
|
||||||
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
copyCount, err := conn.CopyFrom(context.Background(), pgx.Identifier{"foo"}, []string{"a"}, &failSource{})
|
copyCount, err := conn.CopyFrom(ctx, pgx.Identifier{"foo"}, []string{"a"}, &failSource{})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Expected CopyFrom return error, but it did not")
|
t.Errorf("Expected CopyFrom return error, but it did not")
|
||||||
}
|
}
|
||||||
|
@ -565,7 +591,7 @@ func TestConnCopyFromFailServerSideMidwayAbortsWithoutWaiting(t *testing.T) {
|
||||||
t.Errorf("Failing CopyFrom shouldn't have taken so long: %v", copyTime)
|
t.Errorf("Failing CopyFrom shouldn't have taken so long: %v", copyTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := conn.Query(context.Background(), "select * from foo")
|
rows, err := conn.Query(ctx, "select * from foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error for Query: %v", err)
|
t.Errorf("Unexpected error for Query: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -614,6 +640,9 @@ func (fs *slowFailRaceSource) Err() error {
|
||||||
func TestConnCopyFromSlowFailRace(t *testing.T) {
|
func TestConnCopyFromSlowFailRace(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
defer closeConn(t, conn)
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
|
@ -622,7 +651,7 @@ func TestConnCopyFromSlowFailRace(t *testing.T) {
|
||||||
b bytea not null
|
b bytea not null
|
||||||
)`)
|
)`)
|
||||||
|
|
||||||
copyCount, err := conn.CopyFrom(context.Background(), pgx.Identifier{"foo"}, []string{"a", "b"}, &slowFailRaceSource{})
|
copyCount, err := conn.CopyFrom(ctx, pgx.Identifier{"foo"}, []string{"a", "b"}, &slowFailRaceSource{})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Expected CopyFrom return error, but it did not")
|
t.Errorf("Expected CopyFrom return error, but it did not")
|
||||||
}
|
}
|
||||||
|
@ -639,6 +668,9 @@ func TestConnCopyFromSlowFailRace(t *testing.T) {
|
||||||
func TestConnCopyFromCopyFromSourceErrorMidway(t *testing.T) {
|
func TestConnCopyFromCopyFromSourceErrorMidway(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
defer closeConn(t, conn)
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
|
@ -646,7 +678,7 @@ func TestConnCopyFromCopyFromSourceErrorMidway(t *testing.T) {
|
||||||
a bytea not null
|
a bytea not null
|
||||||
)`)
|
)`)
|
||||||
|
|
||||||
copyCount, err := conn.CopyFrom(context.Background(), pgx.Identifier{"foo"}, []string{"a"}, &clientFailSource{})
|
copyCount, err := conn.CopyFrom(ctx, pgx.Identifier{"foo"}, []string{"a"}, &clientFailSource{})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Expected CopyFrom return error, but it did not")
|
t.Errorf("Expected CopyFrom return error, but it did not")
|
||||||
}
|
}
|
||||||
|
@ -654,7 +686,7 @@ func TestConnCopyFromCopyFromSourceErrorMidway(t *testing.T) {
|
||||||
t.Errorf("Expected CopyFrom to return 0 copied rows, but got %d", copyCount)
|
t.Errorf("Expected CopyFrom to return 0 copied rows, but got %d", copyCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := conn.Query(context.Background(), "select * from foo")
|
rows, err := conn.Query(ctx, "select * from foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error for Query: %v", err)
|
t.Errorf("Unexpected error for Query: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -699,6 +731,9 @@ func (cfs *clientFinalErrSource) Err() error {
|
||||||
func TestConnCopyFromCopyFromSourceErrorEnd(t *testing.T) {
|
func TestConnCopyFromCopyFromSourceErrorEnd(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
defer closeConn(t, conn)
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
|
@ -706,7 +741,7 @@ func TestConnCopyFromCopyFromSourceErrorEnd(t *testing.T) {
|
||||||
a bytea not null
|
a bytea not null
|
||||||
)`)
|
)`)
|
||||||
|
|
||||||
copyCount, err := conn.CopyFrom(context.Background(), pgx.Identifier{"foo"}, []string{"a"}, &clientFinalErrSource{})
|
copyCount, err := conn.CopyFrom(ctx, pgx.Identifier{"foo"}, []string{"a"}, &clientFinalErrSource{})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Expected CopyFrom return error, but it did not")
|
t.Errorf("Expected CopyFrom return error, but it did not")
|
||||||
}
|
}
|
||||||
|
@ -714,7 +749,7 @@ func TestConnCopyFromCopyFromSourceErrorEnd(t *testing.T) {
|
||||||
t.Errorf("Expected CopyFrom to return 0 copied rows, but got %d", copyCount)
|
t.Errorf("Expected CopyFrom to return 0 copied rows, but got %d", copyCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := conn.Query(context.Background(), "select * from foo")
|
rows, err := conn.Query(ctx, "select * from foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error for Query: %v", err)
|
t.Errorf("Unexpected error for Query: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -742,6 +777,9 @@ func TestConnCopyFromCopyFromSourceErrorEnd(t *testing.T) {
|
||||||
func TestConnCopyFromAutomaticStringConversion(t *testing.T) {
|
func TestConnCopyFromAutomaticStringConversion(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
defer closeConn(t, conn)
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
|
@ -755,11 +793,11 @@ func TestConnCopyFromAutomaticStringConversion(t *testing.T) {
|
||||||
{8},
|
{8},
|
||||||
}
|
}
|
||||||
|
|
||||||
copyCount, err := conn.CopyFrom(context.Background(), pgx.Identifier{"foo"}, []string{"a"}, pgx.CopyFromRows(inputRows))
|
copyCount, err := conn.CopyFrom(ctx, pgx.Identifier{"foo"}, []string{"a"}, pgx.CopyFromRows(inputRows))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.EqualValues(t, len(inputRows), copyCount)
|
require.EqualValues(t, len(inputRows), copyCount)
|
||||||
|
|
||||||
rows, _ := conn.Query(context.Background(), "select * from foo")
|
rows, _ := conn.Query(ctx, "select * from foo")
|
||||||
nums, err := pgx.CollectRows(rows, pgx.RowTo[int64])
|
nums, err := pgx.CollectRows(rows, pgx.RowTo[int64])
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
"github.com/jackc/pgx/v5/pgtype"
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
|
@ -215,7 +216,10 @@ func TestHstoreCodec(t *testing.T) {
|
||||||
pgxtest.RunValueRoundTripTests(context.Background(), t, ctrWithoutCodec, pgxtest.AllQueryExecModes, "hstore", tests)
|
pgxtest.RunValueRoundTripTests(context.Background(), t, ctrWithoutCodec, pgxtest.AllQueryExecModes, "hstore", tests)
|
||||||
|
|
||||||
// scan empty and NULL: should be different in all query modes
|
// scan empty and NULL: should be different in all query modes
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, ctr, pgxtest.AllQueryExecModes, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, ctr, pgxtest.AllQueryExecModes, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
h := pgtype.Hstore{"should_be_erased": nil}
|
h := pgtype.Hstore{"should_be_erased": nil}
|
||||||
err := conn.QueryRow(ctx, `select cast(null as hstore)`).Scan(&h)
|
err := conn.QueryRow(ctx, `select cast(null as hstore)`).Scan(&h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -220,7 +220,10 @@ func TestConnQueryValuesWithUnregisteredOID(t *testing.T) {
|
||||||
func TestConnQueryArgsAndScanWithUnregisteredOID(t *testing.T) {
|
func TestConnQueryArgsAndScanWithUnregisteredOID(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
tx, err := conn.Begin(ctx)
|
tx, err := conn.Begin(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer tx.Rollback(ctx)
|
defer tx.Rollback(ctx)
|
||||||
|
@ -1943,7 +1946,10 @@ func TestQueryErrorWithDisabledStatementCache(t *testing.T) {
|
||||||
func TestQueryWithQueryRewriter(t *testing.T) {
|
func TestQueryWithQueryRewriter(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
qr := testQueryRewriter{sql: "select $1::int", args: []any{42}}
|
qr := testQueryRewriter{sql: "select $1::int", args: []any{42}}
|
||||||
rows, err := conn.Query(ctx, "should be replaced", &qr)
|
rows, err := conn.Query(ctx, "should be replaced", &qr)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
15
rows_test.go
15
rows_test.go
|
@ -39,7 +39,10 @@ func TestRowScanner(t *testing.T) {
|
||||||
func TestForEachRow(t *testing.T) {
|
func TestForEachRow(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
var actualResults []any
|
var actualResults []any
|
||||||
|
|
||||||
rows, _ := conn.Query(
|
rows, _ := conn.Query(
|
||||||
|
@ -67,7 +70,10 @@ func TestForEachRow(t *testing.T) {
|
||||||
func TestForEachRowScanError(t *testing.T) {
|
func TestForEachRowScanError(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
var actualResults []any
|
var actualResults []any
|
||||||
|
|
||||||
rows, _ := conn.Query(
|
rows, _ := conn.Query(
|
||||||
|
@ -88,7 +94,10 @@ func TestForEachRowScanError(t *testing.T) {
|
||||||
func TestForEachRowAbort(t *testing.T) {
|
func TestForEachRowAbort(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
rows, _ := conn.Query(
|
rows, _ := conn.Query(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
"select n, n * 2 from generate_series(1, $1) n",
|
"select n, n * 2 from generate_series(1, $1) n",
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
"github.com/jackc/pgx/v5/pgxtest"
|
"github.com/jackc/pgx/v5/pgxtest"
|
||||||
|
@ -71,7 +72,10 @@ func TestContextGetsPassedToLogMethod(t *testing.T) {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
logger.Clear() // Clear any logs written when establishing connection
|
logger.Clear() // Clear any logs written when establishing connection
|
||||||
|
|
||||||
ctx = context.WithValue(context.Background(), "ctxdata", "foo")
|
ctx = context.WithValue(context.Background(), "ctxdata", "foo")
|
||||||
|
@ -133,7 +137,10 @@ func TestLogQuery(t *testing.T) {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
logger.Clear() // Clear any logs written when establishing connection
|
logger.Clear() // Clear any logs written when establishing connection
|
||||||
|
|
||||||
_, err := conn.Exec(ctx, `select $1::text`, "testing")
|
_, err := conn.Exec(ctx, `select $1::text`, "testing")
|
||||||
|
@ -172,7 +179,10 @@ func TestLogQueryArgsHandlesUTF8(t *testing.T) {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
logger.Clear() // Clear any logs written when establishing connection
|
logger.Clear() // Clear any logs written when establishing connection
|
||||||
|
|
||||||
var s string
|
var s string
|
||||||
|
@ -217,7 +227,10 @@ func TestLogCopyFrom(t *testing.T) {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, ctr, pgxtest.KnownOIDQueryExecModes, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, ctr, pgxtest.KnownOIDQueryExecModes, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
_, err := conn.Exec(context.Background(), `create temporary table foo(a int4)`)
|
_, err := conn.Exec(context.Background(), `create temporary table foo(a int4)`)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -302,7 +315,10 @@ func TestLogBatchStatementsOnExec(t *testing.T) {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
logger.Clear() // Clear any logs written when establishing connection
|
logger.Clear() // Clear any logs written when establishing connection
|
||||||
|
|
||||||
batch := &pgx.Batch{}
|
batch := &pgx.Batch{}
|
||||||
|
@ -346,7 +362,10 @@ func TestLogBatchStatementsOnBatchResultClose(t *testing.T) {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
logger.Clear() // Clear any logs written when establishing connection
|
logger.Clear() // Clear any logs written when establishing connection
|
||||||
|
|
||||||
batch := &pgx.Batch{}
|
batch := &pgx.Batch{}
|
||||||
|
@ -382,7 +401,10 @@ func TestLogPrepare(t *testing.T) {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, ctr, []pgx.QueryExecMode{
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, ctr, []pgx.QueryExecMode{
|
||||||
pgx.QueryExecModeCacheStatement,
|
pgx.QueryExecModeCacheStatement,
|
||||||
pgx.QueryExecModeCacheDescribe,
|
pgx.QueryExecModeCacheDescribe,
|
||||||
pgx.QueryExecModeDescribeExec,
|
pgx.QueryExecModeDescribeExec,
|
||||||
|
@ -406,7 +428,10 @@ func TestLogPrepare(t *testing.T) {
|
||||||
require.Equal(t, err, logs[0].data["err"])
|
require.Equal(t, err, logs[0].data["err"])
|
||||||
})
|
})
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel = context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
logger.Clear() // Clear any logs written when establishing connection
|
logger.Clear() // Clear any logs written when establishing connection
|
||||||
|
|
||||||
_, err := conn.Prepare(ctx, "test_query_1", `select $1::int`)
|
_, err := conn.Prepare(ctx, "test_query_1", `select $1::int`)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package pgx_test
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
"github.com/jackc/pgx/v5/pgxtest"
|
"github.com/jackc/pgx/v5/pgxtest"
|
||||||
|
@ -106,7 +107,10 @@ func TestTraceExec(t *testing.T) {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
traceQueryStartCalled := false
|
traceQueryStartCalled := false
|
||||||
tracer.traceQueryStart = func(ctx context.Context, conn *pgx.Conn, data pgx.TraceQueryStartData) context.Context {
|
tracer.traceQueryStart = func(ctx context.Context, conn *pgx.Conn, data pgx.TraceQueryStartData) context.Context {
|
||||||
traceQueryStartCalled = true
|
traceQueryStartCalled = true
|
||||||
|
@ -143,7 +147,10 @@ func TestTraceQuery(t *testing.T) {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
traceQueryStartCalled := false
|
traceQueryStartCalled := false
|
||||||
tracer.traceQueryStart = func(ctx context.Context, conn *pgx.Conn, data pgx.TraceQueryStartData) context.Context {
|
tracer.traceQueryStart = func(ctx context.Context, conn *pgx.Conn, data pgx.TraceQueryStartData) context.Context {
|
||||||
traceQueryStartCalled = true
|
traceQueryStartCalled = true
|
||||||
|
@ -182,7 +189,10 @@ func TestTraceBatchNormal(t *testing.T) {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
traceBatchStartCalled := false
|
traceBatchStartCalled := false
|
||||||
tracer.traceBatchStart = func(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchStartData) context.Context {
|
tracer.traceBatchStart = func(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchStartData) context.Context {
|
||||||
traceBatchStartCalled = true
|
traceBatchStartCalled = true
|
||||||
|
@ -242,7 +252,10 @@ func TestTraceBatchClose(t *testing.T) {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
traceBatchStartCalled := false
|
traceBatchStartCalled := false
|
||||||
tracer.traceBatchStart = func(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchStartData) context.Context {
|
tracer.traceBatchStart = func(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchStartData) context.Context {
|
||||||
traceBatchStartCalled = true
|
traceBatchStartCalled = true
|
||||||
|
@ -290,7 +303,10 @@ func TestTraceBatchErrorWhileReadingResults(t *testing.T) {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, ctr, []pgx.QueryExecMode{pgx.QueryExecModeSimpleProtocol}, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, ctr, []pgx.QueryExecMode{pgx.QueryExecModeSimpleProtocol}, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
traceBatchStartCalled := false
|
traceBatchStartCalled := false
|
||||||
tracer.traceBatchStart = func(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchStartData) context.Context {
|
tracer.traceBatchStart = func(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchStartData) context.Context {
|
||||||
traceBatchStartCalled = true
|
traceBatchStartCalled = true
|
||||||
|
@ -356,7 +372,10 @@ func TestTraceBatchErrorWhileReadingResultsWhileClosing(t *testing.T) {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, ctr, []pgx.QueryExecMode{pgx.QueryExecModeSimpleProtocol}, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, ctr, []pgx.QueryExecMode{pgx.QueryExecModeSimpleProtocol}, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
traceBatchStartCalled := false
|
traceBatchStartCalled := false
|
||||||
tracer.traceBatchStart = func(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchStartData) context.Context {
|
tracer.traceBatchStart = func(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchStartData) context.Context {
|
||||||
traceBatchStartCalled = true
|
traceBatchStartCalled = true
|
||||||
|
@ -409,7 +428,13 @@ func TestTraceCopyFrom(t *testing.T) {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
|
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
traceCopyFromStartCalled := false
|
traceCopyFromStartCalled := false
|
||||||
tracer.traceCopyFromStart = func(ctx context.Context, conn *pgx.Conn, data pgx.TraceCopyFromStartData) context.Context {
|
tracer.traceCopyFromStart = func(ctx context.Context, conn *pgx.Conn, data pgx.TraceCopyFromStartData) context.Context {
|
||||||
traceCopyFromStartCalled = true
|
traceCopyFromStartCalled = true
|
||||||
|
@ -426,7 +451,7 @@ func TestTraceCopyFrom(t *testing.T) {
|
||||||
require.NoError(t, data.Err)
|
require.NoError(t, data.Err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := conn.Exec(context.Background(), `create temporary table foo(a int4)`)
|
_, err := conn.Exec(ctx, `create temporary table foo(a int4)`)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
inputRows := [][]any{
|
inputRows := [][]any{
|
||||||
|
@ -434,7 +459,7 @@ func TestTraceCopyFrom(t *testing.T) {
|
||||||
{nil},
|
{nil},
|
||||||
}
|
}
|
||||||
|
|
||||||
copyCount, err := conn.CopyFrom(context.Background(), pgx.Identifier{"foo"}, []string{"a"}, pgx.CopyFromRows(inputRows))
|
copyCount, err := conn.CopyFrom(ctx, pgx.Identifier{"foo"}, []string{"a"}, pgx.CopyFromRows(inputRows))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.EqualValues(t, len(inputRows), copyCount)
|
require.EqualValues(t, len(inputRows), copyCount)
|
||||||
require.True(t, traceCopyFromStartCalled)
|
require.True(t, traceCopyFromStartCalled)
|
||||||
|
@ -454,7 +479,10 @@ func TestTracePrepare(t *testing.T) {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, ctr, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
tracePrepareStartCalled := false
|
tracePrepareStartCalled := false
|
||||||
tracer.tracePrepareStart = func(ctx context.Context, conn *pgx.Conn, data pgx.TracePrepareStartData) context.Context {
|
tracer.tracePrepareStart = func(ctx context.Context, conn *pgx.Conn, data pgx.TracePrepareStartData) context.Context {
|
||||||
tracePrepareStartCalled = true
|
tracePrepareStartCalled = true
|
||||||
|
|
|
@ -19,7 +19,10 @@ import (
|
||||||
func TestDateTranscode(t *testing.T) {
|
func TestDateTranscode(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
dates := []time.Time{
|
dates := []time.Time{
|
||||||
time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC),
|
time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||||
time.Date(1000, 1, 1, 0, 0, 0, 0, time.UTC),
|
time.Date(1000, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||||
|
@ -58,7 +61,10 @@ func TestDateTranscode(t *testing.T) {
|
||||||
func TestTimestampTzTranscode(t *testing.T) {
|
func TestTimestampTzTranscode(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
inputTime := time.Date(2013, 1, 2, 3, 4, 5, 6000, time.Local)
|
inputTime := time.Date(2013, 1, 2, 3, 4, 5, 6000, time.Local)
|
||||||
|
|
||||||
var outputTime time.Time
|
var outputTime time.Time
|
||||||
|
@ -78,7 +84,10 @@ func TestTimestampTzTranscode(t *testing.T) {
|
||||||
func TestJSONAndJSONBTranscode(t *testing.T) {
|
func TestJSONAndJSONBTranscode(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
for _, typename := range []string{"json", "jsonb"} {
|
for _, typename := range []string{"json", "jsonb"} {
|
||||||
if _, ok := conn.TypeMap().TypeForName(typename); !ok {
|
if _, ok := conn.TypeMap().TypeForName(typename); !ok {
|
||||||
continue // No JSON/JSONB type -- must be running against old PostgreSQL
|
continue // No JSON/JSONB type -- must be running against old PostgreSQL
|
||||||
|
@ -246,7 +255,10 @@ func mustParseCIDR(t testing.TB, s string) *net.IPNet {
|
||||||
func TestInetCIDRTranscodeIPNet(t *testing.T) {
|
func TestInetCIDRTranscodeIPNet(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
sql string
|
sql string
|
||||||
value *net.IPNet
|
value *net.IPNet
|
||||||
|
@ -297,7 +309,10 @@ func TestInetCIDRTranscodeIPNet(t *testing.T) {
|
||||||
func TestInetCIDRTranscodeIP(t *testing.T) {
|
func TestInetCIDRTranscodeIP(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
sql string
|
sql string
|
||||||
value net.IP
|
value net.IP
|
||||||
|
@ -361,7 +376,10 @@ func TestInetCIDRTranscodeIP(t *testing.T) {
|
||||||
func TestInetCIDRArrayTranscodeIPNet(t *testing.T) {
|
func TestInetCIDRArrayTranscodeIPNet(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
sql string
|
sql string
|
||||||
value []*net.IPNet
|
value []*net.IPNet
|
||||||
|
@ -424,7 +442,10 @@ func TestInetCIDRArrayTranscodeIPNet(t *testing.T) {
|
||||||
func TestInetCIDRArrayTranscodeIP(t *testing.T) {
|
func TestInetCIDRArrayTranscodeIP(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
sql string
|
sql string
|
||||||
value []net.IP
|
value []net.IP
|
||||||
|
@ -510,7 +531,10 @@ func TestInetCIDRArrayTranscodeIP(t *testing.T) {
|
||||||
func TestInetCIDRTranscodeWithJustIP(t *testing.T) {
|
func TestInetCIDRTranscodeWithJustIP(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
sql string
|
sql string
|
||||||
value string
|
value string
|
||||||
|
@ -556,7 +580,10 @@ func TestInetCIDRTranscodeWithJustIP(t *testing.T) {
|
||||||
func TestArrayDecoding(t *testing.T) {
|
func TestArrayDecoding(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
sql string
|
sql string
|
||||||
query any
|
query any
|
||||||
|
@ -672,7 +699,10 @@ func TestArrayDecoding(t *testing.T) {
|
||||||
func TestEmptyArrayDecoding(t *testing.T) {
|
func TestEmptyArrayDecoding(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
var val []string
|
var val []string
|
||||||
|
|
||||||
err := conn.QueryRow(context.Background(), "select array[]::text[]").Scan(&val)
|
err := conn.QueryRow(context.Background(), "select array[]::text[]").Scan(&val)
|
||||||
|
@ -717,7 +747,10 @@ func TestEmptyArrayDecoding(t *testing.T) {
|
||||||
func TestPointerPointer(t *testing.T) {
|
func TestPointerPointer(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
pgxtest.SkipCockroachDB(t, conn, "Server auto converts ints to bigint and test relies on exact types")
|
pgxtest.SkipCockroachDB(t, conn, "Server auto converts ints to bigint and test relies on exact types")
|
||||||
|
|
||||||
type allTypes struct {
|
type allTypes struct {
|
||||||
|
@ -803,7 +836,10 @@ func TestPointerPointer(t *testing.T) {
|
||||||
func TestPointerPointerNonZero(t *testing.T) {
|
func TestPointerPointerNonZero(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
f := "foo"
|
f := "foo"
|
||||||
dest := &f
|
dest := &f
|
||||||
|
|
||||||
|
@ -820,7 +856,10 @@ func TestPointerPointerNonZero(t *testing.T) {
|
||||||
func TestEncodeTypeRename(t *testing.T) {
|
func TestEncodeTypeRename(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
type _int int
|
type _int int
|
||||||
inInt := _int(1)
|
inInt := _int(1)
|
||||||
var outInt _int
|
var outInt _int
|
||||||
|
@ -989,7 +1028,10 @@ func TestEncodeTypeRename(t *testing.T) {
|
||||||
func TestRowsScanNilThenScanValue(t *testing.T) {
|
func TestRowsScanNilThenScanValue(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
sql := `select null as a, null as b
|
sql := `select null as a, null as b
|
||||||
union
|
union
|
||||||
select 1, 2
|
select 1, 2
|
||||||
|
|
Loading…
Reference in New Issue