mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
test(e2e): fix flakiness: optimize resetDatabase with TRUNCATE and fix selectDay selector scoping (#26776)
fix(e2e): optimize resetDatabase with TRUNCATE and fix selectDay selector scoping
This commit is contained in:
@@ -215,8 +215,9 @@ export const pageUtils = {
|
|||||||
await page.getByText('Confirm').click();
|
await page.getByText('Confirm').click();
|
||||||
},
|
},
|
||||||
async selectDay(page: Page, day: string) {
|
async selectDay(page: Page, day: string) {
|
||||||
await page.getByTitle(day).hover();
|
const section = page.getByTitle(day).locator('xpath=ancestor::section[@data-group]');
|
||||||
await page.locator('[data-group] .w-8').click();
|
await section.hover();
|
||||||
|
await section.locator('.w-8').click();
|
||||||
},
|
},
|
||||||
async pauseTestDebug() {
|
async pauseTestDebug() {
|
||||||
console.log('NOTE: pausing test indefinately for debug');
|
console.log('NOTE: pausing test indefinately for debug');
|
||||||
|
|||||||
+40
-29
@@ -177,40 +177,51 @@ export const utils = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
resetDatabase: async (tables?: string[]) => {
|
resetDatabase: async (tables?: string[]) => {
|
||||||
try {
|
client = await utils.connectDatabase();
|
||||||
client = await utils.connectDatabase();
|
|
||||||
|
|
||||||
tables = tables || [
|
tables = tables || [
|
||||||
// TODO e2e test for deleting a stack, since it is quite complex
|
// TODO e2e test for deleting a stack, since it is quite complex
|
||||||
'stack',
|
'stack',
|
||||||
'library',
|
'library',
|
||||||
'shared_link',
|
'shared_link',
|
||||||
'person',
|
'person',
|
||||||
'album',
|
'album',
|
||||||
'asset',
|
'asset',
|
||||||
'asset_face',
|
'asset_face',
|
||||||
'activity',
|
'activity',
|
||||||
'api_key',
|
'api_key',
|
||||||
'session',
|
'session',
|
||||||
'user',
|
'user',
|
||||||
'system_metadata',
|
'system_metadata',
|
||||||
'tag',
|
'tag',
|
||||||
];
|
];
|
||||||
|
|
||||||
const sql: string[] = [];
|
const truncateTables = tables.filter((table) => table !== 'system_metadata');
|
||||||
|
const sql: string[] = [];
|
||||||
|
|
||||||
for (const table of tables) {
|
if (truncateTables.length > 0) {
|
||||||
if (table === 'system_metadata') {
|
sql.push(`TRUNCATE "${truncateTables.join('", "')}" CASCADE;`);
|
||||||
sql.push(`DELETE FROM "system_metadata" where "key" NOT IN ('reverse-geocoding-state', 'system-flags');`);
|
}
|
||||||
} else {
|
|
||||||
sql.push(`DELETE FROM "${table}" CASCADE;`);
|
if (tables.includes('system_metadata')) {
|
||||||
|
sql.push(`DELETE FROM "system_metadata" where "key" NOT IN ('reverse-geocoding-state', 'system-flags');`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const query = sql.join('\n');
|
||||||
|
const maxRetries = 3;
|
||||||
|
|
||||||
|
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
||||||
|
try {
|
||||||
|
await client.query(query);
|
||||||
|
return;
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error?.code === '40P01' && attempt < maxRetries) {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 250 * attempt));
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
console.error('Failed to reset database', error);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
await client.query(sql.join('\n'));
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to reset database', error);
|
|
||||||
throw error;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user