From 8549e278775dcc13be318a6a995931f4b19bfcdd Mon Sep 17 00:00:00 2001 From: kohinoor98 Date: Mon, 6 Nov 2023 19:48:39 -0800 Subject: [PATCH 1/6] wait added for api call before cy.contains Signed-off-by: kohinoor98 --- .../index-management-dashboards-plugin/aliases.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js b/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js index 55b0dfe72..69a7d1922 100644 --- a/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js +++ b/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js @@ -26,11 +26,21 @@ describe("Aliases", () => { }); beforeEach(() => { + // Intercept the specific POST request + cy.intercept("POST", "/api/ism/apiCaller", (req) => { + if (req.body.data && req.body.data.name === "**" && req.body.data.s === "alias:desc" && req.body.endpoint === "cat.aliases") { + req.alias = "apiCaller"; // Assign an alias directly if the condition is met + } + }); + // Visit ISM OSD cy.visit(`${BASE_PATH}/app/${IM_PLUGIN_NAME}#/aliases`); + // Wait for the API call to complete + cy.wait("@apiCaller", { timeout: 120000 }); + // Common text to wait for to confirm page loaded, give up to 60 seconds for initial load - cy.contains("Rows per page", { timeout: 60000 }); + cy.contains("Rows per page", { timeout: 60000 }).should("be.visible"); }); describe("can be searched / sorted / paginated", () => { From aa3e0cca472b072c6e308439dd3d236d27b46ac3 Mon Sep 17 00:00:00 2001 From: kohinoor98 Date: Sun, 12 Nov 2023 17:20:35 -0600 Subject: [PATCH 2/6] adding an arbitrary wait for aliases.js Signed-off-by: kohinoor98 --- .../plugins/index-management-dashboards-plugin/aliases.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js b/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js index 69a7d1922..05f5df0d8 100644 --- a/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js +++ b/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js @@ -33,6 +33,10 @@ describe("Aliases", () => { } }); + // Wait for 10 seconds for OSD to start. + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(10000); + // Visit ISM OSD cy.visit(`${BASE_PATH}/app/${IM_PLUGIN_NAME}#/aliases`); From 3fa2b23aabaa893d2602e6e8d9289010563911f8 Mon Sep 17 00:00:00 2001 From: kohinoor98 Date: Wed, 15 Nov 2023 02:46:15 -0800 Subject: [PATCH 3/6] optimised beforeEach and increased wait time Signed-off-by: kohinoor98 --- .../plugins/index-management-dashboards-plugin/aliases.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js b/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js index 05f5df0d8..4400c2a8c 100644 --- a/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js +++ b/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js @@ -33,13 +33,13 @@ describe("Aliases", () => { } }); - // Wait for 10 seconds for OSD to start. - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(10000); - // Visit ISM OSD cy.visit(`${BASE_PATH}/app/${IM_PLUGIN_NAME}#/aliases`); + // Wait for 30 seconds for OSD to start. + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(30000); + // Wait for the API call to complete cy.wait("@apiCaller", { timeout: 120000 }); From cd824e4b5d1e13a154980f4e3b785dd2d0fe5703 Mon Sep 17 00:00:00 2001 From: kohinoor98 Date: Wed, 15 Nov 2023 04:17:50 -0800 Subject: [PATCH 4/6] increasing timeout and custom impl for retry Signed-off-by: kohinoor98 --- .../aliases.js | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js b/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js index 4400c2a8c..1e85746ab 100644 --- a/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js +++ b/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js @@ -25,6 +25,24 @@ describe("Aliases", () => { cy.addIndexAlias(`${SAMPLE_ALIAS_PREFIX}-0`, `${SAMPLE_INDEX_PREFIX}-*`); }); + Cypress.Commands.add("waitForAliasWithRetry", (alias, retryCount = 3, timeout = 240000) => { + const tryWait = (currentAttempt) => { + cy.wait(alias, { timeout: timeout }).then( + () => true, // If successful, do nothing + (error) => { + if (currentAttempt < retryCount) { + cy.log(`Retry attempt ${currentAttempt + 1} for ${alias}`); + tryWait(currentAttempt + 1); // Retry + } else { + throw error; // If retries are exhausted, throw the error + } + } + ); + }; + + tryWait(0); // Initial call to tryWait + }); + beforeEach(() => { // Intercept the specific POST request cy.intercept("POST", "/api/ism/apiCaller", (req) => { @@ -36,15 +54,15 @@ describe("Aliases", () => { // Visit ISM OSD cy.visit(`${BASE_PATH}/app/${IM_PLUGIN_NAME}#/aliases`); - // Wait for 30 seconds for OSD to start. + // Wait for 120 seconds for OSD to start. // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(30000); + cy.wait(120000); - // Wait for the API call to complete - cy.wait("@apiCaller", { timeout: 120000 }); + // Use the custom command for waiting with retries + cy.waitForAliasWithRetry("@apiCaller"); - // Common text to wait for to confirm page loaded, give up to 60 seconds for initial load - cy.contains("Rows per page", { timeout: 60000 }).should("be.visible"); + // Common text to wait for to confirm page loaded, give up to 120 seconds for initial load + cy.contains("Rows per page", { timeout: 120000 }).should("be.visible"); }); describe("can be searched / sorted / paginated", () => { From 8fd546a0890f8e97a397e8c29ed597f5e1602df9 Mon Sep 17 00:00:00 2001 From: kohinoor98 Date: Wed, 15 Nov 2023 04:32:21 -0800 Subject: [PATCH 5/6] revert retry logic Signed-off-by: kohinoor98 --- .../aliases.js | 22 ++----------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js b/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js index 1e85746ab..8d301eb45 100644 --- a/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js +++ b/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js @@ -25,24 +25,6 @@ describe("Aliases", () => { cy.addIndexAlias(`${SAMPLE_ALIAS_PREFIX}-0`, `${SAMPLE_INDEX_PREFIX}-*`); }); - Cypress.Commands.add("waitForAliasWithRetry", (alias, retryCount = 3, timeout = 240000) => { - const tryWait = (currentAttempt) => { - cy.wait(alias, { timeout: timeout }).then( - () => true, // If successful, do nothing - (error) => { - if (currentAttempt < retryCount) { - cy.log(`Retry attempt ${currentAttempt + 1} for ${alias}`); - tryWait(currentAttempt + 1); // Retry - } else { - throw error; // If retries are exhausted, throw the error - } - } - ); - }; - - tryWait(0); // Initial call to tryWait - }); - beforeEach(() => { // Intercept the specific POST request cy.intercept("POST", "/api/ism/apiCaller", (req) => { @@ -58,8 +40,8 @@ describe("Aliases", () => { // eslint-disable-next-line cypress/no-unnecessary-waiting cy.wait(120000); - // Use the custom command for waiting with retries - cy.waitForAliasWithRetry("@apiCaller"); + // Wait for the API call to complete + cy.wait("@apiCaller", { timeout: 240000 }); // Common text to wait for to confirm page loaded, give up to 120 seconds for initial load cy.contains("Rows per page", { timeout: 120000 }).should("be.visible"); From 33154342e32f6d2e78ad19f2c8de6159ce3c2c96 Mon Sep 17 00:00:00 2001 From: kohinoor98 Date: Thu, 16 Nov 2023 12:42:31 -0800 Subject: [PATCH 6/6] added log for apiCaller and removed wait for osd Signed-off-by: kohinoor98 --- .../index-management-dashboards-plugin/aliases.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js b/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js index 8d301eb45..97e84cb6e 100644 --- a/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js +++ b/cypress/integration/plugins/index-management-dashboards-plugin/aliases.js @@ -38,10 +38,17 @@ describe("Aliases", () => { // Wait for 120 seconds for OSD to start. // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(120000); + // cy.wait(120000); + + const startTime = new Date().getTime(); // Wait for the API call to complete - cy.wait("@apiCaller", { timeout: 240000 }); + cy.wait("@apiCaller", { timeout: 240000 }).then(() => { + // Log the calculated duration + const endTime = new Date().getTime(); + const duration = endTime - startTime; // Duration in milliseconds + cy.log(`@apiCaller completed in ${duration} milliseconds`); + }); // Common text to wait for to confirm page loaded, give up to 120 seconds for initial load cy.contains("Rows per page", { timeout: 120000 }).should("be.visible");