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

Function TestConnExecPreparedCanceled

pgconn/pgconn_test.go:1545–1575  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1543}
1544
1545func TestConnExecPreparedCanceled(t *testing.T) {
1546 t.Parallel()
1547
1548 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
1549 defer cancel()
1550
1551 pgConn, err := pgconn.Connect(ctx, os.Getenv("PGX_TEST_DATABASE"))
1552 require.NoError(t, err)
1553 defer closeConn(t, pgConn)
1554
1555 _, err = pgConn.Prepare(ctx, "ps1", "select current_database(), pg_sleep(1)", nil)
1556 require.NoError(t, err)
1557
1558 ctx, cancel = context.WithTimeout(ctx, 100*time.Millisecond)
1559 defer cancel()
1560 result := pgConn.ExecPrepared(ctx, "ps1", nil, nil, nil)
1561 rowCount := 0
1562 for result.NextRow() {
1563 rowCount += 1
1564 }
1565 assert.Equal(t, 0, rowCount)
1566 commandTag, err := result.Close()
1567 assert.Equal(t, pgconn.CommandTag{}, commandTag)
1568 assert.True(t, pgconn.Timeout(err))
1569 assert.True(t, pgConn.IsClosed())
1570 select {
1571 case <-pgConn.CleanupDone():
1572 case <-time.After(5 * time.Second):
1573 t.Fatal("Connection cleanup exceeded maximum time")
1574 }
1575}
1576
1577func TestConnExecPreparedPrecanceled(t *testing.T) {
1578 t.Parallel()

Callers

nothing calls this directly

Calls 9

ConnectFunction · 0.92
TimeoutFunction · 0.92
NextRowMethod · 0.80
CleanupDoneMethod · 0.80
closeConnFunction · 0.70
PrepareMethod · 0.65
CloseMethod · 0.65
ExecPreparedMethod · 0.45
IsClosedMethod · 0.45

Tested by

no test coverage detected