diff --git a/internal/imgcache/eviction_internal_test.go b/internal/imgcache/eviction_internal_test.go index cbc2b5c..5b51f18 100644 --- a/internal/imgcache/eviction_internal_test.go +++ b/internal/imgcache/eviction_internal_test.go @@ -1077,6 +1077,30 @@ func TestReconciliationWalksStopOnceCancelled(t *testing.T) { } } +// TestReconciliationPassLogsNoWarningOnceCancelled checks that a +// reconciliation pass run with an already cancelled context logs no +// warning, so a periodic tick the loop takes after a stop adds no +// warning to the one from the pass the stop interrupted. +func TestReconciliationPassLogsNoWarningOnceCancelled(t *testing.T) { + t.Parallel() + + cache, _ := newEvictionTestCache(t, 1<<30) + + var logBuf bytes.Buffer + + cache.log = slog.New(slog.NewJSONHandler(&logBuf, nil)) + + ctx, cancel := context.WithCancel(t.Context()) + cancel() + + cache.runReconciliationPass(ctx) + t.Logf("log output: %s", logBuf.String()) + + if strings.Contains(logBuf.String(), `"level":"WARN"`) { + t.Errorf("runReconciliationPass logged a warning with a cancelled context") + } +} + // TestEvictSourceBlobExcludesConcurrentStoreOfIdenticalContent exercises // the exact TOCTOU window between evictSourceBlob's row-deletion // transaction commit and its content file unlink: a concurrent