1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-29 17:41:15 +03:00

feat(pool): add check for badConnection

* fix: badConn check(#2053)

* fix: internalpool test

* fix: sentinel test

* fix: conncheck ut

* fix: remove maxBadConnRetries

* fix: add connCheck.deadline check

Signed-off-by: monkey92t <golang@88.com>
This commit is contained in:
naiqianz
2022-03-21 01:06:47 +08:00
committed by GitHub
parent f5fbb367e7
commit a8a7665ddf
10 changed files with 204 additions and 8 deletions

View File

@ -0,0 +1,48 @@
//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"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("tests conn_check with real conns", func() {
var ts *httptest.Server
var conn net.Conn
var err error
BeforeEach(func() {
ts = httptest.NewServer(nil)
conn, err = net.DialTimeout(ts.Listener.Addr().Network(), ts.Listener.Addr().String(), time.Second)
Expect(err).NotTo(HaveOccurred())
})
AfterEach(func() {
ts.Close()
})
It("good conn check", func() {
Expect(connCheck(conn)).NotTo(HaveOccurred())
Expect(conn.Close()).NotTo(HaveOccurred())
Expect(connCheck(conn)).To(HaveOccurred())
})
It("bad conn check", func() {
Expect(conn.Close()).NotTo(HaveOccurred())
Expect(connCheck(conn)).To(HaveOccurred())
})
It("check conn deadline", func() {
Expect(conn.SetDeadline(time.Now())).NotTo(HaveOccurred())
time.Sleep(time.Millisecond * 10)
Expect(connCheck(conn)).NotTo(HaveOccurred())
Expect(conn.Close()).NotTo(HaveOccurred())
})
})