fix: resolve test hang issues in CI

- Fixed MSW event listener memory leaks
- Added proper database connection cleanup
- Fixed MSW server lifecycle management
- Reduced global test timeout to 30s for faster failure detection
- Added resource cleanup in all integration tests

This should resolve the GitHub Actions test hanging issue
This commit is contained in:
czlonkowski
2025-07-29 13:07:51 +02:00
parent c824fb5ebf
commit 115bb6f36c
5 changed files with 88 additions and 25 deletions

View File

@@ -138,9 +138,13 @@ describe('Database Connection Management', () => {
// Test concurrent reads
const promises = connections.map((conn, index) => {
return new Promise((resolve) => {
const result = conn.prepare('SELECT ? as id').get(index);
resolve(result);
return new Promise((resolve, reject) => {
try {
const result = conn.prepare('SELECT ? as id').get(index);
resolve(result);
} catch (error) {
reject(error);
}
});
});
@@ -148,12 +152,32 @@ describe('Database Connection Management', () => {
expect(results).toHaveLength(connectionCount);
} finally {
// Cleanup connections
connections.forEach(conn => conn.close());
if (fs.existsSync(dbPath)) {
fs.unlinkSync(dbPath);
fs.unlinkSync(`${dbPath}-wal`);
fs.unlinkSync(`${dbPath}-shm`);
// Cleanup connections - ensure all are closed even if some fail
await Promise.all(
connections.map(async (conn) => {
try {
if (conn.open) {
conn.close();
}
} catch (error) {
// Ignore close errors
}
})
);
// Clean up files with error handling
try {
if (fs.existsSync(dbPath)) {
fs.unlinkSync(dbPath);
}
if (fs.existsSync(`${dbPath}-wal`)) {
fs.unlinkSync(`${dbPath}-wal`);
}
if (fs.existsSync(`${dbPath}-shm`)) {
fs.unlinkSync(`${dbPath}-shm`);
}
} catch (error) {
// Ignore cleanup errors
}
}
});
@@ -285,7 +309,7 @@ describe('Database Connection Management', () => {
db.exec('ROLLBACK');
conn2.close();
}
});
}, { timeout: 5000 }); // Add explicit timeout
});
describe('Database Configuration', () => {