Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions tests/server/port-reclaim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ async function reclaimWithMockClock(options: ReclaimListenPortOptions): Promise<
const clock = spyOn(Date, "now").mockImplementation(() => now);
try {
return await reclaimListenPort(10100, "127.0.0.1", {
...options, timeoutMs: 50, intervalMs: 10, scanIntervalMs: 10,
sleepMs: async () => { now += 10; },
...options,
timeoutMs: options.timeoutMs ?? 50,
intervalMs: options.intervalMs ?? 10,
scanIntervalMs: options.scanIntervalMs ?? 10,
sleepMs: async ms => {
now += ms;
await options.sleepMs?.(ms);
},
});
} finally {
clock.mockRestore();
Expand Down Expand Up @@ -880,16 +886,17 @@ describe("reclaimListenPort", () => {

test("killAllOcxOnPort kills ocx listeners absent from the allowlist snapshot", async () => {
const killed: number[] = [];
let holder = 9001;
const holderPid = process.pid === 9001 ? 9002 : 9001;
let holder = holderPid;
let available = false;
await expect(reclaimListenPort(10100, "127.0.0.1", {
await expect(reclaimWithMockClock({
timeoutMs: 200,
intervalMs: 20,
scanIntervalMs: 20,
dropTcpRows: false,
killOcxHolders: true,
killAllOcxOnPort: true,
onlyKillPids: [100], // pre-update PID — respawned child is 9001
onlyKillPids: [100], // pre-update PID — the respawned holder is deliberately not self
isAvailableFn: async () => available,
listListenPidsFn: () => (holder > 0 ? [holder] : []),
isAliveFn: pid => pid === holder,
Expand All @@ -902,7 +909,7 @@ describe("reclaimListenPort", () => {
if (holder === 0) available = true;
},
})).resolves.toBe(true);
expect(killed).toEqual([9001]);
expect(killed).toEqual([holderPid]);
});

test("foreign non-ocx claimant survives reclaim without allowlist or ocx identity", async () => {
Expand Down
Loading