fix(cache): resolve test failures in Gitea Actions by closing Redis clients and using IPv4 address
This commit is contained in:
40
internal/cache/store_test.go
vendored
40
internal/cache/store_test.go
vendored
@@ -12,9 +12,11 @@ import (
|
||||
// TestCacheGetSet tests basic Get and Set operations.
|
||||
func TestCacheGetSet(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
client := NewRedisClient(redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
}), metrics.New())
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "127.0.0.1:6379",
|
||||
})
|
||||
client := NewRedisClient(rdb, metrics.New())
|
||||
defer rdb.Close()
|
||||
|
||||
// Test Set
|
||||
key := &CacheKey{Kind: "city", Code: "c146"}
|
||||
@@ -88,9 +90,11 @@ func TestCacheKeyString(t *testing.T) {
|
||||
// TestCacheAsideGetOrSet tests the cache-aside GetOrSetFuncPattern.
|
||||
func TestCacheAsideGetOrSet(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
client := NewRedisClient(redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
}), metrics.New())
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "127.0.0.1:6379",
|
||||
})
|
||||
client := NewRedisClient(rdb, metrics.New())
|
||||
defer rdb.Close()
|
||||
|
||||
fetchCallCount := 0
|
||||
fetchFunc := func() ([]byte, error) {
|
||||
@@ -128,9 +132,11 @@ func TestCacheAsideGetOrSet(t *testing.T) {
|
||||
// TestCacheAsideGetCity tests GetCity with cache.
|
||||
func TestCacheAsideGetCity(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
client := NewRedisClient(redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
}), metrics.New())
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "127.0.0.1:6379",
|
||||
})
|
||||
client := NewRedisClient(rdb, metrics.New())
|
||||
defer rdb.Close()
|
||||
|
||||
fetchCallCount := 0
|
||||
fetchFunc := func() ([]byte, error) {
|
||||
@@ -167,9 +173,11 @@ func TestCacheAsideGetCity(t *testing.T) {
|
||||
// TestCacheAsideGetSearch tests GetSearch with near-term and far-term TTL.
|
||||
func TestCacheAsideGetSearch(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
client := NewRedisClient(redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
}), metrics.New())
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "127.0.0.1:6379",
|
||||
})
|
||||
client := NewRedisClient(rdb, metrics.New())
|
||||
defer rdb.Close()
|
||||
|
||||
fetchNearTerm := func() ([]byte, error) {
|
||||
return []byte(`{"near_term":true}`), nil
|
||||
@@ -205,9 +213,11 @@ func TestCacheAsideGetSearch(t *testing.T) {
|
||||
// TestCacheInvalidate tests invalidation operations.
|
||||
func TestCacheInvalidate(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
client := NewRedisClient(redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
}), metrics.New())
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "127.0.0.1:6379",
|
||||
})
|
||||
client := NewRedisClient(rdb, metrics.New())
|
||||
defer rdb.Close()
|
||||
|
||||
// Set up some keys
|
||||
cityKey := &CacheKey{Kind: "city", Code: "c146"}
|
||||
|
||||
Reference in New Issue
Block a user