mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 08:31:24 +00:00
perf(test): trim fixture and import overhead in hot suites
This commit is contained in:
@@ -3,12 +3,16 @@ import fsSync from "node:fs";
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import { resolveConfigPath, resolveGatewayLockDir, resolveStateDir } from "../config/paths.js";
|
||||
import { acquireGatewayLock, GatewayLockError } from "./gateway-lock.js";
|
||||
|
||||
let fixtureRoot = "";
|
||||
let fixtureCount = 0;
|
||||
|
||||
async function makeEnv() {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-gateway-lock-"));
|
||||
const dir = path.join(fixtureRoot, `case-${fixtureCount++}`);
|
||||
await fs.mkdir(dir, { recursive: true });
|
||||
const configPath = path.join(dir, "openclaw.json");
|
||||
await fs.writeFile(configPath, "{}", "utf8");
|
||||
await fs.mkdir(resolveGatewayLockDir(), { recursive: true });
|
||||
@@ -18,9 +22,7 @@ async function makeEnv() {
|
||||
OPENCLAW_STATE_DIR: dir,
|
||||
OPENCLAW_CONFIG_PATH: configPath,
|
||||
},
|
||||
cleanup: async () => {
|
||||
await fs.rm(dir, { recursive: true, force: true });
|
||||
},
|
||||
cleanup: async () => {},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -61,13 +63,21 @@ function makeProcStat(pid: number, startTime: number) {
|
||||
}
|
||||
|
||||
describe("gateway lock", () => {
|
||||
beforeAll(async () => {
|
||||
fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-gateway-lock-"));
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await fs.rm(fixtureRoot, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it("blocks concurrent acquisition until release", async () => {
|
||||
const { env, cleanup } = await makeEnv();
|
||||
const lock = await acquireGatewayLock({
|
||||
env,
|
||||
allowInTests: true,
|
||||
timeoutMs: 200,
|
||||
pollIntervalMs: 20,
|
||||
timeoutMs: 80,
|
||||
pollIntervalMs: 5,
|
||||
});
|
||||
expect(lock).not.toBeNull();
|
||||
|
||||
@@ -75,8 +85,8 @@ describe("gateway lock", () => {
|
||||
acquireGatewayLock({
|
||||
env,
|
||||
allowInTests: true,
|
||||
timeoutMs: 200,
|
||||
pollIntervalMs: 20,
|
||||
timeoutMs: 80,
|
||||
pollIntervalMs: 5,
|
||||
}),
|
||||
).rejects.toBeInstanceOf(GatewayLockError);
|
||||
|
||||
@@ -84,8 +94,8 @@ describe("gateway lock", () => {
|
||||
const lock2 = await acquireGatewayLock({
|
||||
env,
|
||||
allowInTests: true,
|
||||
timeoutMs: 200,
|
||||
pollIntervalMs: 20,
|
||||
timeoutMs: 80,
|
||||
pollIntervalMs: 5,
|
||||
});
|
||||
await lock2?.release();
|
||||
await cleanup();
|
||||
@@ -114,8 +124,8 @@ describe("gateway lock", () => {
|
||||
const lock = await acquireGatewayLock({
|
||||
env,
|
||||
allowInTests: true,
|
||||
timeoutMs: 200,
|
||||
pollIntervalMs: 20,
|
||||
timeoutMs: 80,
|
||||
pollIntervalMs: 5,
|
||||
platform: "linux",
|
||||
});
|
||||
expect(lock).not.toBeNull();
|
||||
@@ -148,8 +158,8 @@ describe("gateway lock", () => {
|
||||
acquireGatewayLock({
|
||||
env,
|
||||
allowInTests: true,
|
||||
timeoutMs: 120,
|
||||
pollIntervalMs: 20,
|
||||
timeoutMs: 50,
|
||||
pollIntervalMs: 5,
|
||||
staleMs: 10_000,
|
||||
platform: "linux",
|
||||
}),
|
||||
@@ -173,8 +183,8 @@ describe("gateway lock", () => {
|
||||
const lock = await acquireGatewayLock({
|
||||
env,
|
||||
allowInTests: true,
|
||||
timeoutMs: 200,
|
||||
pollIntervalMs: 20,
|
||||
timeoutMs: 80,
|
||||
pollIntervalMs: 5,
|
||||
staleMs: 1,
|
||||
platform: "linux",
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user