























@@ -32,6 +32,9 @@ describe("gateway --force helpers", () => {
3232originalKill = process.kill.bind(process);
3333originalPlatform = process.platform;
3434tryListenOnPortMock.mockReset();
35+tryListenOnPortMock.mockRejectedValue(
36+Object.assign(new Error("in use"), { code: "EADDRINUSE" }),
37+);
3538// Pin to linux so all lsof tests are platform-invariant.
3639Object.defineProperty(process, "platform", { value: "linux", configurable: true });
3740});
@@ -59,12 +62,8 @@ describe("gateway --force helpers", () => {
5962expect(listPortListeners(18789)).toEqual([]);
6063});
616462-it("does not re-scan lsof when no listeners were killed", async () => {
63-(execFileSync as unknown as Mock).mockImplementation(() => {
64-const err = new Error("no matches") as NodeJS.ErrnoException & { status?: number };
65-err.status = 1; // lsof uses exit 1 for no matches
66-throw err;
67-});
65+it("skips lsof when the port is already bindable", async () => {
66+tryListenOnPortMock.mockResolvedValue(undefined);
68676968const result = await forceFreePortAndWait(18789, { timeoutMs: 500, intervalMs: 100 });
7069@@ -73,7 +72,7 @@ describe("gateway --force helpers", () => {
7372waitedMs: 0,
7473escalatedToSigkill: false,
7574});
76-expect(execFileSync).toHaveBeenCalledOnce();
75+expect(execFileSync).not.toHaveBeenCalled();
7776});
78777978it("throws when lsof missing", () => {
@@ -181,7 +180,9 @@ describe("gateway --force helpers", () => {
181180}
182181return "18789/tcp: 4242\n";
183182});
184-tryListenOnPortMock.mockResolvedValue(undefined);
183+tryListenOnPortMock
184+.mockRejectedValueOnce(Object.assign(new Error("in use"), { code: "EADDRINUSE" }))
185+.mockResolvedValue(undefined);
185186186187const result = await forceFreePortAndWait(18789, { timeoutMs: 500, intervalMs: 100 });
187188@@ -216,6 +217,7 @@ describe("gateway --force helpers", () => {
216217.mockRejectedValueOnce(busyErr)
217218.mockRejectedValueOnce(busyErr)
218219.mockRejectedValueOnce(busyErr)
220+.mockRejectedValueOnce(busyErr)
219221.mockResolvedValueOnce(undefined);
220222221223const promise = forceFreePortAndWait(18789, {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。