fix(cache): resolve test failures in Gitea Actions by closing Redis clients and using IPv4 address
Some checks failed
CI / test (push) Failing after 1m15s
CI / build (push) Has been skipped
CI / docker (push) Has been skipped
CI / lint (push) Successful in 13s

This commit is contained in:
2026-08-20 18:12:09 +03:00
parent ca8b137e55
commit 65deb2e55c

View File

@@ -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"}