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 branch-switch e2e test (#80397)
Andersone9235e298314
diff --git a/e2e/support/helpers/e2e-remote-sync-helpers.ts b/e2e/support/helpers/e2e-remote-sync-helpers.tsindex 9e42be8b62d..269e32e213e 100644--- a/e2e/support/helpers/e2e-remote-sync-helpers.ts+++ b/e2e/support/helpers/e2e-remote-sync-helpers.ts@@ -328,7 +328,7 @@ export const interceptTask = () =>* renders from the same task poll that `waitForTask` observes.*/export const closeSyncResultModal = () => {- cy.findByTestId("sync-success-close-button", { timeout: 10000 }).click();+ cy.findByTestId("sync-success-close-button").click();};const TASK_POLL_LIMIT = 30;@@ -337,10 +337,11 @@ export const waitForTask = ({ taskName }: { taskName: "import" | "export" },retries = 0,): Cypress.Chainable => {- if (retries > 3) {+ if (retries > TASK_POLL_LIMIT) {throw Error(`Too many retries waiting for ${taskName}`);}- return cy.wait("@currentTask").then(({ response }) => {++ return cy.wait("@currentTask", { timeout: 10000 }).then(({ response }) => {const { body } = response || {};if (body?.sync_task_type !== taskName) {return waitForTask({ taskName });diff --git a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts b/e2e/test/scenarios/admin/remote-sync.cy.spec.tsindex f0035adae8f..15f2c3d1083 100644--- a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts+++ b/e2e/test/scenarios/admin/remote-sync.cy.spec.ts@@ -21,22 +21,26 @@ const SOURCE_QUESTION_NAME = "Dependency Source Question";const DEPENDENT_QUESTION_NAME = "Dependent Question";const SECOND_DEPENDENT_QUESTION_NAME = "Second Dependent Question";-describe("Remote Sync", () => {- beforeEach(() => {- H.restore("postgres-writable");- H.resetSnowplow();- cy.signInAsAdmin();- H.activateToken("pro-self-hosted");- H.updateSetting("transforms-enabled", true);- H.setupGitSync();- H.interceptTask();- });+const setup = (snapshot = "default") => {+ H.restore(snapshot);+ H.resetSnowplow();+ cy.signInAsAdmin();+ H.activateToken("pro-self-hosted");+ H.setupGitSync();+ H.interceptTask();+};+describe("Remote Sync", () => {afterEach(() => {H.expectNoBadSnowplowEvents();});describe("read-write Mode", () => {+ beforeEach(() => {+ setup("postgres-writable");+ H.updateSetting("transforms-enabled", true);+ });+it("can push and pull changes", () => {H.configureGitWithNewSyncedCollection("read-write").as("syncedCollection",@@ -464,10 +468,7 @@ describe("Remote Sync", () => {describe("remote sync admin settings page", () => {beforeEach(() => {- H.restore();- H.activateToken("pro-self-hosted");- H.setupGitSync();- cy.signInAsAdmin();+ setup();});it("can set up read-write mode", () => {@@ -698,24 +699,25 @@ describe("Remote Sync", () => {describe("read-only mode", () => {beforeEach(() => {- H.restore();- cy.signInAsAdmin();- H.activateToken("pro-self-hosted");- H.setupGitSync();+ setup();});- it("can change branches", () => {+ it("can change branches", { requestTimeout: 15000 }, () => {const UPDATED_REMOTE_QUESTION_NAME = "New Name";H.copySyncedCollectionFixture();H.commitToRepo();- H.configureGit("read-only");+ H.configureGitAndPullChanges("read-only");+ cy.intercept("GET", /\/api\/collection\/\d+\/items/).as(+ "mainBranchItems",+ );cy.visit("/");H.navigationSidebar().findByRole("treeitem", { name: /Synced Collection/ }).click();+ cy.wait(["@mainBranchItems", "@mainBranchItems"]);H.collectionTable().findByText(REMOTE_QUESTION_NAME);// Make a change, and commit it to the branch@@ -725,8 +727,23 @@ describe("Remote Sync", () => {return doc;});+ cy.intercept("GET", "/api/session/properties").as("sessionProperties");+ cy.intercept("GET", "/api/setting").as("settingDetails");+ cy.intercept("GET", "/api/collection/root/items?*").as("rootItems");+ cy.intercept("GET", "/api/ee/library").as("libraryCollection");cy.visit("/admin/settings/remote-sync");- cy.findByLabelText("Sync branch").scrollIntoView().clear().type("test");+ cy.wait([+ "@sessionProperties",+ "@settingDetails",+ "@rootItems",+ "@libraryCollection",+ ]);++ cy.findByLabelText("Sync branch")+ .scrollIntoView()+ .clear()+ .type("test")+ .should("have.value", "test");cy.findByTestId("remote-sync-submit-button").click();cy.findByTestId("admin-layout-content")@@ -741,11 +758,17 @@ describe("Remote Sync", () => {cy.findByTestId("remote-sync-submit-button").should("be.disabled");+ H.pollForTask({ taskName: "import" });++ cy.intercept("GET", /\/api\/collection\/\d+\/items/).as(+ "testBranchItems",+ );cy.visit("/");H.navigationSidebar().findByRole("treeitem", { name: /Synced Collection/ }).click();+ cy.wait(["@testBranchItems", "@testBranchItems"]);H.collectionTable().findByText(UPDATED_REMOTE_QUESTION_NAME);});@@ -772,11 +795,7 @@ describe("Remote Sync", () => {describe("shared tenant collections", () => {beforeEach(() => {- H.restore();- cy.signInAsAdmin();- H.activateToken("pro-self-hosted");- H.setupGitSync();- H.interceptTask();+ setup();// Enable tenants featureH.enableTenants();@@ -1006,6 +1025,9 @@ describe("Remote Sync", () => {describe("initial pull conflict handling", () => {beforeEach(() => {+ setup("postgres-writable");+ H.updateSetting("transforms-enabled", true);+// Create a local transform that could be overwritten by the remoteH.createSqlTransform({sourceQuery: "SELECT 1",diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/impl.cljindex c9b3335425b..b60b6ff50d5 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj@@ -17,6 +17,7 @@[metabase.analytics-interface.core :as analytics][metabase.api.common :as api][metabase.app-db.cluster-lock :as cluster-lock]+ [metabase.app-db.core :as mdb][metabase.collections.models.collection :as collection][metabase.events.core :as events][metabase.models.serialization :as serdes]@@ -344,7 +345,7 @@has-transforms? (snapshot-has-transforms? base-ingestable)ingestable-snapshot (source.ingestable/wrap-progress-ingestable task-id 0.7 base-ingestable)load-result (serdes/with-cache- (serialization/load-metabase! ingestable-snapshot))+ (serialization/load-metabase! ingestable-snapshot :reindex? false))seen-paths (:seen load-result)imported-data (spec/extract-imported-entities seen-paths)](remote-sync.task/update-progress! task-id 0.8)@@ -365,6 +366,12 @@(settings/remote-sync-transforms))(log/info "No transforms in remote source, disabling remote-sync-transforms setting")(settings/remote-sync-transforms! false))+ ;; On H2 the reindex's table DDL blocks readers and can deadlock with them, so it must finish+ ;; inside the task; other app DBs keep the previous behavior of reindexing asynchronously.+ (try+ (search/reindex! :async? (not= :h2 (mdb/db-type)))+ (catch Exception e+ (log/warn e "Search reindex after import failed")))(remote-sync.task/update-progress! task-id 0.95)imported-data))diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/impl_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/impl_test.cljindex 83a91c67f90..b869909dbdf 100644--- a/enterprise/backend/test/metabase_enterprise/remote_sync/impl_test.clj+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/impl_test.clj@@ -465,6 +465,23 @@(is (= 0.8 (:progress (nth @progress-calls 3))))(is (= 0.95 (:progress (nth @progress-calls 4)))))))))))+(deftest import!-runs-a-single-reindex-inside-the-task-test+ (testing "a full import runs exactly one reindex, synchronous on H2 and asynchronous elsewhere"+ (mt/dataset test-data+ (mt/db)+ (let [task-id (t2/insert-returning-pk! :model/RemoteSyncTask+ {:sync_task_type "import"+ :initiated_by (mt/user->id :rasta)})+ calls (atom [])]+ (mt/with-dynamic-fn-redefs [search/reindex! (fn [& {:as opts}]+ (swap! calls conj opts)+ nil)]+ (let [result (impl/import! (source.p/snapshot (test-helpers/create-mock-source))+ task-id+ :force? true)]+ (is (= :success (:status result)))))+ (is (= [{:async? (not= :h2 (app-db/db-type))}] @calls))))))+(deftest export!-calls-update-progress-with-expected-values-test(testing "export! calls update-progress! with expected progress values"(mt/dataset test-data