Skip to content

Commit 6e0ed33

Browse files
author
hidu
committed
fix ut: pool with badconn
1 parent 78875ec commit 6e0ed33

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

main_test.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import (
1212
"testing"
1313
"time"
1414

15-
"github.com/go-redis/redis/v8"
16-
1715
. "github.com/onsi/ginkgo"
1816
. "github.com/onsi/gomega"
17+
18+
"github.com/go-redis/redis/v8"
1919
)
2020

2121
const (
@@ -117,7 +117,7 @@ func TestGinkgoSuite(t *testing.T) {
117117
RunSpecs(t, "go-redis")
118118
}
119119

120-
//------------------------------------------------------------------------------
120+
// ------------------------------------------------------------------------------
121121

122122
func redisOptions() *redis.Options {
123123
return &redis.Options{
@@ -364,7 +364,7 @@ func startSentinel(port, masterName, masterPort string) (*redisProcess, error) {
364364
return p, nil
365365
}
366366

367-
//------------------------------------------------------------------------------
367+
// ------------------------------------------------------------------------------
368368

369369
type badConnError string
370370

@@ -373,14 +373,28 @@ func (e badConnError) Timeout() bool { return true }
373373
func (e badConnError) Temporary() bool { return false }
374374

375375
type badConn struct {
376-
net.TCPConn
377-
378376
readDelay, writeDelay time.Duration
379377
readErr, writeErr error
380378
}
381379

382380
var _ net.Conn = &badConn{}
383381

382+
func (cn *badConn) Close() error {
383+
return nil
384+
}
385+
386+
func (cn *badConn) LocalAddr() net.Addr {
387+
return &net.TCPAddr{}
388+
}
389+
390+
func (cn *badConn) RemoteAddr() net.Addr {
391+
return &net.TCPAddr{}
392+
}
393+
394+
func (cn *badConn) SetDeadline(t time.Time) error {
395+
return nil
396+
}
397+
384398
func (cn *badConn) SetReadDeadline(t time.Time) error {
385399
return nil
386400
}
@@ -409,7 +423,7 @@ func (cn *badConn) Write([]byte) (int, error) {
409423
return 0, badConnError("bad connection")
410424
}
411425

412-
//------------------------------------------------------------------------------
426+
// ------------------------------------------------------------------------------
413427

414428
type hook struct {
415429
beforeProcess func(ctx context.Context, cmd redis.Cmder) (context.Context, error)

0 commit comments

Comments
 (0)