1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-31 05:04:23 +03:00

hotfix/v8_conn_pool_check_fd (#2431)

This commit is contained in:
hardeyhe
2023-02-09 23:01:02 +08:00
committed by GitHub
parent c888488a7a
commit f7b3619c8b
9 changed files with 199 additions and 11 deletions

View File

@ -0,0 +1,47 @@
//go:build linux || darwin || dragonfly || freebsd || netbsd || openbsd || solaris || illumos
// +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")
}
})
}