https://github.com/jackc/pgx/issues/1847
(t *testing.T)
| 1622 | |
| 1623 | // https://github.com/jackc/pgx/issues/1847 |
| 1624 | func TestConnDeallocateInvalidatedCachedStatementsWhenCanceled(t *testing.T) { |
| 1625 | ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) |
| 1626 | defer cancel() |
| 1627 | |
| 1628 | pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { |
| 1629 | pgxtest.SkipCockroachDB(t, conn, "CockroachDB returns decimal instead of integer for integer division") |
| 1630 | |
| 1631 | var n int32 |
| 1632 | err := conn.QueryRow(ctx, "select 1 / $1::int", 1).Scan(&n) |
| 1633 | require.NoError(t, err) |
| 1634 | require.EqualValues(t, 1, n) |
| 1635 | |
| 1636 | // Divide by zero causes an error. baseRows.Close() calls Invalidate on the statement cache whenever an error was |
| 1637 | // encountered by the query. Use this to purposely invalidate the query. If we had access to private fields of conn |
| 1638 | // we could call conn.statementCache.InvalidateAll() instead. |
| 1639 | err = conn.QueryRow(ctx, "select 1 / $1::int", 0).Scan(&n) |
| 1640 | require.Error(t, err) |
| 1641 | |
| 1642 | ctx2, cancel2 := context.WithCancel(ctx) |
| 1643 | cancel2() |
| 1644 | err = conn.QueryRow(ctx2, "select 1 / $1::int", 1).Scan(&n) |
| 1645 | require.Error(t, err) |
| 1646 | require.ErrorIs(t, err, context.Canceled) |
| 1647 | |
| 1648 | err = conn.QueryRow(ctx, "select 1 / $1::int", 1).Scan(&n) |
| 1649 | require.NoError(t, err) |
| 1650 | require.EqualValues(t, 1, n) |
| 1651 | }) |
| 1652 | } |
| 1653 | |
| 1654 | // https://github.com/jackc/pgx/issues/1847 |
| 1655 | func TestConnDeallocateInvalidatedCachedStatementsInTransactionWithBatch(t *testing.T) { |
nothing calls this directly
no test coverage detected