From 3923ce5db92a41999cc2b55cb2dbc2bbc6ae95cd Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Fri, 20 Nov 2026 11:05:45 -0500 Subject: [PATCH] fix(e2e): wait on the photon fixture's own ready line, not its files The fixture wrote its two endpoints to files and the test polled for both to exist. A file exists before its content is written, so the test could read an empty endpoint, and a fixture that died left the test polling out its 10 s as "fixture failed to bind" (CI on 7878d6103 failed two photon cases that way, with no output from node). The fixture now prints both endpoints on one stdout line once both servers listen, and the test waits on the pipe. The wait reports a line written before its deadline however late the test thread runs, and a fixture that exits first fails at once with its status. Binding took 0.15 s idle and at most 0.83 s with 3 copies of the file on 2 CPUs beside a Gleam suite, so the 10 s bound stays. --- e2e/fixtures/photon/server.cjs | 17 ++++++++++++----- e2e/photon_test.py | 26 +++++++++++++++++++------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/e2e/fixtures/photon/server.cjs b/e2e/fixtures/photon/server.cjs index 71e4c0d2e..9952fbf24 100644 --- a/e2e/fixtures/photon/server.cjs +++ b/e2e/fixtures/photon/server.cjs @@ -173,6 +173,14 @@ server.addService(defs.MessageService.service, { }); }, }); +// Both endpoints go out on one stdout line once both listen: the test waits +// on that line, which also ends at once if this process dies first. +const bound = {}; +function announce() { + if (bound.address && bound.cloud) { + process.stdout.write(JSON.stringify(bound) + "\n"); + } +} const key = fs.readFileSync(path.join(__dirname, "localhost.key")); const cert = fs.readFileSync(path.join(__dirname, "localhost.pem")); server.bindAsync( @@ -182,7 +190,8 @@ server.bindAsync( ]), (err, port) => { if (err) throw err; - fs.writeFileSync(path.join(state, "address"), "127.0.0.1:" + port); + bound.address = "127.0.0.1:" + port; + announce(); }, ); @@ -234,8 +243,6 @@ const cloud = http.createServer(async (request, response) => { .end(JSON.stringify({ succeed: true, data })); }); cloud.listen(0, "127.0.0.1", () => { - fs.writeFileSync( - path.join(state, "cloud"), - `http://127.0.0.1:${cloud.address().port}`, - ); + bound.cloud = `http://127.0.0.1:${cloud.address().port}`; + announce(); }); diff --git a/e2e/photon_test.py b/e2e/photon_test.py index 94a2ecd46..eca5067a2 100644 --- a/e2e/photon_test.py +++ b/e2e/photon_test.py @@ -3,6 +3,7 @@ import base64 import json from pathlib import Path +import selectors import shutil import subprocess import threading @@ -51,20 +52,31 @@ class PhotonTests(unittest.TestCase): helper = shutil.which("albedo-photon") assert helper is not None, "the development shell must provide albedo-photon" server = subprocess.Popen( - ["node", FIXTURE / "server.cjs", Path(helper).resolve(), app.root] + ["node", FIXTURE / "server.cjs", Path(helper).resolve(), app.root], + stdout=subprocess.PIPE, + text=True, ) + output = server.stdout + assert output is not None + self.addCleanup(output.close) self.addCleanup(server.wait) self.addCleanup(server.terminate) - address = app.root / "address" - cloud = app.root / "cloud" - wait_until( - lambda: address.exists() and cloud.exists(), 10, "fixture failed to bind" - ) + # The fixture prints both endpoints once both listen. A wait on the + # pipe sees a line written before the deadline even when this thread + # runs again only after it, and ends at once if the fixture dies. + with selectors.DefaultSelector() as pipe: + pipe.register(output, selectors.EVENT_READ) + if not pipe.select(10): + raise AssertionError("fixture did not bind in 10 s") + line = output.readline() + if not line: + raise AssertionError(f"fixture exited with {server.wait()} before binding") + bound = json.loads(line) app.env.update( SSL_CERT_FILE=str(FIXTURE / "localhost.pem"), NIX_SSL_CERT_FILE=str(FIXTURE / "localhost.pem"), ) - return address.read_text(), cloud.read_text() + return bound["address"], bound["cloud"] def test_text_and_resume(self): provider = Provider(self.respond) -- knotmirror 0.0.1