Skip to content

Commit

Permalink
test: more leak detections
Browse files Browse the repository at this point in the history
Signed-off-by: Rueian <[email protected]>
  • Loading branch information
rueian committed Jun 20, 2024
1 parent 5f7e158 commit 63951b5
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func TestNewSingleClientReplicaOnlyNotSupported(t *testing.T) {
}

func TestNewSingleClientError(t *testing.T) {
defer ShouldNotLeaked(SetupLeakDetection())
v := errors.New("dail err")
if _, err := newSingleClient(&ClientOption{InitAddress: []string{""}}, nil, func(dst string, opt *ClientOption) conn {
return &mockConn{DialFn: func() error { return v }}
Expand All @@ -211,6 +212,7 @@ func TestNewSingleClientError(t *testing.T) {
}

func TestNewSingleClientOverride(t *testing.T) {
defer ShouldNotLeaked(SetupLeakDetection())
m1 := &mockConn{}
var m2 conn
if _, err := newSingleClient(&ClientOption{InitAddress: []string{""}}, m1, func(dst string, opt *ClientOption) conn {
Expand All @@ -225,6 +227,7 @@ func TestNewSingleClientOverride(t *testing.T) {

//gocyclo:ignore
func TestSingleClient(t *testing.T) {
defer ShouldNotLeaked(SetupLeakDetection())
m := &mockConn{
AddrFn: func() string { return "myaddr" },
}
Expand Down Expand Up @@ -587,6 +590,7 @@ func TestSingleClient(t *testing.T) {
}

func TestSingleClientRetry(t *testing.T) {
defer ShouldNotLeaked(SetupLeakDetection())
SetupClientRetry(t, func(m *mockConn) Client {
c, err := newSingleClient(&ClientOption{InitAddress: []string{""}}, m, func(dst string, opt *ClientOption) conn {
return m
Expand Down
1 change: 1 addition & 0 deletions cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4333,6 +4333,7 @@ func TestClusterShardsParsing(t *testing.T) {

// https://github.com/redis/rueidis/issues/543
func TestConnectToNonAvailableCluster(t *testing.T) {
defer ShouldNotLeaked(SetupLeakDetection())
var wg sync.WaitGroup
for i := 0; i < 4; i++ {
wg.Add(1)
Expand Down
10 changes: 10 additions & 0 deletions message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1873,6 +1873,9 @@ func TestRedisMessage(t *testing.T) {
if ret, _ := (RedisResult{val: RedisMessage{typ: '*', values: []RedisMessage{{string: "0", typ: '+'}, {typ: '_'}}}}).AsScanEntry(); !reflect.DeepEqual(ScanEntry{}, ret) {
t.Fatal("AsScanEntry not get value as expected")
}
if _, err := (RedisResult{val: RedisMessage{typ: '*', values: []RedisMessage{{string: "0", typ: '+'}}}}).AsScanEntry(); err == nil || !strings.Contains(err.Error(), "a scan response or its length is not at least 2") {
t.Fatal("AsScanEntry not get value as expected")
}
})

t.Run("ToMap with non-string key", func(t *testing.T) {
Expand All @@ -1883,6 +1886,13 @@ func TestRedisMessage(t *testing.T) {
if !strings.Contains(err.Error(), "redis message type set is not a RESP3 map") {
t.Fatalf("ToMap failed with unexpected error: %v", err)
}
_, err = (&RedisMessage{typ: '%', values: []RedisMessage{{typ: ':'}, {typ: ':'}}}).ToMap()
if err == nil {
t.Fatal("ToMap did not fail as expected")
}
if !strings.Contains(err.Error(), "int64 as map key is not supported") {
t.Fatalf("ToMap failed with unexpected error: %v", err)
}
})

t.Run("IsCacheHit", func(t *testing.T) {
Expand Down
Loading

0 comments on commit 63951b5

Please sign in to comment.