forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(redis): go-redis v9 regression missing metrics and reconnect hook (…
…argoproj#13415) (argoproj#15275) * fix(redis): go-redis v9 regression missing metrics and reconnect hook Signed-off-by: phanama <[email protected]> * fix: golangci lint return values not checked in tests Signed-off-by: phanama <[email protected]> * chore: move dnsError var locally into func Signed-off-by: phanama <[email protected]> --------- Signed-off-by: phanama <[email protected]>
- Loading branch information
Showing
5 changed files
with
146 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,53 @@ | ||
package cache | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
"time" | ||
|
||
"github.com/alicebob/miniredis/v2" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/redis/go-redis/v9" | ||
) | ||
|
||
func Test_ReconnectCallbackHookCalled(t *testing.T) { | ||
mr, err := miniredis.Run() | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer mr.Close() | ||
|
||
called := false | ||
hook := NewArgoRedisHook(func() { | ||
called = true | ||
}) | ||
|
||
cmd := &redis.StringCmd{} | ||
cmd.SetErr(errors.New("Failed to resync revoked tokens. retrying again in 1 minute: dial tcp: lookup argocd-redis on 10.179.0.10:53: no such host")) | ||
|
||
_ = hook.AfterProcess(context.Background(), cmd) | ||
faultyDNSRedisClient := redis.NewClient(&redis.Options{Addr: "invalidredishost.invalid:12345"}) | ||
faultyDNSRedisClient.AddHook(hook) | ||
|
||
faultyDNSClient := NewRedisCache(faultyDNSRedisClient, 60*time.Second, RedisCompressionNone) | ||
err = faultyDNSClient.Set(&Item{Key: "baz", Object: "foo"}) | ||
assert.Equal(t, called, true) | ||
assert.Error(t, err) | ||
} | ||
|
||
func Test_ReconnectCallbackHookNotCalled(t *testing.T) { | ||
mr, err := miniredis.Run() | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer mr.Close() | ||
|
||
called := false | ||
hook := NewArgoRedisHook(func() { | ||
called = true | ||
}) | ||
cmd := &redis.StringCmd{} | ||
cmd.SetErr(errors.New("Something wrong")) | ||
|
||
_ = hook.AfterProcess(context.Background(), cmd) | ||
redisClient := redis.NewClient(&redis.Options{Addr: mr.Addr()}) | ||
redisClient.AddHook(hook) | ||
client := NewRedisCache(redisClient, 60*time.Second, RedisCompressionNone) | ||
|
||
err = client.Set(&Item{Key: "foo", Object: "bar"}) | ||
assert.Equal(t, called, false) | ||
assert.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters