mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-26 17:32:16 +00:00
test: harden threaded channel follow-ups
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
export type { FileLockHandle, FileLockOptions } from "../plugin-sdk/file-lock.js";
|
||||
export {
|
||||
acquireFileLock,
|
||||
drainFileLockStateForTest,
|
||||
resetFileLockStateForTest,
|
||||
withFileLock,
|
||||
} from "../plugin-sdk/file-lock.js";
|
||||
|
||||
@@ -40,6 +40,14 @@ function releaseAllLocksSync(): void {
|
||||
}
|
||||
}
|
||||
|
||||
async function drainAllLocks(): Promise<void> {
|
||||
for (const [normalizedFile, held] of Array.from(HELD_LOCKS.entries())) {
|
||||
HELD_LOCKS.delete(normalizedFile);
|
||||
await held.handle.close().catch(() => undefined);
|
||||
await fs.rm(held.lockPath, { force: true }).catch(() => undefined);
|
||||
}
|
||||
}
|
||||
|
||||
function rmLockPathSync(lockPath: string): void {
|
||||
try {
|
||||
fsSync.rmSync(lockPath, { force: true });
|
||||
@@ -133,6 +141,10 @@ export function resetFileLockStateForTest(): void {
|
||||
releaseAllLocksSync();
|
||||
}
|
||||
|
||||
export async function drainFileLockStateForTest(): Promise<void> {
|
||||
await drainAllLocks();
|
||||
}
|
||||
|
||||
/** Acquire a re-entrant process-local file lock backed by a `.lock` sidecar file. */
|
||||
export async function acquireFileLock(
|
||||
filePath: string,
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { drainSessionWriteLockStateForTest } from "../agents/session-write-lock.js";
|
||||
import { clearSessionStoreCacheForTest } from "../config/sessions/store.js";
|
||||
import { drainFileLockStateForTest } from "../infra/file-lock.js";
|
||||
|
||||
export async function cleanupSessionStateForTest(): Promise<void> {
|
||||
clearSessionStoreCacheForTest();
|
||||
await drainFileLockStateForTest();
|
||||
await drainSessionWriteLockStateForTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user