From 526c71a655e0d8ef189b52e4838ce9062de1d16d Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 14 Feb 2026 21:26:19 +0000 Subject: [PATCH] perf(test): speed up session store lock suite --- src/config/sessions/store.lock.test.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/config/sessions/store.lock.test.ts b/src/config/sessions/store.lock.test.ts index 83b92529532..65e366a5908 100644 --- a/src/config/sessions/store.lock.test.ts +++ b/src/config/sessions/store.lock.test.ts @@ -1,7 +1,7 @@ import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; -import { afterEach, describe, expect, it } from "vitest"; +import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest"; import type { SessionEntry } from "./types.js"; import { sleep } from "../../utils.js"; import { @@ -14,12 +14,15 @@ import { } from "../sessions.js"; describe("session store lock (Promise chain mutex)", () => { + let fixtureRoot = ""; + let caseId = 0; let tmpDirs: string[] = []; async function makeTmpStore( initial: Record = {}, ): Promise<{ dir: string; storePath: string }> { - const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-lock-test-")); + const dir = path.join(fixtureRoot, `case-${caseId++}`); + await fs.mkdir(dir, { recursive: true }); tmpDirs.push(dir); const storePath = path.join(dir, "sessions.json"); if (Object.keys(initial).length > 0) { @@ -28,11 +31,18 @@ describe("session store lock (Promise chain mutex)", () => { return { dir, storePath }; } + beforeAll(async () => { + fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-lock-test-")); + }); + + afterAll(async () => { + if (fixtureRoot) { + await fs.rm(fixtureRoot, { recursive: true, force: true }).catch(() => undefined); + } + }); + afterEach(async () => { clearSessionStoreCacheForTest(); - for (const dir of tmpDirs) { - await fs.rm(dir, { recursive: true, force: true }).catch(() => undefined); - } tmpDirs = []; });