(t *testing.T)
| 4705 | } |
| 4706 | |
| 4707 | func TestDeadlineContextWatcherHandler(t *testing.T) { |
| 4708 | t.Parallel() |
| 4709 | |
| 4710 | t.Run("DeadlineExceeded with zero DeadlineDelay", func(t *testing.T) { |
| 4711 | config, err := pgconn.ParseConfig(os.Getenv("PGX_TEST_DATABASE")) |
| 4712 | require.NoError(t, err) |
| 4713 | config.BuildContextWatcherHandler = func(conn *pgconn.PgConn) ctxwatch.Handler { |
| 4714 | return &pgconn.DeadlineContextWatcherHandler{Conn: conn.Conn()} |
| 4715 | } |
| 4716 | config.ConnectTimeout = 5 * time.Second |
| 4717 | |
| 4718 | pgConn, err := pgconn.ConnectConfig(context.Background(), config) |
| 4719 | require.NoError(t, err) |
| 4720 | defer closeConn(t, pgConn) |
| 4721 | |
| 4722 | ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond) |
| 4723 | defer cancel() |
| 4724 | |
| 4725 | _, err = pgConn.Exec(ctx, "select 1, pg_sleep(1)").ReadAll() |
| 4726 | require.Error(t, err) |
| 4727 | require.ErrorIs(t, err, context.DeadlineExceeded) |
| 4728 | require.True(t, pgConn.IsClosed()) |
| 4729 | }) |
| 4730 | |
| 4731 | t.Run("DeadlineExceeded with DeadlineDelay", func(t *testing.T) { |
| 4732 | config, err := pgconn.ParseConfig(os.Getenv("PGX_TEST_DATABASE")) |
| 4733 | require.NoError(t, err) |
| 4734 | config.BuildContextWatcherHandler = func(conn *pgconn.PgConn) ctxwatch.Handler { |
| 4735 | return &pgconn.DeadlineContextWatcherHandler{Conn: conn.Conn(), DeadlineDelay: 500 * time.Millisecond} |
| 4736 | } |
| 4737 | config.ConnectTimeout = 5 * time.Second |
| 4738 | |
| 4739 | pgConn, err := pgconn.ConnectConfig(context.Background(), config) |
| 4740 | require.NoError(t, err) |
| 4741 | defer closeConn(t, pgConn) |
| 4742 | |
| 4743 | ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) |
| 4744 | defer cancel() |
| 4745 | |
| 4746 | _, err = pgConn.Exec(ctx, "select 1, pg_sleep(0.250)").ReadAll() |
| 4747 | require.NoError(t, err) |
| 4748 | |
| 4749 | ensureConnValid(t, pgConn) |
| 4750 | }) |
| 4751 | } |
| 4752 | |
| 4753 | func TestCancelRequestContextWatcherHandler(t *testing.T) { |
| 4754 | t.Parallel() |
nothing calls this directly
no test coverage detected