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 schema-viewer writable-Postgres test (#75094)
Stas Gavrylova1d5e4b0716b
diff --git a/e2e/support/helpers/e2e-qa-databases-helpers.js b/e2e/support/helpers/e2e-qa-databases-helpers.jsindex 26b3553d9fa..4646c97bd46 100644--- a/e2e/support/helpers/e2e-qa-databases-helpers.js+++ b/e2e/support/helpers/e2e-qa-databases-helpers.js@@ -352,40 +352,65 @@ export const createModelFromTableName = ({});};+const RESYNC_TRIGGER_INDEX = 10;+const MAX_RESYNC_ITERATIONS = 40;export function waitForSyncToFinish({iteration = 0,dbId = 2,tableName = "",tableAlias,+ tables = [],+ retrigger = false,}) {// 40 x 500ms (20s) should be plenty of time for the sync to finish.- if (iteration === 40) {+ if (iteration === MAX_RESYNC_ITERATIONS) {throw new Error("The sync is taking too long. Something is wrong.");}+ // `sync_schema` submits to a single-threaded task pool and can be queued+ // behind a slow task or bump into an already-running sync, so in some scenarios one-shot+ // schema sync may be silently dropped. If we assume such scenario, we force+ // schema sync to be retriggered occasionally.+ // (https://linear.app/metabase/issue/QUE2-663/calls-to-sync-schema-are-occasionally-silently-dropped)+ if (retrigger && iteration > 0 && iteration % RESYNC_TRIGGER_INDEX === 0) {+ cy.request("POST", `/api/database/${dbId}/sync_schema`);+ }+cy.wait(SYNC_RETRY_DELAY_MS);+ const rerunSync = () =>+ waitForSyncToFinish({+ iteration: iteration + 1,+ dbId,+ tableName,+ tables,+ tableAlias,+ retrigger,+ });+cy.request("GET", `/api/database/${dbId}/metadata`).then(({ body }) => {if (!body.tables.length) {- return waitForSyncToFinish({- iteration: ++iteration,- dbId,- tableName,- tableAlias,- });- } else if (tableName) {+ return rerunSync();+ }++ if (tables.length) {+ const completed = new Set(+ body.tables+ .filter((table) => table.initial_sync_status === "complete")+ .map((table) => table.name),+ );++ return tables.every((name) => completed.has(name)) ? null : rerunSync();+ }++ if (tableName) {const table = body.tables.find((table) =>table.name === tableName && table.initial_sync_status === "complete",);if (!table) {- return waitForSyncToFinish({- iteration: ++iteration,- dbId,- tableName,- tableAlias,- });+ return rerunSync();}if (tableAlias) {@@ -401,11 +426,20 @@ export function resyncDatabase({dbId = 2,tableName = "",tableAlias = undefined, // TS was complaining that this was a required param+ tables,+ retrigger = false,}) {// must be signed in as admin to synccy.request("POST", `/api/database/${dbId}/sync_schema`);cy.request("POST", `/api/database/${dbId}/rescan_values`);- waitForSyncToFinish({ iteration: 0, dbId, tableName, tableAlias });+ waitForSyncToFinish({+ iteration: 0,+ dbId,+ tableName,+ tables,+ tableAlias,+ retrigger,+ });}export function addSqliteDatabase(displayName = "sqlite") {diff --git a/e2e/test/scenarios/schema-viewer/schema-viewer.cy.spec.ts b/e2e/test/scenarios/schema-viewer/schema-viewer.cy.spec.tsindex bc786803e7b..b3e2251e300 100644--- a/e2e/test/scenarios/schema-viewer/schema-viewer.cy.spec.ts+++ b/e2e/test/scenarios/schema-viewer/schema-viewer.cy.spec.ts@@ -62,6 +62,15 @@ const SV_SETUP_SQL = `);`;+const SV_REQUIRED_TABLES = [+ "users",+ "profiles",+ "categories",+ "products",+ "lookup",+ "other",+];+const tableNode = (tableId: TableId) => cy.get(`[data-id="table-${tableId}"]`);const schemaPickerTrigger = () => cy.findByTestId("schema-picker-button");const searchInput = () => cy.findByTestId("schema-viewer-node-search-input");@@ -328,7 +337,11 @@ describe("scenarios > schema-viewer (writable Postgres: multi-schema, self-ref,H.activateToken("bleeding-edge");cy.intercept("GET", "/api/ee/erd*").as(ERD_ALIAS);H.queryWritableDB(SV_SETUP_SQL, "postgres");- H.resyncDatabase({ dbId: WRITABLE_DB_ID });+ H.resyncDatabase({+ dbId: WRITABLE_DB_ID,+ tables: SV_REQUIRED_TABLES,+ retrigger: true,+ });});after(() => {