Skip to content

Commit

Permalink
fix#479
Browse files Browse the repository at this point in the history
  • Loading branch information
chenfuqian committed Nov 1, 2018
1 parent 351912f commit 91e6172
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
12 changes: 8 additions & 4 deletions backend/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,19 @@ func (db *DB) Ping() error {
if db.checkConn == nil {
db.checkConn, err = db.newConn()
if err != nil {
db.checkConn.Close()
db.checkConn = nil
if db.checkConn != nil {
db.checkConn.Close()
db.checkConn = nil
}
return err
}
}
err = db.checkConn.Ping()
if err != nil {
db.checkConn.Close()
db.checkConn = nil
if db.checkConn != nil{
db.checkConn.Close()
db.checkConn = nil
}
return err
}
return nil
Expand Down
16 changes: 16 additions & 0 deletions backend/db_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package backend

import (
. "github.com/flike/kingshard/backend"

"testing"
)

func TestDB_Ping(t *testing.T) {
db, err := Open("127.0.0.1:3306", "root", "", "kingshard", 1)
if err != nil {
t.Fatal(err)
}
defer db.Close()
db.Ping()
}

0 comments on commit 91e6172

Please sign in to comment.