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
+12 -3
View File
@@ -39,7 +39,10 @@ func TestRowScanner(t *testing.T) {
func TestForEachRow(t *testing.T) {
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
rows, _ := conn.Query(
@@ -67,7 +70,10 @@ func TestForEachRow(t *testing.T) {
func TestForEachRowScanError(t *testing.T) {
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
rows, _ := conn.Query(
@@ -88,7 +94,10 @@ func TestForEachRowScanError(t *testing.T) {
func TestForEachRowAbort(t *testing.T) {
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(
context.Background(),
"select n, n * 2 from generate_series(1, $1) n",