Skip to content

Commit 70beacc

Browse files
committed
fix(test): handle Windows file locking in cleanup
Add retry logic with exponential backoff to handle EBUSY errors when unlinking the test database file on Windows. Also add a small delay after db.destroy() to ensure the file handle is fully released before attempting cleanup.
1 parent 1ad78b9 commit 70beacc

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

test.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,22 @@ const Client_PhotoStructureSQLite = require("./index");
88
const dbPath = "./test.db";
99

1010
async function cleanup() {
11-
if (existsSync(dbPath)) {
12-
await unlink(dbPath);
11+
if (!existsSync(dbPath)) return;
12+
13+
// Retry logic for Windows file locking issues
14+
const maxRetries = 5;
15+
for (let i = 0; i < maxRetries; i++) {
16+
try {
17+
await unlink(dbPath);
18+
return;
19+
} catch (err) {
20+
if (err.code === 'EBUSY' && i < maxRetries - 1) {
21+
// Wait before retry, with exponential backoff
22+
await new Promise(resolve => setTimeout(resolve, 50 * Math.pow(2, i)));
23+
continue;
24+
}
25+
throw err;
26+
}
1327
}
1428
}
1529

@@ -28,6 +42,8 @@ describe("@photostructure/knex-sqlite", () => {
2842

2943
after(async () => {
3044
await db.destroy();
45+
// Small delay to ensure database file is fully released on Windows
46+
await new Promise(resolve => setTimeout(resolve, 100));
3147
await cleanup();
3248
});
3349

0 commit comments

Comments
 (0)