Skip to content

Commit f223d45

Browse files
xuiocodex
andcommitted
Stabilize app-server test cleanup
Co-Authored-By: OpenAI Codex <noreply@openai.com>
1 parent 54213e7 commit f223d45

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

test/app-server-hardening.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,22 @@ async function waitFor(
4242
return Boolean(await predicate());
4343
}
4444

45+
async function removeTempDir(dir: string): Promise<void> {
46+
for (let attempt = 0; attempt < 5; attempt += 1) {
47+
try {
48+
await rm(dir, { recursive: true, force: true });
49+
return;
50+
} catch (error) {
51+
const code = (error as NodeJS.ErrnoException).code;
52+
if (code !== "ENOTEMPTY" && code !== "EBUSY" && code !== "EPERM") throw error;
53+
await new Promise((resolve) => setTimeout(resolve, 25 * (attempt + 1)));
54+
}
55+
}
56+
await rm(dir, { recursive: true, force: true });
57+
}
58+
4559
afterEach(async () => {
46-
await Promise.all(tempDirs.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
60+
await Promise.all(tempDirs.splice(0).map(removeTempDir));
4761
});
4862

4963
describe("app-server hardening", () => {

0 commit comments

Comments
 (0)