fix(e2e): browser drivers fail fast instead of hanging
test_legend_toggle_e2e hung 900 s in Firefox during the 032-063 run and passed on rerun: bidi.mjs and cdp.mjs waited for every reply without a deadline, and neither a closed socket nor a browser exit after start ever rejected a waiting command. The new tests/e2e/driver.mjs gives each command 240 s and names it on timeout, and fails every waiting command when the socket closes or the browser exits; both drivers use it, along with its plan reading. tests/test_e2e_drivers.py runs both drivers against a fake browser that dies while a command waits: 4.5 s now, a 60 s timeout on the old drivers. The two-browser legend e2e is green on the new drivers. The Firefox stall itself is still unexplained; the next one fails with the command's name. 🎯 Fix: 95 % 💥 Break: 3 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 92 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0fece7664a
commit
156e9a1e83
4 files changed
+133
-48
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import {readFileSync} from "node:fs";
|
||||
|
||||
const ANSWER_MS = 240000;
|
||||
|
||||
// Returns {binary, plan}: the browser binary and the parsed plan.json named by the driver's two arguments.
|
||||
export function readPlan() {
|
||||
const [binary, planFile] = process.argv.slice(2);
|
||||
return {binary, plan: JSON.parse(readFileSync(planFile, "utf8"))};
|
||||
}
|
||||
|
||||
// Args: socket an open WebSocket to the browser; browser its spawned process; label names the protocol in errors;
|
||||
// failure(data) returns the Error a reply carries, else null; event(data) sees every message.
|
||||
// Returns call({method, ...}): sends it with a fresh id and resolves with the reply's result; it rejects on an error
|
||||
// reply, after ANSWER_MS without one, or once the socket closes or the browser exits.
|
||||
export function connect(socket, browser, label, failure, event) {
|
||||
const waiting = new Map();
|
||||
let next = 0;
|
||||
const failAll = (why) => {
|
||||
for (const {reject} of waiting.values()) {
|
||||
reject(new Error(why));
|
||||
}
|
||||
waiting.clear();
|
||||
};
|
||||
socket.onclose = () => failAll(`${label} socket closed`);
|
||||
browser.on("exit", (code) => failAll(`browser exited with ${code}`));
|
||||
socket.onmessage = (message) => {
|
||||
const data = JSON.parse(message.data);
|
||||
event(data);
|
||||
if (data.id && waiting.has(data.id)) {
|
||||
const {resolve, reject} = waiting.get(data.id);
|
||||
waiting.delete(data.id);
|
||||
const error = failure(data);
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(data.result);
|
||||
}
|
||||
}
|
||||
};
|
||||
return (payload) => {
|
||||
next += 1;
|
||||
const id = next;
|
||||
socket.send(JSON.stringify({id, ...payload}));
|
||||
return new Promise((resolve, reject) => {
|
||||
const timer = setTimeout(() => {
|
||||
waiting.delete(id);
|
||||
reject(new Error(`${payload.method} got no answer within ${ANSWER_MS} ms`));
|
||||
}, ANSWER_MS);
|
||||
const settle = (finish) => (value) => {
|
||||
clearTimeout(timer);
|
||||
finish(value);
|
||||
};
|
||||
waiting.set(id, {resolve: settle(resolve), reject: settle(reject)});
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user