From d9e192f31fd2ff4c43a3c87afac25ee965d7190e Mon Sep 17 00:00:00 2001 From: Cristian Magherusan-Stanciu Date: Fri, 16 Oct 2026 12:57:24 +0200 Subject: [PATCH] test(scheduler): kick the stale refresh with an unrestricted reader #938 rewrote the stale-cache tests around staleListRecommendations, which reads through a plain context.Background(). #932 (a86c6d72) made ListRecommendations kick a cold-start or stale-cache collection only when ctx carries WithBackgroundCollection (scheduler.go mayCollect), so the two merged without a textual conflict but the positive test never saw a refresh and timed out on main. Mark the helper's ctx with WithBackgroundCollection, as the #932 tests do. This also keeps the TTL==0 sentinel test meaningful: with an unmarked ctx it could never refresh and would pass vacuously. Removing the TTL==0 guard now fails it. Co-Authored-By: Claude Opus 5.5 --- internal/scheduler/scheduler_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/scheduler/scheduler_test.go b/internal/scheduler/scheduler_test.go index 571cbf477..08caf29a5 100644 --- a/internal/scheduler/scheduler_test.go +++ b/internal/scheduler/scheduler_test.go @@ -942,10 +942,12 @@ func TestScheduler_ListRecommendations(t *testing.T) { // ListRecommendations with the given RecommendationsCacheStaleHours. The first // GetGlobalConfig call (the TTL resolution) succeeds; any later call can only // come from the background refresh's CollectRecommendations, so it signals the -// returned channel and fails, which ends the refresh immediately. +// returned channel and fails, which ends the refresh immediately. The read +// runs as an unrestricted reader (WithBackgroundCollection), the only caller +// allowed to kick a refresh; without it neither TTL case could ever refresh. func staleListRecommendations(t *testing.T, staleHours int) <-chan struct{} { t.Helper() - ctx := context.Background() + ctx := WithBackgroundCollection(context.Background()) mockStore := new(MockConfigStore) old := time.Now().Add(-72 * time.Hour)