From 6e0ed332506d4e4a01784bac544c36d4d1df95ad Mon Sep 17 00:00:00 2001 From: hidu Date: Fri, 16 Jul 2021 17:02:39 +0800 Subject: [PATCH] fix ut: pool with badconn --- main_test.go | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/main_test.go b/main_test.go index 0cb2b1d4..17d76972 100644 --- a/main_test.go +++ b/main_test.go @@ -12,10 +12,10 @@ import ( "testing" "time" - "github.com/go-redis/redis/v8" - . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + + "github.com/go-redis/redis/v8" ) const ( @@ -117,7 +117,7 @@ func TestGinkgoSuite(t *testing.T) { RunSpecs(t, "go-redis") } -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ func redisOptions() *redis.Options { return &redis.Options{ @@ -364,7 +364,7 @@ func startSentinel(port, masterName, masterPort string) (*redisProcess, error) { return p, nil } -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ type badConnError string @@ -373,14 +373,28 @@ func (e badConnError) Timeout() bool { return true } func (e badConnError) Temporary() bool { return false } type badConn struct { - net.TCPConn - readDelay, writeDelay time.Duration readErr, writeErr error } var _ net.Conn = &badConn{} +func (cn *badConn) Close() error { + return nil +} + +func (cn *badConn) LocalAddr() net.Addr { + return &net.TCPAddr{} +} + +func (cn *badConn) RemoteAddr() net.Addr { + return &net.TCPAddr{} +} + +func (cn *badConn) SetDeadline(t time.Time) error { + return nil +} + func (cn *badConn) SetReadDeadline(t time.Time) error { return nil } @@ -409,7 +423,7 @@ func (cn *badConn) Write([]byte) (int, error) { return 0, badConnError("bad connection") } -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ type hook struct { beforeProcess func(ctx context.Context, cmd redis.Cmder) (context.Context, error)