perf(test): stabilize e2e harness and reduce flaky gateway coverage

This commit is contained in:
Peter Steinberger
2026-02-13 17:31:58 +00:00
parent 2ab7715d16
commit fdfc34fa1f
25 changed files with 427 additions and 940 deletions

View File

@@ -13,16 +13,28 @@ type HeldLock = {
lockPath: string;
};
const HELD_LOCKS = new Map<string, HeldLock>();
const CLEANUP_SIGNALS = ["SIGINT", "SIGTERM", "SIGQUIT", "SIGABRT"] as const;
type CleanupSignal = (typeof CLEANUP_SIGNALS)[number];
const CLEANUP_STATE_KEY = Symbol.for("openclaw.sessionWriteLockCleanupState");
const HELD_LOCKS_KEY = Symbol.for("openclaw.sessionWriteLockHeldLocks");
type CleanupState = {
registered: boolean;
cleanupHandlers: Map<CleanupSignal, () => void>;
};
function resolveHeldLocks(): Map<string, HeldLock> {
const proc = process as NodeJS.Process & {
[HELD_LOCKS_KEY]?: Map<string, HeldLock>;
};
if (!proc[HELD_LOCKS_KEY]) {
proc[HELD_LOCKS_KEY] = new Map<string, HeldLock>();
}
return proc[HELD_LOCKS_KEY];
}
const HELD_LOCKS = resolveHeldLocks();
function resolveCleanupState(): CleanupState {
const proc = process as NodeJS.Process & {
[CLEANUP_STATE_KEY]?: CleanupState;
@@ -78,6 +90,7 @@ function handleTerminationSignal(signal: CleanupSignal): void {
const handler = cleanupState.cleanupHandlers.get(signal);
if (handler) {
process.off(signal, handler);
cleanupState.cleanupHandlers.delete(signal);
}
try {
process.kill(process.pid, signal);
@@ -89,18 +102,19 @@ function handleTerminationSignal(signal: CleanupSignal): void {
function registerCleanupHandlers(): void {
const cleanupState = resolveCleanupState();
if (cleanupState.registered) {
return;
if (!cleanupState.registered) {
cleanupState.registered = true;
// Cleanup on normal exit and process.exit() calls
process.on("exit", () => {
releaseAllLocksSync();
});
}
cleanupState.registered = true;
// Cleanup on normal exit and process.exit() calls
process.on("exit", () => {
releaseAllLocksSync();
});
// Handle termination signals
for (const signal of CLEANUP_SIGNALS) {
if (cleanupState.cleanupHandlers.has(signal)) {
continue;
}
try {
const handler = () => handleTerminationSignal(signal);
cleanupState.cleanupHandlers.set(signal, handler);