mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04: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 { PassThrough } from "node:stream";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { createRestartIterationHook } from "./restart-recovery.js";
|
||||
import { spawnWithFallback } from "./spawn-utils.js";
|
||||
|
||||
function createStubChild() {
|
||||
@@ -61,3 +62,19 @@ describe("spawnWithFallback", () => {
|
||||
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