@@ -184,24 +184,26 @@ async def test_postgresql_parameters_change(ops_test: OpsTest) -> None:
184184 for unit_id in UNIT_IDS :
185185 host = await get_unit_address (ops_test , f"{ APP_NAME } /{ unit_id } " )
186186 logger .info ("connecting to the database host: %s" , host )
187- with psycopg2 .connect (
188- f"dbname='postgres' user='operator' host='{ host } ' password='{ password } ' connect_timeout=1"
189- ) as connection , connection .cursor () as cursor :
190- settings_names = ["max_prepared_transactions" , "shared_buffers" , "lc_monetary" ]
191- cursor .execute (
192- sql .SQL ("SELECT name,setting FROM pg_settings WHERE name IN ({});" ).format (
193- sql .SQL (", " ).join (sql .Placeholder () * len (settings_names ))
194- ),
195- settings_names ,
196- )
197- records = cursor .fetchall ()
198- settings = convert_records_to_dict (records )
199- connection .close ()
200-
201- # Validate each configuration set by Patroni on PostgreSQL.
202- assert settings ["max_prepared_transactions" ] == "100"
203- assert settings ["shared_buffers" ] == "128"
204- assert settings ["lc_monetary" ] == "en_GB.utf8"
187+ try :
188+ with psycopg2 .connect (
189+ f"dbname='postgres' user='operator' host='{ host } ' password='{ password } ' connect_timeout=1"
190+ ) as connection , connection .cursor () as cursor :
191+ settings_names = ["max_prepared_transactions" , "shared_buffers" , "lc_monetary" ]
192+ cursor .execute (
193+ sql .SQL ("SELECT name,setting FROM pg_settings WHERE name IN ({});" ).format (
194+ sql .SQL (", " ).join (sql .Placeholder () * len (settings_names ))
195+ ),
196+ settings_names ,
197+ )
198+ records = cursor .fetchall ()
199+ settings = convert_records_to_dict (records )
200+
201+ # Validate each configuration set by Patroni on PostgreSQL.
202+ assert settings ["max_prepared_transactions" ] == "100"
203+ assert settings ["shared_buffers" ] == "128"
204+ assert settings ["lc_monetary" ] == "en_GB.utf8"
205+ finally :
206+ connection .close ()
205207
206208
207209@pytest .mark .group (1 )
0 commit comments