Skip to content

Commit eb238ad

Browse files
committed
test: DRY scache/config sleep in io tests
Also increase schema cache sleep to 0.2 as 0.1 tends to fail in CI.
1 parent 54786a6 commit eb238ad

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

test/io/postgrest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@
1717
from config import *
1818

1919

20+
def sleep_until_postgrest_scache_reload():
21+
"Sleep until schema cache reload"
22+
time.sleep(0.2)
23+
24+
25+
def sleep_until_postgrest_config_reload():
26+
"Sleep until config reload"
27+
time.sleep(0.1)
28+
29+
30+
def sleep_until_postgrest_full_reload():
31+
"Sleep until schema cache plus config reload"
32+
time.sleep(0.2)
33+
34+
2035
class PostgrestTimedOut(Exception):
2136
"Connecting to PostgREST endpoint timed out."
2237

test/io/test_io.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test_app_settings_flush_pool(defaultenv):
169169

170170
# SIGUSR1 causes the postgres connection pool to be flushed
171171
postgrest.process.send_signal(signal.SIGUSR1)
172-
time.sleep(0.1)
172+
sleep_until_postgrest_scache_reload()
173173

174174
uri = "/rpc/get_guc_value?name=app.settings.external_api_secret"
175175
response = postgrest.session.get(uri)
@@ -213,7 +213,7 @@ def test_app_settings_reload(tmp_path, defaultenv):
213213
# reload
214214
postgrest.process.send_signal(signal.SIGUSR2)
215215

216-
time.sleep(0.1)
216+
sleep_until_postgrest_config_reload()
217217

218218
response = postgrest.session.get(uri)
219219
assert response.text == '"Jane"'
@@ -237,7 +237,7 @@ def test_jwt_secret_reload(tmp_path, defaultenv):
237237
# reload config
238238
postgrest.process.send_signal(signal.SIGUSR2)
239239

240-
time.sleep(0.1)
240+
sleep_until_postgrest_config_reload()
241241

242242
response = postgrest.session.get("/authors_only", headers=headers)
243243
assert response.status_code == 200
@@ -267,14 +267,14 @@ def test_jwt_secret_external_file_reload(tmp_path, defaultenv):
267267

268268
# SIGUSR1 doesn't reload external files, at least when db-config=false
269269
postgrest.process.send_signal(signal.SIGUSR1)
270-
time.sleep(0.1)
270+
sleep_until_postgrest_scache_reload()
271271

272272
response = postgrest.session.get("/authors_only", headers=headers)
273273
assert response.status_code == 401
274274

275275
# reload config and external file with SIGUSR2
276276
postgrest.process.send_signal(signal.SIGUSR2)
277-
time.sleep(0.1)
277+
sleep_until_postgrest_config_reload()
278278

279279
response = postgrest.session.get("/authors_only", headers=headers)
280280
assert response.status_code == 200
@@ -285,7 +285,7 @@ def test_jwt_secret_external_file_reload(tmp_path, defaultenv):
285285
# reload config and external file with NOTIFY
286286
response = postgrest.session.post("/rpc/reload_pgrst_config")
287287
assert response.status_code == 204
288-
time.sleep(0.1)
288+
sleep_until_postgrest_config_reload()
289289

290290
response = postgrest.session.get("/authors_only", headers=headers)
291291
assert response.status_code == 401
@@ -308,11 +308,11 @@ def test_db_schema_reload(tmp_path, defaultenv):
308308

309309
# reload config
310310
postgrest.process.send_signal(signal.SIGUSR2)
311-
time.sleep(0.1)
311+
sleep_until_postgrest_config_reload()
312312

313313
# reload schema cache to verify that the config reload actually happened
314314
postgrest.process.send_signal(signal.SIGUSR1)
315-
time.sleep(0.1)
315+
sleep_until_postgrest_scache_reload()
316316

317317
response = postgrest.session.get("/rpc/get_guc_value?name=search_path")
318318
assert response.text == '"\\"v1\\", \\"public\\""'
@@ -332,7 +332,7 @@ def test_db_schema_notify_reload(defaultenv):
332332
"/rpc/change_db_schema_and_full_reload", data={"schemas": "v1"}
333333
)
334334

335-
time.sleep(0.2)
335+
sleep_until_postgrest_full_reload()
336336

337337
response = postgrest.session.get("/rpc/get_guc_value?name=search_path")
338338
assert response.text == '"\\"v1\\", \\"public\\""'
@@ -360,7 +360,7 @@ def test_max_rows_reload(defaultenv):
360360
# reload config
361361
postgrest.process.send_signal(signal.SIGUSR2)
362362

363-
time.sleep(0.1)
363+
sleep_until_postgrest_config_reload()
364364

365365
response = postgrest.session.head("/projects")
366366
assert response.status_code == 200
@@ -390,7 +390,7 @@ def test_max_rows_notify_reload(defaultenv):
390390
"/rpc/change_max_rows_config", data={"val": 1, "notify": True}
391391
)
392392

393-
time.sleep(0.1)
393+
sleep_until_postgrest_config_reload()
394394

395395
response = postgrest.session.head("/projects")
396396
assert response.status_code == 200
@@ -501,7 +501,7 @@ def test_change_statement_timeout(defaultenv, metapostgrest):
501501

502502
# trigger schema refresh
503503
postgrest.process.send_signal(signal.SIGUSR1)
504-
time.sleep(0.1)
504+
sleep_until_postgrest_scache_reload()
505505

506506
response = postgrest.session.get("/rpc/sleep?seconds=1")
507507
assert response.status_code == 500
@@ -512,7 +512,7 @@ def test_change_statement_timeout(defaultenv, metapostgrest):
512512

513513
# trigger role setting refresh
514514
postgrest.process.send_signal(signal.SIGUSR1)
515-
time.sleep(0.1)
515+
sleep_until_postgrest_scache_reload()
516516

517517
response = postgrest.session.get("/rpc/sleep?seconds=1")
518518
assert response.status_code == 204
@@ -663,7 +663,7 @@ def test_admin_ready_includes_schema_cache_state(defaultenv, metapostgrest):
663663

664664
# force a reconnection so the new role setting is picked up
665665
postgrest.process.send_signal(signal.SIGUSR1)
666-
time.sleep(0.1)
666+
sleep_until_postgrest_scache_reload()
667667

668668
response = postgrest.admin.get("/ready")
669669
assert response.status_code == 503
@@ -830,7 +830,7 @@ def test_notify_reloading_catalog_cache(defaultenv):
830830
# change it to a bigint
831831
response = postgrest.session.post("/rpc/drop_change_cats")
832832
assert response.status_code == 204
833-
time.sleep(0.1)
833+
sleep_until_postgrest_scache_reload()
834834

835835
# next request should succeed with a bigint value
836836
response = postgrest.session.get("/cats?id=eq.1")
@@ -858,7 +858,7 @@ def test_role_settings(defaultenv):
858858

859859
response = postgrest.session.get("/rpc/reload_pgrst_config")
860860
assert response.status_code == 204
861-
time.sleep(0.1)
861+
sleep_until_postgrest_config_reload()
862862

863863
response = postgrest.session.get("/rpc/get_guc_value?name=statement_timeout")
864864
assert response.text == '"5s"'

0 commit comments

Comments
 (0)