

















@@ -2,19 +2,52 @@ import { describe, expect, it } from "vitest";
22import { shouldRemoveDeadOwnerOrExpiredLock } from "./stale-lock-file.js";
3344describe("stale lock file ownership", () => {
5-it("treats permission-denied process probes as not definitely dead", () => {
5+it("keeps expired locks when a pid owner is not definitely dead", () => {
66expect(
77shouldRemoveDeadOwnerOrExpiredLock({
88payload: {
99pid: 123,
10-createdAt: new Date(Date.now() - 60_000).toISOString(),
10+createdAt: "2026-05-23T00:00:00.000Z",
1111},
1212staleMs: 10,
13+nowMs: Date.parse("2026-05-23T00:00:11.000Z"),
1314isPidDefinitelyDead: () => false,
1415}),
1516).toBe(false);
1617});
171819+it("removes locks when the owner pid starttime changed", () => {
20+expect(
21+shouldRemoveDeadOwnerOrExpiredLock({
22+payload: {
23+pid: 123,
24+createdAt: "2026-05-23T00:00:00.000Z",
25+starttime: 111,
26+},
27+staleMs: 60_000,
28+nowMs: Date.parse("2026-05-23T00:00:10.000Z"),
29+isPidDefinitelyDead: () => false,
30+getProcessStartTime: () => 222,
31+}),
32+).toBe(true);
33+});
34+35+it("does not remove locks when the owner pid starttime still matches", () => {
36+expect(
37+shouldRemoveDeadOwnerOrExpiredLock({
38+payload: {
39+pid: 123,
40+createdAt: "2026-05-23T00:00:00.000Z",
41+starttime: 111,
42+},
43+staleMs: 10,
44+nowMs: Date.parse("2026-05-23T00:00:11.000Z"),
45+isPidDefinitelyDead: () => false,
46+getProcessStartTime: () => 111,
47+}),
48+).toBe(false);
49+});
50+1851it("only removes pid-owned locks when the owner is definitely dead", () => {
1952expect(
2053shouldRemoveDeadOwnerOrExpiredLock({
@@ -27,4 +60,16 @@ describe("stale lock file ownership", () => {
2760}),
2861).toBe(true);
2962});
63+64+it("removes expired pidless locks", () => {
65+expect(
66+shouldRemoveDeadOwnerOrExpiredLock({
67+payload: {
68+createdAt: "2026-05-23T00:00:00.000Z",
69+},
70+staleMs: 10,
71+nowMs: Date.parse("2026-05-23T00:00:11.000Z"),
72+}),
73+).toBe(true);
74+});
3075});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。