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.
|
// TestCacheGetSet tests basic Get and Set operations.
|
||||||
func TestCacheGetSet(t *testing.T) {
|
func TestCacheGetSet(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
client := NewRedisClient(redis.NewClient(&redis.Options{
|
rdb := redis.NewClient(&redis.Options{
|
||||||
Addr: "localhost:6379",
|
Addr: "127.0.0.1:6379",
|
||||||
}), metrics.New())
|
})
|
||||||
|
client := NewRedisClient(rdb, metrics.New())
|
||||||
|
defer rdb.Close()
|
||||||
|
|
||||||
// Test Set
|
// Test Set
|
||||||
key := &CacheKey{Kind: "city", Code: "c146"}
|
key := &CacheKey{Kind: "city", Code: "c146"}
|
||||||
@@ -88,9 +90,11 @@ func TestCacheKeyString(t *testing.T) {
|
|||||||
// TestCacheAsideGetOrSet tests the cache-aside GetOrSetFuncPattern.
|
// TestCacheAsideGetOrSet tests the cache-aside GetOrSetFuncPattern.
|
||||||
func TestCacheAsideGetOrSet(t *testing.T) {
|
func TestCacheAsideGetOrSet(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
client := NewRedisClient(redis.NewClient(&redis.Options{
|
rdb := redis.NewClient(&redis.Options{
|
||||||
Addr: "localhost:6379",
|
Addr: "127.0.0.1:6379",
|
||||||
}), metrics.New())
|
})
|
||||||
|
client := NewRedisClient(rdb, metrics.New())
|
||||||
|
defer rdb.Close()
|
||||||
|
|
||||||
fetchCallCount := 0
|
fetchCallCount := 0
|
||||||
fetchFunc := func() ([]byte, error) {
|
fetchFunc := func() ([]byte, error) {
|
||||||
@@ -128,9 +132,11 @@ func TestCacheAsideGetOrSet(t *testing.T) {
|
|||||||
// TestCacheAsideGetCity tests GetCity with cache.
|
// TestCacheAsideGetCity tests GetCity with cache.
|
||||||
func TestCacheAsideGetCity(t *testing.T) {
|
func TestCacheAsideGetCity(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
client := NewRedisClient(redis.NewClient(&redis.Options{
|
rdb := redis.NewClient(&redis.Options{
|
||||||
Addr: "localhost:6379",
|
Addr: "127.0.0.1:6379",
|
||||||
}), metrics.New())
|
})
|
||||||
|
client := NewRedisClient(rdb, metrics.New())
|
||||||
|
defer rdb.Close()
|
||||||
|
|
||||||
fetchCallCount := 0
|
fetchCallCount := 0
|
||||||
fetchFunc := func() ([]byte, error) {
|
fetchFunc := func() ([]byte, error) {
|
||||||
@@ -167,9 +173,11 @@ func TestCacheAsideGetCity(t *testing.T) {
|
|||||||
// TestCacheAsideGetSearch tests GetSearch with near-term and far-term TTL.
|
// TestCacheAsideGetSearch tests GetSearch with near-term and far-term TTL.
|
||||||
func TestCacheAsideGetSearch(t *testing.T) {
|
func TestCacheAsideGetSearch(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
client := NewRedisClient(redis.NewClient(&redis.Options{
|
rdb := redis.NewClient(&redis.Options{
|
||||||
Addr: "localhost:6379",
|
Addr: "127.0.0.1:6379",
|
||||||
}), metrics.New())
|
})
|
||||||
|
client := NewRedisClient(rdb, metrics.New())
|
||||||
|
defer rdb.Close()
|
||||||
|
|
||||||
fetchNearTerm := func() ([]byte, error) {
|
fetchNearTerm := func() ([]byte, error) {
|
||||||
return []byte(`{"near_term":true}`), nil
|
return []byte(`{"near_term":true}`), nil
|
||||||
@@ -205,9 +213,11 @@ func TestCacheAsideGetSearch(t *testing.T) {
|
|||||||
// TestCacheInvalidate tests invalidation operations.
|
// TestCacheInvalidate tests invalidation operations.
|
||||||
func TestCacheInvalidate(t *testing.T) {
|
func TestCacheInvalidate(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
client := NewRedisClient(redis.NewClient(&redis.Options{
|
rdb := redis.NewClient(&redis.Options{
|
||||||
Addr: "localhost:6379",
|
Addr: "127.0.0.1:6379",
|
||||||
}), metrics.New())
|
})
|
||||||
|
client := NewRedisClient(rdb, metrics.New())
|
||||||
|
defer rdb.Close()
|
||||||
|
|
||||||
// Set up some keys
|
// Set up some keys
|
||||||
cityKey := &CacheKey{Kind: "city", Code: "c146"}
|
cityKey := &CacheKey{Kind: "city", Code: "c146"}
|
||||||
|
|||||||
Reference in New Issue
Block a user