Skip to content

Commit

Permalink
Merge pull request #926 from lib/ping-empty
Browse files Browse the repository at this point in the history
allow ping during a failed txn
  • Loading branch information
maddyblue authored Dec 11, 2019
2 parents d7918e3 + e3ef896 commit 9927457
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion conn_go18.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (cn *conn) Ping(ctx context.Context) error {
if finish := cn.watchCancel(ctx); finish != nil {
defer finish()
}
rows, err := cn.simpleQuery("SELECT 'lib/pq ping test';")
rows, err := cn.simpleQuery(";")
if err != nil {
return driver.ErrBadConn // https://golang.org/pkg/database/sql/driver/#Pinger
}
Expand Down
7 changes: 7 additions & 0 deletions go19_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ func TestPing(t *testing.T) {
if rows.Err() != nil {
t.Fatal(err)
}
// Fail the transaction and make sure we can still ping.
if _, err := tx.Query("INVALID SQL"); err == nil {
t.Fatal("expected error")
}
if err := conn.PingContext(ctx); err != nil {
t.Fatal(err)
}
if err := tx.Rollback(); err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 9927457

Please sign in to comment.