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

Function TestConnSendBatchCloseRowsPartiallyRead

batch_test.go:488–546  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

486}
487
488func TestConnSendBatchCloseRowsPartiallyRead(t *testing.T) {
489 t.Parallel()
490
491 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
492 defer cancel()
493
494 pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
495 batch := &pgx.Batch{}
496 batch.Queue("select n from generate_series(0,5) n")
497 batch.Queue("select n from generate_series(0,5) n")
498
499 br := conn.SendBatch(ctx, batch)
500
501 rows, err := br.Query()
502 if err != nil {
503 t.Error(err)
504 }
505
506 for i := range 3 {
507 if !rows.Next() {
508 t.Error("expected a row to be available")
509 }
510
511 var n int
512 if err := rows.Scan(&n); err != nil {
513 t.Error(err)
514 }
515 if n != i {
516 t.Errorf("n => %v, want %v", n, i)
517 }
518 }
519
520 rows.Close()
521
522 rows, err = br.Query()
523 if err != nil {
524 t.Error(err)
525 }
526
527 for i := 0; rows.Next(); i++ {
528 var n int
529 if err := rows.Scan(&n); err != nil {
530 t.Error(err)
531 }
532 if n != i {
533 t.Errorf("n => %v, want %v", n, i)
534 }
535 }
536
537 if rows.Err() != nil {
538 t.Error(rows.Err())
539 }
540
541 err = br.Close()
542 if err != nil {
543 t.Fatal(err)
544 }
545 })

Callers

nothing calls this directly

Calls 9

QueueMethod · 0.95
RunWithQueryExecModesFunction · 0.92
SendBatchMethod · 0.65
QueryMethod · 0.65
NextMethod · 0.65
ScanMethod · 0.65
CloseMethod · 0.65
ErrMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected