test(portal): tolerate slow approval endpoint
This commit is contained in:
parent
2e52956155
commit
0805dbc5e9
@ -337,8 +337,26 @@ def main() -> int:
|
||||
raise SystemExit(f"failed to exchange token for portal approval as {portal_admin_username!r}: {exc}")
|
||||
|
||||
approve_url = f"{portal_base}/api/admin/access/requests/{urllib.parse.quote(username, safe='')}/approve"
|
||||
approve_resp = _request_json("POST", approve_url, portal_bearer, payload=None, timeout_s=60)
|
||||
if not isinstance(approve_resp, dict) or approve_resp.get("ok") is not True:
|
||||
approve_timeout_s = int(os.environ.get("E2E_APPROVE_TIMEOUT_SECONDS", "180"))
|
||||
approve_attempts = int(os.environ.get("E2E_APPROVE_ATTEMPTS", "3"))
|
||||
approve_resp = None
|
||||
approve_error = None
|
||||
for attempt in range(1, approve_attempts + 1):
|
||||
try:
|
||||
approve_resp = _request_json("POST", approve_url, portal_bearer, payload=None, timeout_s=approve_timeout_s)
|
||||
approve_error = None
|
||||
break
|
||||
except (http.client.RemoteDisconnected, TimeoutError, urllib.error.URLError) as exc:
|
||||
approve_error = str(exc)
|
||||
if attempt == approve_attempts:
|
||||
break
|
||||
time.sleep(3)
|
||||
if approve_resp is None:
|
||||
print(
|
||||
"WARNING: portal approval request did not return a response; "
|
||||
f"continuing to poll status (last_error={approve_error})"
|
||||
)
|
||||
elif not isinstance(approve_resp, dict) or approve_resp.get("ok") is not True:
|
||||
raise SystemExit(f"unexpected approval response: {approve_resp}")
|
||||
|
||||
status_url = f"{portal_base}/api/access/request/status"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user