From 0a97c7734230a473156587fd6db00a647e98651a Mon Sep 17 00:00:00 2001 From: Algis Dumbris Date: Thu, 27 Aug 2026 20:15:22 +0300 Subject: [PATCH] test(runtime): fix racy config-watcher reload assertions TestConfigWatcher_ReloadPropagatesGlobalConfigToUpstream failed CI (run 33043282299, job 98421741995) with "expected: 99999, actual: 20000". ReloadConfiguration publishes the configsvc snapshot first (configSvc.ReloadFromFile), then syncs the legacy r.cfg, then calls upstreamManager.SetGlobalConfig. Both tests gated on the snapshot with require.Eventually and then asserted a downstream surface once, so the snapshot wait could be satisfied while the upstream manager (or legacy r.cfg) still held the old value. Poll both downstream assertions on the same 5s/25ms cadence. TestConfigWatcher_ReloadSyncsLegacyGetConfig had the identical window and is fixed alongside it. Test-only change; no production behaviour altered. Verified: go test -race -count=20 -run TestConfigWatcher ./internal/runtime --- internal/runtime/config_watcher_test.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/internal/runtime/config_watcher_test.go b/internal/runtime/config_watcher_test.go index 8dc1cdf14..adfc92c3c 100644 --- a/internal/runtime/config_watcher_test.go +++ b/internal/runtime/config_watcher_test.go @@ -273,9 +273,13 @@ func TestConfigWatcher_ReloadSyncsLegacyGetConfig(t *testing.T) { return rt.ConfigSnapshot().Config.ToolResponseLimit == 77777 }, 5*time.Second, 25*time.Millisecond, "snapshot must pick up the external edit") - legacyCfg, err := rt.GetConfig() - require.NoError(t, err) - assert.Equal(t, 77777, legacyCfg.ToolResponseLimit, + // The reload publishes the configsvc snapshot BEFORE syncing the legacy + // r.cfg, so poll here too — a bare assert right after the snapshot wait + // races with that window. + require.Eventually(t, func() bool { + legacyCfg, err := rt.GetConfig() + return err == nil && legacyCfg != nil && legacyCfg.ToolResponseLimit == 77777 + }, 5*time.Second, 25*time.Millisecond, "legacy GetConfig (backing GET/PATCH /api/v1/config) must see the reloaded config") } @@ -293,9 +297,13 @@ func TestConfigWatcher_ReloadPropagatesGlobalConfigToUpstream(t *testing.T) { return rt.ConfigSnapshot().Config.ToolResponseLimit == 99999 }, 5*time.Second, 25*time.Millisecond, "snapshot must pick up the external edit") - gc := rt.upstreamManager.GlobalConfig() - require.NotNil(t, gc) - assert.Equal(t, 99999, gc.ToolResponseLimit, + // SetGlobalConfig runs AFTER the configsvc snapshot is published, so the + // snapshot wait above does not imply the upstream manager has caught up — + // poll instead of asserting once (flaky CI run 33043282299). + require.Eventually(t, func() bool { + gc := rt.upstreamManager.GlobalConfig() + return gc != nil && gc.ToolResponseLimit == 99999 + }, 5*time.Second, 25*time.Millisecond, "watcher reload must propagate the new global config to the upstream manager") }