MCPcopy
hub / github.com/jackc/pgx / TestRawValuesUnderlyingMemoryReused

Function TestRawValuesUnderlyingMemoryReused

conn_test.go:1592–1621  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1590}
1591
1592func TestRawValuesUnderlyingMemoryReused(t *testing.T) {
1593 defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
1594 var buf []byte
1595
1596 rows, err := conn.Query(ctx, `select 1::int`)
1597 require.NoError(t, err)
1598
1599 for rows.Next() {
1600 buf = rows.RawValues()[0]
1601 }
1602
1603 require.NoError(t, rows.Err())
1604
1605 original := make([]byte, len(buf))
1606 copy(original, buf)
1607
1608 for i := range 1_000_000 {
1609 rows, err := conn.Query(ctx, `select $1::int`, i)
1610 require.NoError(t, err)
1611 rows.Close()
1612 require.NoError(t, rows.Err())
1613
1614 if !bytes.Equal(original, buf) {
1615 return
1616 }
1617 }
1618
1619 t.Fatal("expected buffer from RawValues to be overwritten by subsequent queries but it was not")
1620 })
1621}
1622
1623// https://github.com/jackc/pgx/issues/1847
1624func TestConnDeallocateInvalidatedCachedStatementsWhenCanceled(t *testing.T) {

Callers

nothing calls this directly

Calls 6

RunTestMethod · 0.80
QueryMethod · 0.65
NextMethod · 0.65
RawValuesMethod · 0.65
ErrMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected