mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-05 16:57:06 +08:00
fix: client connection error
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/hdt3213/godis/lib/logger"
|
||||
"github.com/hdt3213/godis/redis/protocol"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestClient(t *testing.T) {
|
||||
@@ -104,3 +106,36 @@ func TestClient(t *testing.T) {
|
||||
|
||||
client.Close()
|
||||
}
|
||||
|
||||
func TestReconnect(t *testing.T) {
|
||||
logger.Setup(&logger.Settings{
|
||||
Path: "logs",
|
||||
Name: "godis",
|
||||
Ext: ".log",
|
||||
TimeFormat: "2006-01-02",
|
||||
})
|
||||
client, err := MakeClient("localhost:6379")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
client.Start()
|
||||
|
||||
_ = client.conn.Close()
|
||||
time.Sleep(time.Second) // wait for reconnecting
|
||||
success := false
|
||||
for i := 0; i < 3; i++ {
|
||||
result := client.Send([][]byte{
|
||||
[]byte("PING"),
|
||||
})
|
||||
if bytes.Equal(result.ToBytes(), []byte("+PONG\r\n")) {
|
||||
success = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !success {
|
||||
t.Error("reconnect error")
|
||||
}
|
||||
//var wg sync.WaitGroup
|
||||
//wg.Add(1)
|
||||
//wg.Wait()
|
||||
}
|
||||
|
Reference in New Issue
Block a user