mirror of https://github.com/zulip/zulip.git
puppeteer: Fix `subscribe_toogle.ts` long pending flake.
The issue with the existing code is that we use the `page.waitForSelector` function to detect if the element is visible and interactable. `page.waitForSelector` only ensures that the element is visible and doesn't guarantees that the element is interactable. Most of the time it is enough but sometimes it is too fast and our test fails. To fix this we change our approach to check the button text on the stream settings page (`/#streams/stream_id`). Either it could be `Subscribe` or `Unsubscribe`.
This commit is contained in:
parent
d4b6d36740
commit
6242602276
|
@ -9,10 +9,16 @@ async function test_subscription_button(page: Page): Promise<void> {
|
|||
const unsubscribed_selector = `${button_selector}:not(.checked)`;
|
||||
|
||||
async function subscribed(): Promise<ElementHandle | null> {
|
||||
await page.waitForFunction(
|
||||
() => $(".stream_settings_header .sub_unsub_button").text().trim() === "Unsubscribe",
|
||||
);
|
||||
return await page.waitForSelector(subscribed_selector, {visible: true});
|
||||
}
|
||||
|
||||
async function unsubscribed(): Promise<ElementHandle | null> {
|
||||
await page.waitForFunction(
|
||||
() => $(".stream_settings_header .sub_unsub_button").text().trim() === "Subscribe",
|
||||
);
|
||||
return await page.waitForSelector(unsubscribed_selector, {visible: true});
|
||||
}
|
||||
|
||||
|
@ -20,6 +26,8 @@ async function test_subscription_button(page: Page): Promise<void> {
|
|||
await page.waitForSelector(stream_selector, {visible: true});
|
||||
await page.waitForSelector(button_selector, {visible: true});
|
||||
|
||||
await page.click(stream_selector);
|
||||
|
||||
// Note that we intentionally re-find the button after each click, since
|
||||
// the live-update code may replace the whole row.
|
||||
let button;
|
||||
|
@ -28,20 +36,12 @@ async function test_subscription_button(page: Page): Promise<void> {
|
|||
// should happen immediately.
|
||||
button = await subscribed();
|
||||
|
||||
// Toggle subscriptions several times. This test code has been known
|
||||
// to flake, so we add console statements. It appears that the console
|
||||
// statements help prevent the flake, which is probably caused by some
|
||||
// subtle race condition. We will hopefully diagnose the root cause of
|
||||
// the flake, but I am confident that the test will mostly catch actual
|
||||
// bugs in the real code, so as long as the console.info statements help
|
||||
// here, we should just leave them in.
|
||||
// Toggle subscriptions several times.
|
||||
for (let i = 0; i < 10; i += 1) {
|
||||
console.info(`\n unsubscribe/subscribe loop ${i}\n\n`);
|
||||
await button!.click();
|
||||
button = await unsubscribed();
|
||||
await button!.click();
|
||||
button = await subscribed();
|
||||
console.info(`\n end loop ${i}\n\n`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue