Skip to content

Commit 0f7ac1b

Browse files
committed
test: schema cache load max duration
Test to ensure no regression happens after #4396
1 parent 1ada6e6 commit 0f7ac1b

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

test/io/test_big_schema.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"IO tests for PostgREST started on the big schema."
22

3+
import re
4+
35
import pytest
46

57
from postgrest import run
@@ -57,6 +59,35 @@ def test_requests_without_resource_embedding_wait_for_schema_cache_reload(defaul
5759
)
5860

5961

62+
def test_schema_cache_load_max_duration(defaultenv):
63+
"schema cache load should not surpass a max_duration of elapsed milliseconds"
64+
65+
max_duration = 500.0
66+
67+
env = {
68+
**defaultenv,
69+
"PGRST_DB_SCHEMAS": "apflora",
70+
"PGRST_DB_POOL": "2",
71+
"PGRST_DB_ANON_ROLE": "postgrest_test_anonymous",
72+
}
73+
74+
with run(env=env, wait_max_seconds=30, no_startup_stdout=False) as postgrest:
75+
log_lines = postgrest.read_stdout(nlines=50)
76+
schema_cache_lines = [
77+
line for line in log_lines if "Schema cache loaded in" in line
78+
]
79+
80+
match = re.search(
81+
r"Schema cache loaded in ([0-9]+(?:\.[0-9])?) milliseconds",
82+
schema_cache_lines[-1],
83+
)
84+
85+
assert match, f"unexpected log format: {schema_cache_lines[-1]}"
86+
duration_ms = float(match.group(1))
87+
88+
assert duration_ms < max_duration
89+
90+
6091
# TODO: This test fails now because of https://github.com/PostgREST/postgrest/pull/2122
6192
# The stack size of 1K(-with-rtsopts=-K1K) is not enough and this fails with "stack overflow"
6293
# A stack size of 200K seems to be enough for succeess

0 commit comments

Comments
 (0)