mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 10:51:37 +00:00
perf(test): fold restart recovery helper into spawn utils suite
This commit is contained in:
@@ -1,18 +0,0 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
|
||||||
import { createRestartIterationHook } from "./restart-recovery.js";
|
|
||||||
|
|
||||||
describe("restart-recovery", () => {
|
|
||||||
it("skips recovery on first iteration and runs on subsequent iterations", () => {
|
|
||||||
const onRestart = vi.fn();
|
|
||||||
const onIteration = createRestartIterationHook(onRestart);
|
|
||||||
|
|
||||||
expect(onIteration()).toBe(false);
|
|
||||||
expect(onRestart).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
expect(onIteration()).toBe(true);
|
|
||||||
expect(onRestart).toHaveBeenCalledTimes(1);
|
|
||||||
|
|
||||||
expect(onIteration()).toBe(true);
|
|
||||||
expect(onRestart).toHaveBeenCalledTimes(2);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -2,6 +2,7 @@ import type { ChildProcess } from "node:child_process";
|
|||||||
import { EventEmitter } from "node:events";
|
import { EventEmitter } from "node:events";
|
||||||
import { PassThrough } from "node:stream";
|
import { PassThrough } from "node:stream";
|
||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
import { createRestartIterationHook } from "./restart-recovery.js";
|
||||||
import { spawnWithFallback } from "./spawn-utils.js";
|
import { spawnWithFallback } from "./spawn-utils.js";
|
||||||
|
|
||||||
function createStubChild() {
|
function createStubChild() {
|
||||||
@@ -61,3 +62,19 @@ describe("spawnWithFallback", () => {
|
|||||||
expect(spawnMock).toHaveBeenCalledTimes(1);
|
expect(spawnMock).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("restart-recovery", () => {
|
||||||
|
it("skips recovery on first iteration and runs on subsequent iterations", () => {
|
||||||
|
const onRestart = vi.fn();
|
||||||
|
const onIteration = createRestartIterationHook(onRestart);
|
||||||
|
|
||||||
|
expect(onIteration()).toBe(false);
|
||||||
|
expect(onRestart).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
expect(onIteration()).toBe(true);
|
||||||
|
expect(onRestart).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
|
expect(onIteration()).toBe(true);
|
||||||
|
expect(onRestart).toHaveBeenCalledTimes(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user