mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 17:18:25 +00:00
perf(test): speed up test runs and harden temp cleanup
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { setTimeout as delay } from "node:timers/promises";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { OPENAI_DEFAULT_MODEL } from "./openai-model-default.js";
|
||||
|
||||
@@ -29,6 +30,22 @@ type OnboardEnv = {
|
||||
runtime: RuntimeMock;
|
||||
};
|
||||
|
||||
async function removeDirWithRetry(dir: string): Promise<void> {
|
||||
for (let attempt = 0; attempt < 5; attempt += 1) {
|
||||
try {
|
||||
await fs.rm(dir, { recursive: true, force: true });
|
||||
return;
|
||||
} catch (error) {
|
||||
const code = (error as NodeJS.ErrnoException).code;
|
||||
const isTransient = code === "ENOTEMPTY" || code === "EBUSY" || code === "EPERM";
|
||||
if (!isTransient || attempt === 4) {
|
||||
throw error;
|
||||
}
|
||||
await delay(25 * (attempt + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function captureEnv(): EnvSnapshot {
|
||||
return {
|
||||
home: process.env.HOME,
|
||||
@@ -102,7 +119,7 @@ async function withOnboardEnv(
|
||||
try {
|
||||
await run({ configPath, runtime });
|
||||
} finally {
|
||||
await fs.rm(tempHome, { recursive: true, force: true });
|
||||
await removeDirWithRetry(tempHome);
|
||||
restoreEnv(prev);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user