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

Function TestConnSendBatchWithPreparedStatementAndStatementCacheDisabled

batch_test.go:427–486  ·  view source on GitHub ↗

https://github.com/jackc/pgx/issues/856

(t *testing.T)

Source from the content-addressed store, hash-verified

425
426// https://github.com/jackc/pgx/issues/856
427func TestConnSendBatchWithPreparedStatementAndStatementCacheDisabled(t *testing.T) {
428 t.Parallel()
429
430 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
431 defer cancel()
432
433 config, err := pgx.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
434 require.NoError(t, err)
435
436 config.DefaultQueryExecMode = pgx.QueryExecModeDescribeExec
437 config.StatementCacheCapacity = 0
438 config.DescriptionCacheCapacity = 0
439
440 conn := mustConnect(t, config)
441 defer closeConn(t, conn)
442
443 pgxtest.SkipCockroachDB(t, conn, "Server issues incorrect ParameterDescription (https://github.com/cockroachdb/cockroach/issues/60907)")
444
445 _, err = conn.Prepare(ctx, "ps1", "select n from generate_series(0,$1::int) n")
446 if err != nil {
447 t.Fatal(err)
448 }
449
450 batch := &pgx.Batch{}
451
452 queryCount := 3
453 for range queryCount {
454 batch.Queue("ps1", 5)
455 }
456
457 br := conn.SendBatch(ctx, batch)
458
459 for range queryCount {
460 rows, err := br.Query()
461 if err != nil {
462 t.Fatal(err)
463 }
464
465 for k := 0; rows.Next(); k++ {
466 var n int
467 if err := rows.Scan(&n); err != nil {
468 t.Fatal(err)
469 }
470 if n != k {
471 t.Fatalf("n => %v, want %v", n, k)
472 }
473 }
474
475 if rows.Err() != nil {
476 t.Fatal(rows.Err())
477 }
478 }
479
480 err = br.Close()
481 if err != nil {
482 t.Fatal(err)
483 }
484

Callers

nothing calls this directly

Calls 12

QueueMethod · 0.95
SkipCockroachDBFunction · 0.92
mustConnectFunction · 0.70
closeConnFunction · 0.70
ensureConnValidFunction · 0.70
PrepareMethod · 0.65
SendBatchMethod · 0.65
QueryMethod · 0.65
NextMethod · 0.65
ScanMethod · 0.65
ErrMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected