2023-07-13 04:22:52 +00:00
|
|
|
package adapter_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
2023-07-22 06:30:31 +00:00
|
|
|
"time"
|
2023-07-13 04:22:52 +00:00
|
|
|
|
2023-07-22 06:30:31 +00:00
|
|
|
"github.com/cenkalti/backoff/v4"
|
2023-07-13 04:22:52 +00:00
|
|
|
"github.com/redis/go-redis/v9"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newRedisClient(tb testing.TB) *redis.Client {
|
|
|
|
tb.Helper()
|
|
|
|
|
2023-07-17 06:45:30 +00:00
|
|
|
opts, err := redis.ParseURL(redisConnectionString)
|
2023-07-13 04:22:52 +00:00
|
|
|
require.NoError(tb, err, "couldn't parse redis connection string")
|
|
|
|
|
|
|
|
client := redis.NewClient(opts)
|
|
|
|
tb.Cleanup(func() {
|
|
|
|
_ = client.Close()
|
|
|
|
})
|
2023-07-22 06:30:31 +00:00
|
|
|
|
|
|
|
bo := backoff.NewExponentialBackOff()
|
|
|
|
bo.MaxInterval = time.Second * 5
|
|
|
|
bo.MaxElapsedTime = 30 * time.Second
|
|
|
|
require.NoError(tb, backoff.Retry(func() error {
|
2023-07-13 04:22:52 +00:00
|
|
|
return client.Ping(context.Background()).Err()
|
2023-07-22 06:30:31 +00:00
|
|
|
}, bo), "couldn't ping DB")
|
2023-07-13 04:22:52 +00:00
|
|
|
|
|
|
|
return client
|
|
|
|
}
|