Replace fixed timeout with polling in random-jobs E2E test

- Removed brittle 1-second waitForTimeout
- Use toPass() with polling to wait for job outcome
- Check for specific user's email instead of exact row count
- More robust under slow worker conditions or CI load
This commit is contained in:
counterweight 2025-12-21 23:14:59 +01:00
parent 18284c5e63
commit 405dfd526e
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C

View file

@ -18,9 +18,6 @@ test.describe("Random Jobs - E2E", () => {
const counterValue = await page.locator("h1").textContent(); const counterValue = await page.locator("h1").textContent();
expect(counterValue).toMatch(/^\d+$/); expect(counterValue).toMatch(/^\d+$/);
// Give the worker a moment to process the job
await page.waitForTimeout(1000);
// Step 3: Logout // Step 3: Logout
await page.click("text=Sign out"); await page.click("text=Sign out");
await expect(page).toHaveURL("/login"); await expect(page).toHaveURL("/login");
@ -35,13 +32,12 @@ test.describe("Random Jobs - E2E", () => {
await page.click('a[href="/admin/random-jobs"]'); await page.click('a[href="/admin/random-jobs"]');
await expect(page).toHaveURL("/admin/random-jobs"); await expect(page).toHaveURL("/admin/random-jobs");
// Step 6: Verify the table contains at least one row // Step 6: Poll for job outcome to appear (worker may take time to process)
// Wait for table to load and have data // Keep refreshing until we see the regular user's email in the table
await expect(page.locator("table tbody tr")).toHaveCount(1, { timeout: 10000 }); await expect(async () => {
await page.reload();
// Verify the row has the regular user's email await expect(page.locator("table tbody")).toContainText(REGULAR_USER.email);
const tableContent = await page.locator("table tbody").textContent(); }).toPass({ timeout: 15000, intervals: [500, 1000, 2000] });
expect(tableContent).toContain(REGULAR_USER.email);
// Verify the outcome has expected fields // Verify the outcome has expected fields
// Value should be a number 0-100 // Value should be a number 0-100