mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-07 10:34:44 +00:00
fix(e2e): cancel ClickClack fixture bodies
This commit is contained in:
@@ -55,6 +55,7 @@ async function withClickClackFixtureResponse(url, init, consume, options = {}) {
|
||||
const controller = new AbortController();
|
||||
const timeoutError = new Error(`${url} timed out after ${timeoutMs}ms`);
|
||||
let timer;
|
||||
let response;
|
||||
const timeoutPromise = new Promise((_resolve, reject) => {
|
||||
timer = setTimeout(() => {
|
||||
controller.abort(timeoutError);
|
||||
@@ -62,7 +63,7 @@ async function withClickClackFixtureResponse(url, init, consume, options = {}) {
|
||||
}, timeoutMs);
|
||||
});
|
||||
try {
|
||||
const response = await Promise.race([
|
||||
response = await Promise.race([
|
||||
fetch(url, {
|
||||
...init,
|
||||
signal: controller.signal,
|
||||
@@ -72,6 +73,7 @@ async function withClickClackFixtureResponse(url, init, consume, options = {}) {
|
||||
return await consume(response, { timeoutPromise });
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
await response?.body?.cancel?.().catch(() => undefined);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,17 @@ async function withEnv<T>(env: Record<string, string>, callback: () => Promise<T
|
||||
}
|
||||
}
|
||||
|
||||
async function waitUntil(matches: () => boolean, label: string): Promise<void> {
|
||||
const startedAt = Date.now();
|
||||
while (Date.now() - startedAt < 1000) {
|
||||
if (matches()) {
|
||||
return;
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
}
|
||||
throw new Error(`timed out waiting for ${label}`);
|
||||
}
|
||||
|
||||
async function startTcpFixtureServer(handler: (socket: Socket) => void): Promise<{
|
||||
port: number;
|
||||
stop: () => Promise<void>;
|
||||
@@ -303,6 +314,33 @@ describe("release user journey assertions", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("cancels successful ClickClack inbound response bodies", async () => {
|
||||
const root = mkdtempSync(path.join(tmpdir(), "openclaw-release-user-assertions-"));
|
||||
const home = path.join(root, "home");
|
||||
let socketClosed = false;
|
||||
const server = await startTcpFixtureServer((socket) => {
|
||||
socket.on("close", () => {
|
||||
socketClosed = true;
|
||||
});
|
||||
socket.write("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nleft-open");
|
||||
});
|
||||
|
||||
try {
|
||||
await expect(
|
||||
withEnv({ HOME: home, OPENCLAW_RELEASE_USER_JOURNEY_HTTP_TIMEOUT_MS: "1000" }, () =>
|
||||
runReleaseUserJourneyAssertion("post-clickclack-inbound", [
|
||||
`http://127.0.0.1:${server.port}`,
|
||||
"hello",
|
||||
]),
|
||||
),
|
||||
).resolves.toBeUndefined();
|
||||
await waitUntil(() => socketClosed, "ClickClack inbound socket close");
|
||||
} finally {
|
||||
await server.stop();
|
||||
rmSync(root, { force: true, recursive: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("bounds stalled ClickClack fixture HTTP probes", async () => {
|
||||
const root = mkdtempSync(path.join(tmpdir(), "openclaw-release-user-assertions-"));
|
||||
const home = path.join(root, "home");
|
||||
|
||||
Reference in New Issue
Block a user