From aae929a7185065a31d565fbe6ab05cc43897af02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C5=82eczek?= Date: Wed, 1 Apr 2026 09:57:02 +0200 Subject: [PATCH] test: Schema cache load debouncing test: adjust replicateM to 100 (cherry picked from commit 328598eaedf26266b0b10400aa70e920505847ab) --- test/observability/Observation/MetricsSpec.hs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/observability/Observation/MetricsSpec.hs b/test/observability/Observation/MetricsSpec.hs index f21f71179..524e0c101 100644 --- a/test/observability/Observation/MetricsSpec.hs +++ b/test/observability/Observation/MetricsSpec.hs @@ -47,6 +47,31 @@ spec = describe "Server started with metrics enabled" $ do -- wait up to 2 secs so that retry can happen waitFor (2 * sec) "SchemaCacheLoadedObs" $ \x -> [ o | o@(SchemaCacheLoadedObs{}) <- pure x] + it "Should debounce schema cache loads" $ do + SpecState{specAppState = appState, specMetrics = metrics, specObsChan} <- getState + let waitFor = waitForObs specObsChan + + liftIO $ checkState' metrics [ + -- we expect exactly 2 successful schema cache loads + schemaCacheLoads "FAIL" (+0), + schemaCacheLoads "SUCCESS" (+2) + ] $ do + AppState.schemaCacheLoader appState + -- at this moment there is no dedicated observation emited + -- when schema cache load starts + -- so we wait for DBConnectedObs which is emited right after successful + -- PostgreSQL version query during schema cache loading + waitFor (1 * sec) "DBConnectedObs" $ \x -> [ o | o@(DBConnectedObs{}) <- pure x] + -- request schema cache load multiple times + -- all of them should be handled by a single schema cache load + replicateM_ 100 (AppState.schemaCacheLoader appState) + -- wait for two expected SchemaCacheLoadedObs events + replicateM_ 2 $ waitFor (1 * sec) "SchemaCacheLoadedObs" $ \x -> [ o | o@(SchemaCacheLoadedObs{}) <- pure x] + -- wait 1 sec to make sure we capture all potential schema cache loads + -- (there should be none but we need to verify that) + threadDelay $ 1 * sec + + where -- prometheus-client api to handle vectors is convoluted schemaCacheLoads label = expectField @"schemaCacheLoads" $