

























@@ -6,6 +6,7 @@ import path from "node:path";
66import { MAX_TIMER_TIMEOUT_MS } from "@openclaw/normalization-core/number-coercion";
77import type { Model } from "openclaw/plugin-sdk/llm";
88import { afterEach, describe, expect, it, vi } from "vitest";
9+import { killPidIfAlive, readPidFile, waitForPidToExit } from "../test-utils/process-tree.js";
910import {
1011attachModelProviderLocalService,
1112ensureModelProviderLocalService,
@@ -301,6 +302,8 @@ describe("provider local service", () => {
301302const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-local-service-restart-"));
302303const startsPath = path.join(tempDir, "starts.txt");
303304const statusPath = path.join(tempDir, "status.txt");
305+const forkedPidPath = path.join(tempDir, "forked.pid");
306+let firstForkedPid: number | undefined;
304307const model = attachModelProviderLocalService(
305308{
306309id: "demo",
@@ -312,7 +315,9 @@ describe("provider local service", () => {
312315command: process.execPath,
313316args: [
314317"-e",
315-`const fs=require("node:fs");const http=require("node:http");fs.appendFileSync(${JSON.stringify(
318+`const fs=require("node:fs");const http=require("node:http");const {spawn}=require("node:child_process");const fork=spawn(process.execPath,["-e","setInterval(() => {}, 1000)"],{stdio:"ignore"});fs.writeFileSync(${JSON.stringify(
319+ forkedPidPath,
320+ )},String(fork.pid));fs.appendFileSync(${JSON.stringify(
316321 startsPath,
317322 )},"start\\n");fs.writeFileSync(${JSON.stringify(
318323 statusPath,
@@ -330,6 +335,7 @@ describe("provider local service", () => {
330335const firstLease = await ensureModelProviderLocalService(model);
331336firstLease?.release();
332337expect((await fetch(healthUrl)).ok).toBe(true);
338+firstForkedPid = await readPidFile(forkedPidPath);
333339334340await fs.writeFile(statusPath, "down", "utf8");
335341expect((await fetch(healthUrl)).status).toBe(503);
@@ -339,11 +345,13 @@ describe("provider local service", () => {
339345throw new Error("Expected restarted provider local service lease");
340346}
341347expect((await fetch(healthUrl)).ok).toBe(true);
348+expect(await waitForPidToExit(firstForkedPid)).toBe(true);
342349secondLease.release();
343350344351const starts = (await fs.readFile(startsPath, "utf8")).trim().split("\n");
345352expect(starts).toHaveLength(2);
346353} finally {
354+killPidIfAlive(firstForkedPid);
347355await fs.rm(tempDir, { force: true, recursive: true });
348356}
349357});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。