bump retries and wait for networkidle in retry

This commit is contained in:
Gregor Vostrak
2026-03-02 16:57:15 +01:00
parent 5b053bc2c1
commit b2fa07b38b

View File

@@ -25,10 +25,10 @@ export interface TestContext {
* then used for all subsequent API calls, making them independent of cookie state. * then used for all subsequent API calls, making them independent of cookie state.
* *
* If the first attempt returns 401 (Octane hasn't fully committed the session yet), * If the first attempt returns 401 (Octane hasn't fully committed the session yet),
* we reload the page to trigger a fresh CreateFreshApiToken and retry once. * we reload the page to trigger a fresh CreateFreshApiToken and retry.
*/ */
async function createApiToken(page: Page): Promise<string> { async function createApiToken(page: Page): Promise<string> {
for (let attempt = 0; attempt < 2; attempt++) { for (let attempt = 0; attempt < 3; attempt++) {
const result = await page.evaluate(async (baseUrl) => { const result = await page.evaluate(async (baseUrl) => {
const xsrfCookie = document.cookie.split('; ').find((c) => c.startsWith('XSRF-TOKEN=')); const xsrfCookie = document.cookie.split('; ').find((c) => c.startsWith('XSRF-TOKEN='));
const xsrfToken = xsrfCookie const xsrfToken = xsrfCookie
@@ -57,11 +57,12 @@ async function createApiToken(page: Page): Promise<string> {
return result; return result;
} }
// Reload to get a fresh laravel_token cookie and retry // Reload to get a fresh laravel_token cookie and retry.
await page.reload({ waitUntil: 'domcontentloaded' }); // networkidle gives Octane time to fully commit the session.
await page.reload({ waitUntil: 'networkidle' });
} }
throw new Error('Failed to create API token after retry'); throw new Error('Failed to create API token after retries');
} }
function buildAuthHeaders(token: string, xsrfToken: string): Record<string, string> { function buildAuthHeaders(token: string, xsrfToken: string): Record<string, string> {