From 747c78f6f491983b53cfb784cb71119799dd2a2b Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Thu, 9 May 2024 09:19:31 +0200 Subject: [PATCH] test: Prevent test_admin_ready_includes_schema_cache_state from timing out By increasing the delays in this test by factor 400x, postgrest will not swamp pg with connection retries after the failed schema cache anymore. This would happen because there is no backoff included after fatal errors. Once it does, the io tests hang indefinitely in CI. --- src/PostgREST/SchemaCache.hs | 6 +++--- test/io/test_io.py | 13 ++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/PostgREST/SchemaCache.hs b/src/PostgREST/SchemaCache.hs index 055d02a7c..0c30e7623 100644 --- a/src/PostgREST/SchemaCache.hs +++ b/src/PostgREST/SchemaCache.hs @@ -145,6 +145,9 @@ type SqlQuery = ByteString querySchemaCache :: AppConfig -> SQL.Transaction SchemaCache querySchemaCache AppConfig{..} = do + _ <- + let sleepCall = SQL.Statement "select pg_sleep($1 / 1000.0)" (param HE.int4) HD.noResult prepared in + whenJust configInternalSCSleep (`SQL.statement` sleepCall) -- only used for testing SQL.sql "set local schema ''" -- This voids the search path. The following queries need this for getting the fully qualified name(schema.name) of every db object pgVer <- SQL.statement mempty $ pgVersionStatement prepared tabs <- SQL.statement schemas $ allTables pgVer prepared @@ -155,9 +158,6 @@ querySchemaCache AppConfig{..} = do reps <- SQL.statement schemas $ dataRepresentations prepared mHdlers <- SQL.statement schemas $ mediaHandlers pgVer prepared tzones <- SQL.statement mempty $ timezones prepared - _ <- - let sleepCall = SQL.Statement "select pg_sleep($1)" (param HE.int4) HD.noResult prepared in - whenJust configInternalSCSleep (`SQL.statement` sleepCall) -- only used for testing let tabsWViewsPks = addViewPrimaryKeys tabs keyDeps rels = addInverseRels $ addM2MRels tabsWViewsPks $ addViewM2OAndO2ORels keyDeps m2oRels diff --git a/test/io/test_io.py b/test/io/test_io.py index 289be9fa9..e825841aa 100644 --- a/test/io/test_io.py +++ b/test/io/test_io.py @@ -710,20 +710,23 @@ def test_admin_ready_includes_schema_cache_state(defaultenv, metapostgrest): **defaultenv, "PGUSER": role, "PGRST_DB_ANON_ROLE": role, + "PGRST_INTERNAL_SCHEMA_CACHE_SLEEP": "500", } with run(env=env) as postgrest: - # make it impossible to load the schema cache, by setting statement timeout to 1ms - set_statement_timeout(metapostgrest, role, 1) + # The schema cache query takes at least 500ms, due do PGRST_INTERNAL_SCHEMA_CACHE_SLEEP above. + # Make it impossible to load the schema cache, by setting statement timeout to 400ms. + set_statement_timeout(metapostgrest, role, 400) # force a reconnection so the new role setting is picked up postgrest.process.send_signal(signal.SIGUSR1) - sleep_until_postgrest_scache_reload() + # wait 600ms to finish schema cache reload attempt + time.sleep(0.6) - response = postgrest.admin.get("/ready") + response = postgrest.admin.get("/ready", timeout=1) assert response.status_code == 503 - response = postgrest.session.get("/projects") + response = postgrest.session.get("/projects", timeout=1) assert response.status_code == 503 reset_statement_timeout(metapostgrest, role)