Skip to content

Commit c18ea58

Browse files
authored
test: scale container daemon regression deadlines (#132406)
* test: scale container daemon regression deadlines * test: expect resolved default account in gateway sends
1 parent cb7eecd commit c18ea58

2 files changed

Lines changed: 41 additions & 5 deletions

File tree

‎src/gateway/server-methods/send.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4564,7 +4564,7 @@ describe("gateway send mirroring", () => {
45644564
expect(mocks.deliverOutboundPayloads).toHaveBeenCalledOnce();
45654565
expect(deliveryCall()).toMatchObject({
45664566
to: testCase.expectedTarget,
4567-
accountId: testCase.accountId,
4567+
accountId: testCase.accountId ?? "default",
45684568
payloads: [
45694569
expect.objectContaining({ text: testCase.nativeDeclines ? "prepared hello" : "hello" }),
45704570
],

‎src/node-host/node-worker-supervisor.container.test.ts‎

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import fs from "node:fs";
33
import path from "node:path";
44
import { afterEach, describe, expect, it, vi } from "vitest";
55
import { useAutoCleanupTempDirTracker } from "../../test/helpers/temp-dir.js";
6+
import * as processExec from "../process/exec.js";
67
import { closeOpenClawStateDatabaseForTest } from "../state/openclaw-state-db.js";
78
import type { WorkerConnectionEndpoint } from "../worker/worker-connection-endpoint.js";
89
import { NodeWorkerContainerLifecycle } from "./node-worker-container-lifecycle.js";
@@ -33,6 +34,7 @@ const endpoint: WorkerConnectionEndpoint = {
3334
const hostLabel = "openclaw.node-worker.host";
3435
const gatewayLabel = "openclaw.node-worker.gateway";
3536
const launchLabel = "openclaw.node-worker.launch";
37+
const DAEMON_TIMER_SCALE = 5;
3638

3739
type FakeContainer = {
3840
id: string;
@@ -151,6 +153,36 @@ function containerFixture(
151153
};
152154
}
153155

156+
function delayDaemonRevalidation(fixture: ReturnType<typeof containerFixture>, delayMs: number) {
157+
fs.writeFileSync(
158+
path.join(fixture.engineRoot, "info-delay-ms"),
159+
String(delayMs / DAEMON_TIMER_SCALE),
160+
);
161+
const requestedTimeouts: number[] = [];
162+
const runExec = processExec.runExec;
163+
vi.spyOn(processExec, "runExec").mockImplementation((command, args, options) => {
164+
if (
165+
command === fixture.containerEngine.command &&
166+
args.length === 3 &&
167+
args[0] === "info" &&
168+
args[1] === "--format" &&
169+
args[2] === "{{.ID}}" &&
170+
typeof options === "object" &&
171+
typeof options.timeoutMs === "number"
172+
) {
173+
// Scale both sides so the old five-second deadline still loses to the
174+
// six-second response. Execa, process signals, and other commands stay real.
175+
requestedTimeouts.push(options.timeoutMs);
176+
return runExec(command, args, {
177+
...options,
178+
timeoutMs: options.timeoutMs / DAEMON_TIMER_SCALE,
179+
});
180+
}
181+
return runExec(command, args, options);
182+
});
183+
return requestedTimeouts;
184+
}
185+
154186
async function waitForWorkerStarted(workspaceDir: string): Promise<void> {
155187
await vi.waitFor(
156188
() => expect(fs.existsSync(path.join(workspaceDir, "worker-started"))).toBe(true),
@@ -438,12 +470,12 @@ describe("node worker supervisor container isolation", () => {
438470
});
439471

440472
it(
441-
"launches after a busy daemon takes six seconds to revalidate",
473+
"launches when daemon revalidation outlasts the discovery timeout",
442474
{ timeout: 15_000 },
443475
async () => {
444476
const fixture = containerFixture();
445477
const input = testWorkerLaunchInput(fixture.workspaceDir, "container-busy-daemon");
446-
fs.writeFileSync(path.join(fixture.engineRoot, "info-delay-ms"), "6000");
478+
const requestedTimeouts = delayDaemonRevalidation(fixture, 6_000);
447479

448480
try {
449481
expect(await fixture.supervisor.launch(input, endpoint)).toMatchObject({
@@ -452,6 +484,7 @@ describe("node worker supervisor container isolation", () => {
452484
expect(await waitForTerminal(fixture.supervisor, input.launchId)).toMatchObject({
453485
state: "completed",
454486
});
487+
expect(requestedTimeouts).toEqual([30_000]);
455488
} finally {
456489
await fixture.supervisor.close();
457490
}
@@ -464,13 +497,16 @@ describe("node worker supervisor container isolation", () => {
464497
async () => {
465498
const fixture = containerFixture();
466499
const input = testWorkerLaunchInput(fixture.workspaceDir, "container-unresponsive-daemon");
467-
fs.writeFileSync(path.join(fixture.engineRoot, "info-delay-ms"), "35000");
500+
const requestedTimeouts = delayDaemonRevalidation(fixture, 35_000);
468501

469502
try {
470503
const failed = await fixture.supervisor.launch(input, endpoint);
471504

472505
expect(failed.state).toBe("failed");
473-
expect(failed.errorText).toMatch(/Command timed out after \d+ milliseconds:/u);
506+
expect(requestedTimeouts).toEqual([30_000]);
507+
expect(failed.errorText).toContain(
508+
`Command timed out after ${30_000 / DAEMON_TIMER_SCALE} milliseconds:`,
509+
);
474510
expect(failed.errorText).toContain("docker info --format '{{.ID}}'");
475511
expect(await fixture.supervisor.status(input.launchId)).toMatchObject({
476512
state: "failed",

0 commit comments

Comments
 (0)