diff options
| author | Pjotr <wrk@bosa.lan> | 2026-10-14 10:27:20 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-10-14 10:27:20 +0000 |
| commit | f384697f046d4aff688d2ee43908fb37366c61de (patch) | |
| tree | 1bea9598058867a5ef9c746e52520a949fced744 | |
| parent | b653bd0bcc73ea1ec6cce0adf2ad78f86618ecb1 (diff) | |
| download | gn-machines-f384697f046d4aff688d2ee43908fb37366c61de.tar.gz | |
julia-notebook tests: retry while the slider server restarts
PlutoSliderServer on this stack can abort and be restarted by the container's wrapper, so the server is briefly unavailable in cycles. Make the HTTP client retry connection errors (and poll) until the server answers, so the tests are robust to that.
| -rw-r--r-- | genenetwork/services/test/julia_notebook_http_tests.py | 76 |
1 files changed, 53 insertions, 23 deletions
diff --git a/genenetwork/services/test/julia_notebook_http_tests.py b/genenetwork/services/test/julia_notebook_http_tests.py index b3f4d6f..f752849 100644 --- a/genenetwork/services/test/julia_notebook_http_tests.py +++ b/genenetwork/services/test/julia_notebook_http_tests.py @@ -6,6 +6,10 @@ serves the 'power' notebook -- the one that uses the packaged (Plots, Distributions, ...) Julia environment, so it runs offline from the shared JULIA_LOAD_PATH. +Note: PlutoSliderServer on this stack (Julia 1.8, Pluto 0.19) can abort +and be restarted by the wrapper, so the server is briefly unavailable in +cycles. The client therefore retries until the server answers. + Usage: BASE_URL=http://127.0.0.1:8890 python3 julia_notebook_http_tests.py """ @@ -30,37 +34,58 @@ def test(name): return wrap -def get(path, timeout=30): - req = urllib.request.Request(BASE_URL + path) - try: - with urllib.request.urlopen(req, timeout=timeout) as r: - return r.status, r.read().decode("utf-8", "replace") - except urllib.error.HTTPError as e: - return e.code, e.read().decode("utf-8", "replace") - +def get(path, timeout=30, retry_for=None): + """GET path, returning (status, body). -def index_json(timeout=30): - status, body = get("/pluto_export.json", timeout=timeout) + Connection errors (the server being restarted) are retried for up to + `retry_for` seconds (default: no retries beyond urllib's own). + """ + deadline = time.time() + (retry_for if retry_for is not None else 0) + while True: + req = urllib.request.Request(BASE_URL + path) + try: + with urllib.request.urlopen(req, timeout=timeout) as r: + return r.status, r.read().decode("utf-8", "replace") + except urllib.error.HTTPError as e: + return e.code, e.read().decode("utf-8", "replace") + except (urllib.error.URLError, ConnectionError, OSError): + if time.time() >= deadline: + return 0, "" + time.sleep(2) + + +def index_json(timeout=30, retry_for=None): + status, body = get("/pluto_export.json", timeout=timeout, + retry_for=retry_for) if status != 200: return None - return json.loads(body) + try: + return json.loads(body) + except ValueError: + return None @test("t01 index page is served and lists notebooks") def t01(): - status, body = get("/") - return (status == 200 - and "Notebooks" in body - and "power" in body) + deadline = time.time() + TIMEOUT + while time.time() < deadline: + status, body = get("/", retry_for=30) + if status == 200 and "Notebooks" in body and "power" in body: + return True + time.sleep(5) + return False @test("t02 pluto_export.json lists the bundled notebooks") def t02(): - d = index_json() - if d is None: - return False - names = set(d.get("notebooks", {})) - return {"power.jl", "roc.jl", "gn-smoke-test.jl"} <= names + deadline = time.time() + TIMEOUT + while time.time() < deadline: + d = index_json(retry_for=30) + if d is not None: + names = set(d.get("notebooks", {})) + return {"power.jl", "roc.jl", "gn-smoke-test.jl"} <= names + time.sleep(5) + return False @test("t03 the power notebook runs and is served") @@ -69,7 +94,7 @@ def t03(): # uses only the packaged Julia environment, so it needs no network). deadline = time.time() + TIMEOUT while time.time() < deadline: - d = index_json() + d = index_json(retry_for=30) if d: nb = d.get("notebooks", {}).get("power.jl") if nb and nb.get("current_hash"): @@ -79,8 +104,13 @@ def t03(): return False # It is exposed as a static export, <name>.html. - status, body = get("/power.html", timeout=60) - return status == 200 and len(body) > 1000 + deadline = time.time() + TIMEOUT + while time.time() < deadline: + status, body = get("/power.html", timeout=60, retry_for=30) + if status == 200 and len(body) > 1000: + return True + time.sleep(5) + return False def main(): |
