Skip to content

Commit 9c4371d

Browse files
committed
fix(test): add robust retry logic for Windows temp directory cleanup
Windows file handle timing requires more aggressive retry strategy. Multiple tests were still failing with EPERM errors during cleanup. - Increase retries to 5 attempts with 50ms initial delay + 100ms between retries - Only apply retry logic on Windows platform - Allows up to 550ms total for file handles to be released - Fixes remaining EPERM errors in json.test.ts on Windows CI
1 parent a544cd2 commit 9c4371d

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

test/unit/json.test.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -767,12 +767,23 @@ describe('json', () => {
767767

768768
afterEach(async () => {
769769
if (testDir) {
770-
// On Windows, add a small delay to ensure file handles are released
771-
// before attempting to delete the temp directory
770+
// On Windows, add retry logic for directory deletion due to file handle timing
772771
if (process.platform === 'win32') {
773-
await sleep(100)
772+
let retries = 5
773+
while (retries > 0) {
774+
try {
775+
await sleep(50)
776+
await safeDelete(testDir)
777+
break
778+
} catch (err) {
779+
retries--
780+
if (retries === 0) {throw err}
781+
await sleep(100)
782+
}
783+
}
784+
} else {
785+
await safeDelete(testDir)
774786
}
775-
await safeDelete(testDir)
776787
}
777788
})
778789

0 commit comments

Comments
 (0)