Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions adapter/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package adapter
import (
"context"
"testing"
"time"

"github.com/redis/go-redis/v9"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -67,9 +68,10 @@ func TestRedis_follower_redirect_node_set_get_deleted(t *testing.T) {
assert.NoError(t, res3.Err())
assert.Equal(t, int64(1), res3.Val())

res4 := rdb.Get(ctx, string(key))
assert.Equal(t, redis.Nil, res4.Err())
assert.Equal(t, "", res4.Val())
assert.Eventually(t, func() bool {
res4 := rdb.Get(ctx, string(key))
return res4.Err() == redis.Nil && res4.Val() == ""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)

}, 2*time.Second, 50*time.Millisecond)
Comment on lines +71 to +74
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using assert.Eventually is a great way to handle potential replication delays in this test. To improve readability and maintainability, consider extracting the magic numbers for the timeout (2*time.Second) and tick interval (50*time.Millisecond) into named constants.

This makes their purpose clearer and simplifies future modifications. You could define them at the top of the test function, for example:

const (
    replicationTimeout = 2 * time.Second
    checkInterval      = 50 * time.Millisecond
)

Then, you can use these constants in the assert.Eventually call.

}

func TestRedis_leader_keys(t *testing.T) {
Expand Down
Loading