perf(test): use fs.rm retry options in cron teardown

This commit is contained in:
Peter Steinberger
2026-02-18 17:37:26 +00:00
parent aa3dfe8216
commit 05173ec53a

View File

@@ -17,21 +17,17 @@ async function makeStorePath() {
storePath: path.join(dir, "cron", "jobs.json"),
cleanup: async () => {
// On macOS, teardown can race with trailing async fs writes and leave
// transient ENOTEMPTY errors. Retry briefly for stability.
for (let i = 0; i < 10; i += 1) {
try {
await fs.rm(dir, { recursive: true, force: true });
return;
} catch (err) {
const code = (err as NodeJS.ErrnoException).code;
if (code !== "ENOTEMPTY") {
throw err;
}
// eslint-disable-next-line no-await-in-loop
await new Promise<void>((resolve) => setTimeout(resolve, 10));
}
// transient ENOTEMPTY/EBUSY errors; let fs.rm handle retries natively.
try {
await fs.rm(dir, {
recursive: true,
force: true,
maxRetries: 10,
retryDelay: 10,
});
} catch {
await fs.rm(dir, { recursive: true, force: true });
}
await fs.rm(dir, { recursive: true, force: true });
},
};
}