mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-04 21:13:35 +00:00
perf(plugins): cache runtime mirror file decisions
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
acquireFileLock,
|
||||
drainFileLockStateForTest,
|
||||
@@ -55,4 +55,28 @@ describe("acquireFileLock", () => {
|
||||
return true;
|
||||
});
|
||||
}, 5_000);
|
||||
|
||||
it("closes an opened lock handle when writing the owner payload fails", async () => {
|
||||
const filePath = path.join(tempDir, "write-fails");
|
||||
const writeError = new Error("owner write failed");
|
||||
const close = vi.fn().mockResolvedValue(undefined);
|
||||
vi.spyOn(fs, "open").mockResolvedValue({
|
||||
close,
|
||||
writeFile: vi.fn().mockRejectedValue(writeError),
|
||||
} as unknown as Awaited<ReturnType<typeof fs.open>>);
|
||||
|
||||
await expect(
|
||||
acquireFileLock(filePath, {
|
||||
retries: {
|
||||
retries: 0,
|
||||
factor: 1,
|
||||
minTimeout: 1,
|
||||
maxTimeout: 1,
|
||||
},
|
||||
stale: 100,
|
||||
}),
|
||||
).rejects.toThrow(writeError);
|
||||
|
||||
expect(close).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user