test: Refactor invalid_role_claim_key_notify_reload test to properly read all available input
This commit is contained in:
committed by
Steve Chavez
parent
06a9794448
commit
e8e3349a71
@@ -156,15 +156,23 @@ def run(configpath=None, stdin=None, env=None, port=None):
|
|||||||
command.append(configpath)
|
command.append(configpath)
|
||||||
|
|
||||||
process = subprocess.Popen(
|
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:
|
try:
|
||||||
process.stdin.write(stdin or b"")
|
process.stdin.write(stdin or b"")
|
||||||
process.stdin.close()
|
process.stdin.close()
|
||||||
|
|
||||||
wait_until_ready(baseurl)
|
wait_until_ready(baseurl)
|
||||||
|
|
||||||
|
process.stdout.read()
|
||||||
|
|
||||||
yield PostgrestProcess(process=process, session=PostgrestSession(baseurl))
|
yield PostgrestProcess(process=process, session=PostgrestSession(baseurl))
|
||||||
finally:
|
finally:
|
||||||
process.terminate()
|
process.terminate()
|
||||||
@@ -694,17 +702,22 @@ def test_invalid_role_claim_key_notify_reload(defaultenv):
|
|||||||
**defaultenv,
|
**defaultenv,
|
||||||
"PGRST_DB_CONFIG": "true",
|
"PGRST_DB_CONFIG": "true",
|
||||||
"PGRST_DB_CHANNEL_ENABLED": "true",
|
"PGRST_DB_CHANNEL_ENABLED": "true",
|
||||||
|
"PGRST_LOG_LEVEL": "crit",
|
||||||
}
|
}
|
||||||
|
|
||||||
with run(env=env) as postgrest:
|
with run(env=env) as postgrest:
|
||||||
postgrest.session.post("/rpc/invalid_role_claim_key_reload")
|
postgrest.session.post("/rpc/invalid_role_claim_key_reload")
|
||||||
|
|
||||||
# skips the first lines from stderr, the "Attempting to connect to database", "Connection successful", etc.
|
output = None
|
||||||
# this is a hack to avoid readline() from locking up the test
|
for _ in range(10):
|
||||||
for _ in range(6):
|
output = postgrest.process.stdout.readline()
|
||||||
postgrest.process.stderr.readline()
|
if output:
|
||||||
assert "failed to parse role-claim-key value" in str(
|
break
|
||||||
postgrest.process.stderr.readline()
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
assert (
|
||||||
|
"failed to parse role-claim-key value"
|
||||||
|
in output.decode()
|
||||||
)
|
)
|
||||||
|
|
||||||
postgrest.session.post("/rpc/reset_invalid_role_claim_key")
|
postgrest.session.post("/rpc/reset_invalid_role_claim_key")
|
||||||
|
|||||||
Reference in New Issue
Block a user