2
0

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.
This commit is contained in:
Jack Christensen
2023-05-29 10:25:57 -05:00
parent 4b9aa7c4f2
commit 9f00b6f750
10 changed files with 825 additions and 325 deletions
+5 -1
View File
@@ -4,6 +4,7 @@ import (
"context"
"reflect"
"testing"
"time"
"github.com/jackc/pgx/v5"
"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)
// 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}
err := conn.QueryRow(ctx, `select cast(null as hstore)`).Scan(&h)
if err != nil {