mirror of https://github.com/jackc/pgx.git
Extract connection dead on server test
parent
24193ee322
commit
a9e7e3acbc
11
conn_test.go
11
conn_test.go
|
@ -872,16 +872,7 @@ func TestExecContextCancelationCancelsQuery(t *testing.T) {
|
|||
t.Fatal("Expected context.Canceled err, got %v", err)
|
||||
}
|
||||
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
checkConn := mustConnect(t, *defaultConnConfig)
|
||||
defer closeConn(t, checkConn)
|
||||
|
||||
var found bool
|
||||
err = checkConn.QueryRow("select true from pg_stat_activity where pid=$1", conn.Pid).Scan(&found)
|
||||
if err != pgx.ErrNoRows {
|
||||
t.Fatal("Expected context canceled connection to be disconnected from server, but it wasn't")
|
||||
}
|
||||
ensureConnDeadOnServer(t, conn, *defaultConnConfig)
|
||||
}
|
||||
|
||||
func TestPrepare(t *testing.T) {
|
||||
|
|
|
@ -21,7 +21,6 @@ func mustReplicationConnect(t testing.TB, config pgx.ConnConfig) *pgx.Replicatio
|
|||
return conn
|
||||
}
|
||||
|
||||
|
||||
func closeConn(t testing.TB, conn *pgx.Conn) {
|
||||
err := conn.Close()
|
||||
if err != nil {
|
||||
|
@ -72,3 +71,19 @@ func ensureConnValid(t *testing.T, conn *pgx.Conn) {
|
|||
t.Error("Wrong values returned")
|
||||
}
|
||||
}
|
||||
|
||||
func ensureConnDeadOnServer(t *testing.T, conn *pgx.Conn, config pgx.ConnConfig) {
|
||||
checkConn := mustConnect(t, config)
|
||||
defer closeConn(t, checkConn)
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
var found bool
|
||||
err := checkConn.QueryRow("select true from pg_stat_activity where pid=$1", conn.Pid).Scan(&found)
|
||||
if err == pgx.ErrNoRows {
|
||||
return
|
||||
} else if err != nil {
|
||||
t.Fatalf("Unable to check if conn is dead on server: %v", err)
|
||||
}
|
||||
}
|
||||
t.Fatal("Expected conn to be disconnected from server, but it wasn't")
|
||||
}
|
||||
|
|
|
@ -1513,14 +1513,7 @@ func TestQueryContextCancelationCancelsQuery(t *testing.T) {
|
|||
t.Fatal("Expected context.Canceled error, got %v", rows.Err())
|
||||
}
|
||||
|
||||
checkConn := mustConnect(t, *defaultConnConfig)
|
||||
defer closeConn(t, checkConn)
|
||||
|
||||
var found bool
|
||||
err = checkConn.QueryRow("select true from pg_stat_activity where pid=$1", conn.Pid).Scan(&found)
|
||||
if err != pgx.ErrNoRows {
|
||||
t.Fatal("Expected context canceled connection to be disconnected from server, but it wasn't")
|
||||
}
|
||||
ensureConnDeadOnServer(t, conn, *defaultConnConfig)
|
||||
}
|
||||
|
||||
func TestQueryRowContextSuccess(t *testing.T) {
|
||||
|
@ -1580,12 +1573,5 @@ func TestQueryRowContextCancelationCancelsQuery(t *testing.T) {
|
|||
t.Fatal("Expected context.Canceled error, got %v", err)
|
||||
}
|
||||
|
||||
checkConn := mustConnect(t, *defaultConnConfig)
|
||||
defer closeConn(t, checkConn)
|
||||
|
||||
var found bool
|
||||
err = checkConn.QueryRow("select true from pg_stat_activity where pid=$1", conn.Pid).Scan(&found)
|
||||
if err != pgx.ErrNoRows {
|
||||
t.Fatal("Expected context canceled connection to be disconnected from server, but it wasn't")
|
||||
}
|
||||
ensureConnDeadOnServer(t, conn, *defaultConnConfig)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue