fix: client connection error

This commit is contained in:
finley
2022-07-03 17:56:30 +08:00
parent 380d936ed5
commit 45edbdd7c7
2 changed files with 72 additions and 33 deletions

View File

@@ -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()
}