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