mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-20 21:51:28 +00:00
test: continue vitest threads migration
This commit is contained in:
@@ -1,26 +1,34 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
// Mock getProcessStartTime so PID-recycling detection works on non-Linux
|
||||
// (macOS, CI runners). isPidAlive is left unmocked.
|
||||
const FAKE_STARTTIME = 12345;
|
||||
vi.mock("../shared/pid-alive.js", async (importOriginal) => {
|
||||
const original = await importOriginal<typeof import("../shared/pid-alive.js")>();
|
||||
return {
|
||||
...original,
|
||||
getProcessStartTime: (pid: number) => (pid === process.pid ? FAKE_STARTTIME : null),
|
||||
};
|
||||
});
|
||||
let __testing: typeof import("./session-write-lock.js").__testing;
|
||||
let acquireSessionWriteLock: typeof import("./session-write-lock.js").acquireSessionWriteLock;
|
||||
let cleanStaleLockFiles: typeof import("./session-write-lock.js").cleanStaleLockFiles;
|
||||
let resetSessionWriteLockStateForTest: typeof import("./session-write-lock.js").resetSessionWriteLockStateForTest;
|
||||
let resolveSessionLockMaxHoldFromTimeout: typeof import("./session-write-lock.js").resolveSessionLockMaxHoldFromTimeout;
|
||||
|
||||
import {
|
||||
__testing,
|
||||
acquireSessionWriteLock,
|
||||
cleanStaleLockFiles,
|
||||
resetSessionWriteLockStateForTest,
|
||||
resolveSessionLockMaxHoldFromTimeout,
|
||||
} from "./session-write-lock.js";
|
||||
async function loadFreshSessionWriteLockModuleForTest() {
|
||||
vi.resetModules();
|
||||
// Mock getProcessStartTime so PID-recycling detection works on non-Linux
|
||||
// (macOS, CI runners). isPidAlive is left unmocked.
|
||||
vi.doMock("../shared/pid-alive.js", async (importOriginal) => {
|
||||
const original = await importOriginal<typeof import("../shared/pid-alive.js")>();
|
||||
return {
|
||||
...original,
|
||||
getProcessStartTime: (pid: number) => (pid === process.pid ? FAKE_STARTTIME : null),
|
||||
};
|
||||
});
|
||||
({
|
||||
__testing,
|
||||
acquireSessionWriteLock,
|
||||
cleanStaleLockFiles,
|
||||
resetSessionWriteLockStateForTest,
|
||||
resolveSessionLockMaxHoldFromTimeout,
|
||||
} = await import("./session-write-lock.js"));
|
||||
}
|
||||
|
||||
async function expectLockRemovedOnlyAfterFinalRelease(params: {
|
||||
lockPath: string;
|
||||
@@ -96,11 +104,14 @@ async function expectActiveInProcessLockIsNotReclaimed(params?: {
|
||||
}
|
||||
|
||||
describe("acquireSessionWriteLock", () => {
|
||||
beforeEach(async () => {
|
||||
await loadFreshSessionWriteLockModuleForTest();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
resetSessionWriteLockStateForTest();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("reuses locks across symlinked session paths", async () => {
|
||||
if (process.platform === "win32") {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user