The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Fix flaky remote-sync conflict-modal e2e test (#80396)
Anderson0361fce5603e
diff --git a/e2e/support/helpers/e2e-remote-sync-helpers.ts b/e2e/support/helpers/e2e-remote-sync-helpers.tsindex 4c43cda3eb1..9e42be8b62d 100644--- a/e2e/support/helpers/e2e-remote-sync-helpers.ts+++ b/e2e/support/helpers/e2e-remote-sync-helpers.ts@@ -1,6 +1,6 @@import yaml from "js-yaml";-import type { Collection } from "metabase-types/api";+import type { Collection, RemoteSyncTask } from "metabase-types/api";import { openCollectionItemMenu } from "./e2e-collection-helpers";import {@@ -252,7 +252,9 @@ const MAIN_MENU_OPTION_RE = /Pull changes|Push changes/;const clickGitSyncOption = (getOption: () => Cypress.Chainable<JQuery<HTMLElement>>,) => {- getOption().should("not.be.disabled").realClick();+ // Clicks are swallowed while `data-combobox-disabled` is set (cleared once the git round-trips resolve)+ getOption().should("not.have.attr", "data-combobox-disabled");+ getOption().realClick();cy.get("body").then(($body) => {const mainMenuStillOpen =$body@@ -329,6 +331,8 @@ export const closeSyncResultModal = () => {cy.findByTestId("sync-success-close-button", { timeout: 10000 }).click();};+const TASK_POLL_LIMIT = 30;+export const waitForTask = ({ taskName }: { taskName: "import" | "export" },retries = 0,@@ -348,36 +352,38 @@ export const waitForTask = (});};-// Poll for task completion by actively querying the endpoint-// Use this when the app isn't loaded yet (e.g., in setup helpers before cy.visit)+// Poll for a task's terminal state by actively querying the endpoint; `until` is the expected status.+// Use this when the app isn't loaded yet, or to confirm server-side settling independently of the UI.export const pollForTask = (- { taskName }: { taskName: "import" | "export" },+ {+ taskName,+ until = "successful",+ }: { taskName: "import" | "export"; until?: "successful" | "conflict" },retries = 0,): Cypress.Chainable => {- if (retries > 30) {+ if (retries > TASK_POLL_LIMIT) {throw Error(`Too many retries waiting for ${taskName}`);}return cy- .request("GET", "/api/ee/remote-sync/current-task")+ .request<RemoteSyncTask | null>("GET", "/api/ee/remote-sync/current-task").then((response) => {const { body } = response;// No task exists yet, keep waitingif (!body) {cy.wait(500);- return pollForTask({ taskName }, retries + 1);+ return pollForTask({ taskName, until }, retries + 1);}// Wrong task type, keep waitingif (body.sync_task_type !== taskName) {cy.wait(500);- return pollForTask({ taskName }, retries + 1);+ return pollForTask({ taskName, until }, retries + 1);}- // Task hasn't completed successfully yet- if (body.status !== "successful") {- // Check if it errored+ // Task hasn't reached the expected terminal status yet+ if (body.status !== until) {if (body.status === "errored") {throw Error(`Task ${taskName} failed: ${body.error_message || "Unknown error"}`,@@ -390,11 +396,23 @@ export const pollForTask = ();}+ if (body.status === "successful") {+ throw Error(+ `Task ${taskName} completed without the expected ${until}`,+ );+ }++ if (body.status === "cancelled" || body.status === "timed-out") {+ throw Error(+ `Task ${taskName} ended with status ${body.status}: ${body.error_message || "Unknown error"}`,+ );+ }+cy.wait(500);- return pollForTask({ taskName }, retries + 1);+ return pollForTask({ taskName, until }, retries + 1);}- // Success!+ // Reached the expected terminal status!return cy.wrap(body);});};diff --git a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts b/e2e/test/scenarios/admin/remote-sync.cy.spec.tsindex ebbaba1e938..f0035adae8f 100644--- a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts+++ b/e2e/test/scenarios/admin/remote-sync.cy.spec.ts@@ -1034,7 +1034,11 @@ describe("Remote Sync", () => {});it("shows conflict modal with available options when remote would override local", () => {+ cy.intercept("POST", "/api/ee/remote-sync/import").as("pullImport");+ cy.intercept("GET", "/api/transform*").as("getTransforms");+H.DataStudio.Transforms.visit();+ cy.wait("@getTransforms");cy.findByRole("treegrid").within(() => {cy.findByText("Batman's Existing Transform").should("be.visible");@@ -1042,6 +1046,9 @@ describe("Remote Sync", () => {H.clickPullOption();+ cy.wait("@pullImport");+ H.pollForTask({ taskName: "import", until: "conflict" });+cy.log("make sure conflict modal is displayed");H.modal().within(() => {cy.findByRole("heading", {@@ -1060,13 +1067,18 @@ describe("Remote Sync", () => {cy.findByRole("button", { name: "Delete unsynced changes" }).click();+ cy.log("wait for the forced import to replace local state");+ cy.wait("@pullImport");+ H.pollForTask({ taskName: "import" });+ H.closeSyncResultModal();+cy.findByRole("treegrid").within(() => {+ cy.log("check remote transform was pulled in");+ cy.findByText("Imported Simple SQL transform").should("be.visible");cy.log("check existing transform was removed after pulling from remote",);cy.findByText("Batman's Existing Transform").should("not.exist");- cy.log("check remote transform was pulled in");- cy.findByText("Imported Simple SQL transform").should("be.visible");});});