mirror of
https://github.com/redis/go-redis.git
synced 2025-04-17 20:17:02 +03:00
* conncheck for badconn (#1821) * format imports * fix ut: pool with badconn * fix unstable ut: should facilitate failover * Revert "fix unstable ut: should facilitate failover" This reverts commit c7eeca2a5ca7cdef82cfe39b21dd781d5a286007. * fix test error Signed-off-by: monkey92t <golang@88.com> Co-authored-by: hidu <duv123+github@gmail.com> Co-authored-by: monkey92t <golang@88.com>
47 lines
947 B
Go
47 lines
947 B
Go
// +build linux darwin dragonfly freebsd netbsd openbsd solaris illumos
|
|
|
|
package pool
|
|
|
|
import (
|
|
"net"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func Test_connCheck(t *testing.T) {
|
|
// tests with real conns
|
|
ts := httptest.NewServer(nil)
|
|
defer ts.Close()
|
|
|
|
t.Run("good conn", func(t *testing.T) {
|
|
conn, err := net.DialTimeout(ts.Listener.Addr().Network(), ts.Listener.Addr().String(), time.Second)
|
|
if err != nil {
|
|
t.Fatalf(err.Error())
|
|
}
|
|
defer conn.Close()
|
|
if err = connCheck(conn); err != nil {
|
|
t.Fatalf(err.Error())
|
|
}
|
|
conn.Close()
|
|
|
|
if err = connCheck(conn); err == nil {
|
|
t.Fatalf("expect has error")
|
|
}
|
|
})
|
|
|
|
t.Run("bad conn 2", func(t *testing.T) {
|
|
conn, err := net.DialTimeout(ts.Listener.Addr().Network(), ts.Listener.Addr().String(), time.Second)
|
|
if err != nil {
|
|
t.Fatalf(err.Error())
|
|
}
|
|
defer conn.Close()
|
|
|
|
ts.Close()
|
|
|
|
if err = connCheck(conn); err == nil {
|
|
t.Fatalf("expect has err")
|
|
}
|
|
})
|
|
}
|