Files
traefikoidc/internal/cache/review_r149_test.go
T
lukaszraczylo 4d23d618f5 fix(cache): harden cache backends, resilience, recovery, and transports
- RESP -ERR no longer closes healthy conn / aborts batch; global cap replacement-aware
- global health-check pass serialized (latent data race); MemoryMonitor via ResourceManager
- token-exchange retry, open-circuit rejections counted as failures
- TLS-posture matching transport reuse (no silent InsecureSkipVerify handoff)
2026-08-14 16:16:51 +01:00

31 lines
1.1 KiB
Go

package cache
import (
"testing"
"time"
)
// TestCacheClose_NilStopCleanupNoPanic guards the R149 fix in Close():
// stopCleanup is only allocated when EnableAutoCleanup && CleanupInterval > 0,
// but Close() previously closed it whenever EnableAutoCleanup was set. A
// cache built with EnableAutoCleanup=true and CleanupInterval left at its
// zero value therefore called close(nil) and panicked during shutdown.
func TestCacheClose_NilStopCleanupNoPanic(t *testing.T) {
c := New(Config{EnableAutoCleanup: true}) // CleanupInterval defaults to 0
if err := c.Close(); err != nil {
t.Fatalf("Close() with CleanupInterval=0 must not panic and return nil, got: %v", err)
}
}
// TestCacheClose_WithCleanupIntervalClosesOnce ensures the normal path
// (cleanup started) still closes cleanly exactly once.
func TestCacheClose_WithCleanupIntervalClosesOnce(t *testing.T) {
c := New(Config{EnableAutoCleanup: true, CleanupInterval: time.Minute})
if err := c.Close(); err != nil {
t.Fatalf("Close() with a started cleanup goroutine must succeed, got: %v", err)
}
if err := c.Close(); err == nil {
t.Fatal("second Close() must report already-closed")
}
}