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

Function TestFatalRxError

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

Source from the content-addressed store, hash-verified

840}
841
842func TestFatalRxError(t *testing.T) {
843 t.Parallel()
844
845 conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
846 defer closeConn(t, conn)
847
848 pgxtest.SkipCockroachDB(t, conn, "Server does not support pg_terminate_backend() (https://github.com/cockroachdb/cockroach/issues/35897)")
849
850 var wg sync.WaitGroup
851 wg.Go(func() {
852 var n int32
853 var s string
854 err := conn.QueryRow(context.Background(), "select 1::int4, pg_sleep(10)::varchar").Scan(&n, &s)
855 if pgErr, ok := err.(*pgconn.PgError); ok && pgErr.Severity == "FATAL" {
856 } else {
857 t.Errorf("Expected QueryRow Scan to return fatal PgError, but instead received %v", err)
858 return
859 }
860 })
861
862 otherConn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
863 defer otherConn.Close(context.Background())
864
865 if _, err := otherConn.Exec(context.Background(), "select pg_terminate_backend($1)", conn.PgConn().PID()); err != nil {
866 t.Fatalf("Unable to kill backend PostgreSQL process: %v", err)
867 }
868
869 wg.Wait()
870
871 if !conn.IsClosed() {
872 t.Fatal("Connection should be closed")
873 }
874}
875
876func TestFatalTxError(t *testing.T) {
877 t.Parallel()

Callers

nothing calls this directly

Calls 10

SkipCockroachDBFunction · 0.92
mustConnectStringFunction · 0.85
PIDMethod · 0.80
PgConnMethod · 0.80
closeConnFunction · 0.70
ScanMethod · 0.65
QueryRowMethod · 0.65
CloseMethod · 0.65
ExecMethod · 0.65
IsClosedMethod · 0.45

Tested by

no test coverage detected