mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-24 15:41:40 +00:00
test: stabilize windows flow and session cleanup tests
This commit is contained in:
@@ -19,6 +19,19 @@ function createStoredFlow(): FlowRecord {
|
||||
};
|
||||
}
|
||||
|
||||
async function withFlowRegistryTempDir<T>(run: (root: string) => Promise<T>): Promise<T> {
|
||||
return await withTempDir({ prefix: "openclaw-flow-store-" }, async (root) => {
|
||||
process.env.OPENCLAW_STATE_DIR = root;
|
||||
resetFlowRegistryForTests();
|
||||
try {
|
||||
return await run(root);
|
||||
} finally {
|
||||
// Close the sqlite-backed registry before Windows temp-dir cleanup removes the store root.
|
||||
resetFlowRegistryForTests();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
describe("flow-registry store runtime", () => {
|
||||
afterEach(() => {
|
||||
delete process.env.OPENCLAW_STATE_DIR;
|
||||
@@ -60,7 +73,7 @@ describe("flow-registry store runtime", () => {
|
||||
});
|
||||
|
||||
it("restores persisted flows from the default sqlite store", async () => {
|
||||
await withTempDir({ prefix: "openclaw-flow-store-" }, async (root) => {
|
||||
await withFlowRegistryTempDir(async (root) => {
|
||||
process.env.OPENCLAW_STATE_DIR = root;
|
||||
resetFlowRegistryForTests();
|
||||
|
||||
@@ -85,7 +98,7 @@ describe("flow-registry store runtime", () => {
|
||||
if (process.platform === "win32") {
|
||||
return;
|
||||
}
|
||||
await withTempDir({ prefix: "openclaw-flow-store-" }, async (root) => {
|
||||
await withFlowRegistryTempDir(async (root) => {
|
||||
process.env.OPENCLAW_STATE_DIR = root;
|
||||
resetFlowRegistryForTests();
|
||||
|
||||
|
||||
@@ -2,13 +2,10 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { resetSessionWriteLockStateForTest } from "../agents/session-write-lock.js";
|
||||
import {
|
||||
clearSessionStoreCacheForTest,
|
||||
getSessionStoreLockQueueSizeForTest,
|
||||
withSessionStoreLockForTest,
|
||||
} from "../config/sessions/store.js";
|
||||
import { resetFileLockStateForTest } from "../infra/file-lock.js";
|
||||
import { cleanupSessionStateForTest } from "./session-state-cleanup.js";
|
||||
|
||||
const acquireSessionWriteLockMock = vi.hoisted(() =>
|
||||
@@ -34,17 +31,13 @@ function createDeferred<T>() {
|
||||
}
|
||||
|
||||
describe("cleanupSessionStateForTest", () => {
|
||||
beforeEach(() => {
|
||||
clearSessionStoreCacheForTest();
|
||||
resetFileLockStateForTest();
|
||||
resetSessionWriteLockStateForTest();
|
||||
beforeEach(async () => {
|
||||
await cleanupSessionStateForTest();
|
||||
acquireSessionWriteLockMock.mockClear();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
clearSessionStoreCacheForTest();
|
||||
resetFileLockStateForTest();
|
||||
resetSessionWriteLockStateForTest();
|
||||
afterEach(async () => {
|
||||
await cleanupSessionStateForTest();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
@@ -53,8 +46,9 @@ describe("cleanupSessionStateForTest", () => {
|
||||
const storePath = path.join(fixtureRoot, "openclaw-sessions.json");
|
||||
const started = createDeferred<void>();
|
||||
const release = createDeferred<void>();
|
||||
let running: Promise<void> | undefined;
|
||||
try {
|
||||
const running = withSessionStoreLockForTest(storePath, async () => {
|
||||
running = withSessionStoreLockForTest(storePath, async () => {
|
||||
started.resolve();
|
||||
await release.promise;
|
||||
});
|
||||
@@ -77,6 +71,8 @@ describe("cleanupSessionStateForTest", () => {
|
||||
expect(getSessionStoreLockQueueSizeForTest()).toBe(0);
|
||||
} finally {
|
||||
release.resolve();
|
||||
await running?.catch(() => undefined);
|
||||
await cleanupSessionStateForTest();
|
||||
await fs.rm(fixtureRoot, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user