mirror of https://github.com/openclaw/openclaw.git
test: tighten shared pid and node parsing coverage
This commit is contained in:
parent
783d320547
commit
3a59d40109
|
|
@ -6,6 +6,7 @@ describe("shared/node-list-parse", () => {
|
|||
expect(parseNodeList({ nodes: [{ nodeId: "node-1" }] })).toEqual([{ nodeId: "node-1" }]);
|
||||
expect(parseNodeList({ nodes: "nope" })).toEqual([]);
|
||||
expect(parseNodeList(null)).toEqual([]);
|
||||
expect(parseNodeList(["not-an-object"])).toEqual([]);
|
||||
});
|
||||
|
||||
it("parses node.pair.list payloads", () => {
|
||||
|
|
@ -20,5 +21,6 @@ describe("shared/node-list-parse", () => {
|
|||
});
|
||||
expect(parsePairingList({ pending: 1, paired: "x" })).toEqual({ pending: [], paired: [] });
|
||||
expect(parsePairingList(undefined)).toEqual({ pending: [], paired: [] });
|
||||
expect(parsePairingList(["not-an-object"])).toEqual({ pending: [], paired: [] });
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -59,6 +59,21 @@ describe("isPidAlive", () => {
|
|||
expect(freshIsPidAlive(zombiePid)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
it("treats unreadable linux proc status as non-zombie when kill succeeds", async () => {
|
||||
const readFileSyncSpy = vi.spyOn(fsSync, "readFileSync").mockImplementation(() => {
|
||||
throw new Error("no proc status");
|
||||
});
|
||||
const killSpy = vi.spyOn(process, "kill").mockImplementation(() => true);
|
||||
|
||||
await withLinuxProcessPlatform(async () => {
|
||||
const { isPidAlive: freshIsPidAlive } = await import("./pid-alive.js");
|
||||
expect(freshIsPidAlive(42)).toBe(true);
|
||||
});
|
||||
|
||||
expect(readFileSyncSpy).toHaveBeenCalledWith("/proc/42/status", "utf8");
|
||||
expect(killSpy).toHaveBeenCalledWith(42, 0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getProcessStartTime", () => {
|
||||
|
|
@ -114,4 +129,19 @@ describe("getProcessStartTime", () => {
|
|||
expect(fresh(42)).toBe(55555);
|
||||
});
|
||||
});
|
||||
|
||||
it("returns null for negative or non-integer start times", async () => {
|
||||
const fakeStatPrefix = "42 (node) S 1 42 42 0 -1 4194304 12345 0 0 0 100 50 0 0 20 0 8 0 ";
|
||||
const fakeStatSuffix =
|
||||
" 123456789 5000 18446744073709551615 0 0 0 0 0 0 0 0 0 0 0 0 17 0 0 0 0 0 0";
|
||||
mockProcReads({
|
||||
"/proc/42/stat": `${fakeStatPrefix}-1${fakeStatSuffix}`,
|
||||
"/proc/43/stat": `${fakeStatPrefix}1.5${fakeStatSuffix}`,
|
||||
});
|
||||
await withLinuxProcessPlatform(async () => {
|
||||
const { getProcessStartTime: fresh } = await import("./pid-alive.js");
|
||||
expect(fresh(42)).toBeNull();
|
||||
expect(fresh(43)).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue