Fix dropping schema cache reload notifications
* test: bad schema reload * refactor: DRY using the "extra" lib * refactor: move worker funtions inside AppState * Also rename Workers.hs to Admin.hs
This commit is contained in:
+39
-1
@@ -551,7 +551,7 @@ def test_pool_size(defaultenv, metapostgrest):
|
||||
|
||||
|
||||
def test_pool_acquisition_timeout(defaultenv, metapostgrest):
|
||||
"Verify that PGRST_DB_POOL_ACQUISITON_TIMEOUT times out when the pool is empty"
|
||||
"Verify that PGRST_DB_POOL_ACQUISITION_TIMEOUT times out when the pool is empty"
|
||||
|
||||
env = {
|
||||
**defaultenv,
|
||||
@@ -946,6 +946,44 @@ def test_isolation_level(defaultenv):
|
||||
assert response.text == '"serializable"'
|
||||
|
||||
|
||||
def test_schema_cache_reloading(defaultenv):
|
||||
"schema cache should reload successfully"
|
||||
|
||||
# If DB_POOL=1, then the second request(/rpc/migrate_function) will just wait(PGRST_DB_POOL_ACQUISITION_TIMEOUT=10) for the schema cache reload to finish.
|
||||
# This is bc the only pool connection will be busy with the PGRST_INTERNAL_SCHEMA_CACHE_SLEEP(does a pg_sleep)
|
||||
# So this must be tested with a DB_POOL size of at least 2. That way the second request will pick the other pool connection and proceed.
|
||||
|
||||
env = {
|
||||
**defaultenv,
|
||||
"PGRST_INTERNAL_SCHEMA_CACHE_SLEEP": "1",
|
||||
"PGRST_DB_CHANNEL_ENABLED": "true",
|
||||
"PGRST_DB_POOL": "2",
|
||||
}
|
||||
|
||||
internal_sleep = int(env["PGRST_INTERNAL_SCHEMA_CACHE_SLEEP"])
|
||||
|
||||
with run(env=env, wait_for_readiness=False) as postgrest:
|
||||
time.sleep(2 * internal_sleep + 0.1) # wait for readiness manually
|
||||
|
||||
response = postgrest.session.post("/rpc/create_function")
|
||||
assert response.status_code == 204
|
||||
|
||||
time.sleep(
|
||||
internal_sleep / 2
|
||||
) # wait to be inside the schema cache reload process
|
||||
|
||||
response = postgrest.session.post("/rpc/migrate_function")
|
||||
assert response.status_code == 204
|
||||
|
||||
time.sleep(
|
||||
2 * internal_sleep
|
||||
) # wait enough time to ensure the schema cache state remains
|
||||
|
||||
response = postgrest.session.get("/rpc/mult_them?c=3&d=4")
|
||||
assert response.text == "12"
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
# TODO: This test fails now because of https://github.com/PostgREST/postgrest/pull/2122
|
||||
# The stack size of 1K(-with-rtsopts=-K1K) is not enough and this fails with "stack overflow"
|
||||
# A stack size of 200K seems to be enough for succeess
|
||||
|
||||
Reference in New Issue
Block a user