mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-28 18:33:37 +00:00
test(cleanup): isolate session lock queue coverage
This commit is contained in:
@@ -1,12 +1,29 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
getSessionStoreLockQueueSizeForTest,
|
||||
withSessionStoreLockForTest,
|
||||
} from "../config/sessions/store.js";
|
||||
import { cleanupSessionStateForTest } from "./session-state-cleanup.js";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const acquireSessionWriteLockMock = vi.hoisted(() =>
|
||||
vi.fn(async () => ({ release: vi.fn(async () => {}) })),
|
||||
);
|
||||
|
||||
let getSessionStoreLockQueueSizeForTest: typeof import("../config/sessions/store.js").getSessionStoreLockQueueSizeForTest;
|
||||
let withSessionStoreLockForTest: typeof import("../config/sessions/store.js").withSessionStoreLockForTest;
|
||||
let cleanupSessionStateForTest: typeof import("./session-state-cleanup.js").cleanupSessionStateForTest;
|
||||
|
||||
async function loadFreshCleanupModules() {
|
||||
vi.resetModules();
|
||||
vi.doMock("../agents/session-write-lock.js", async (importOriginal) => {
|
||||
const original = await importOriginal<typeof import("../agents/session-write-lock.js")>();
|
||||
return {
|
||||
...original,
|
||||
acquireSessionWriteLock: acquireSessionWriteLockMock,
|
||||
};
|
||||
});
|
||||
({ getSessionStoreLockQueueSizeForTest, withSessionStoreLockForTest } =
|
||||
await import("../config/sessions/store.js"));
|
||||
({ cleanupSessionStateForTest } = await import("./session-state-cleanup.js"));
|
||||
}
|
||||
|
||||
function createDeferred<T>() {
|
||||
let resolve!: (value: T | PromiseLike<T>) => void;
|
||||
@@ -19,8 +36,14 @@ function createDeferred<T>() {
|
||||
}
|
||||
|
||||
describe("cleanupSessionStateForTest", () => {
|
||||
beforeEach(async () => {
|
||||
acquireSessionWriteLockMock.mockClear();
|
||||
await loadFreshCleanupModules();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await cleanupSessionStateForTest();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("waits for in-flight session store locks before clearing test state", async () => {
|
||||
|
||||
Reference in New Issue
Block a user