test: Refactor invalid_role_claim_key_notify_reload test to properly read all available input

This commit is contained in:
Wolfgang Walther
2022-06-03 22:19:16 -05:00
committed by Steve Chavez
parent 06a9794448
commit e8e3349a71
+20 -7
View File
@@ -156,15 +156,23 @@ def run(configpath=None, stdin=None, env=None, port=None):
command.append(configpath)
process = subprocess.Popen(
command, stdin=subprocess.PIPE, stderr=subprocess.PIPE, env=env
command,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
env=env,
)
os.set_blocking(process.stdout.fileno(), False)
try:
process.stdin.write(stdin or b"")
process.stdin.close()
wait_until_ready(baseurl)
process.stdout.read()
yield PostgrestProcess(process=process, session=PostgrestSession(baseurl))
finally:
process.terminate()
@@ -694,17 +702,22 @@ def test_invalid_role_claim_key_notify_reload(defaultenv):
**defaultenv,
"PGRST_DB_CONFIG": "true",
"PGRST_DB_CHANNEL_ENABLED": "true",
"PGRST_LOG_LEVEL": "crit",
}
with run(env=env) as postgrest:
postgrest.session.post("/rpc/invalid_role_claim_key_reload")
# skips the first lines from stderr, the "Attempting to connect to database", "Connection successful", etc.
# this is a hack to avoid readline() from locking up the test
for _ in range(6):
postgrest.process.stderr.readline()
assert "failed to parse role-claim-key value" in str(
postgrest.process.stderr.readline()
output = None
for _ in range(10):
output = postgrest.process.stdout.readline()
if output:
break
time.sleep(0.1)
assert (
"failed to parse role-claim-key value"
in output.decode()
)
postgrest.session.post("/rpc/reset_invalid_role_claim_key")