test(electron): cover renderer recovery policy

This commit is contained in:
wq.pan
2026-08-27 11:22:18 +08:00
parent 2a1c10cb3e
commit 5f1c1434f8
2 changed files with 64 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
const RECOVERY_WINDOW_MS = 60_000;
const MAX_RECOVERY_ATTEMPTS = 3;
const RECOVERABLE_REASONS = new Set([
'abnormal-exit',
'crashed',
'oom',
'memory-eviction',
]);
export const createRendererRecoveryPolicy = (now = Date.now) => {
let windowStartedAt = 0;
let attempts = 0;
return {
shouldReload: (reason) => {
if (!RECOVERABLE_REASONS.has(reason)) return false;
const currentTime = now();
if (currentTime - windowStartedAt >= RECOVERY_WINDOW_MS) {
windowStartedAt = currentTime;
attempts = 0;
}
if (attempts >= MAX_RECOVERY_ATTEMPTS) return false;
attempts += 1;
return true;
},
};
};