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
Make the e2e create a copy of the sample db, so it doesn't run into locking issues with core app (#64120)
Nicolò Pretto49152f6a3641
diff --git a/e2e/runner/run_cypress_local.ts b/e2e/runner/run_cypress_local.tsindex 6b9bfc9cbdc..83fb7288571 100644--- a/e2e/runner/run_cypress_local.ts+++ b/e2e/runner/run_cypress_local.ts@@ -1,3 +1,7 @@+import fs from "fs";+import os from "os";+import path from "path";+import { FAILURE_EXIT_CODE, SUCCESS_EXIT_CODE } from "./constants/exit-code";import CypressBackend from "./cypress-runner-backend";import runCypress from "./cypress-runner-run-tests";@@ -10,6 +14,8 @@ import {import { startHostAppContainers } from "./embedding-sdk/host-apps/start-host-app-containers";import { startSampleAppContainers } from "./embedding-sdk/sample-apps/start-sample-app-containers";+let tempSampleDBDir: string | null = null;+// if you want to change these, set them as environment variables in your shellconst userOptions = {TEST_SUITE: "e2e", // e2e | component@@ -92,6 +98,14 @@ const init = async () => {process.exit(FAILURE_EXIT_CODE);}+ // Use a temporary copy of the sample db so it won't use and lock the db used for local development+ tempSampleDBDir = path.join(+ os.tmpdir(),+ `metabase-sample-db-e2e-${process.pid}`,+ );+ fs.mkdirSync(tempSampleDBDir, { recursive: true });+ process.env.MB_INTERNAL_DO_NOT_USE_SAMPLE_DB_DIR = tempSampleDBDir;+printBold("⏳ Starting backend");await CypressBackend.start();}@@ -147,6 +161,20 @@ const cleanup = async (exitCode: string | number = SUCCESS_EXIT_CODE) => {await CypressBackend.stop();}+ // Add cleanup for the temporary sample database directory+ if (tempSampleDBDir) {+ try {+ fs.rmSync(tempSampleDBDir, { recursive: true, force: true });+ printBold(+ `🗑️ Cleaned up temporary sample database directory: ${tempSampleDBDir}`,+ );+ } catch (e) {+ console.error(+ `Error cleaning up temporary sample database directory: ${e}`,+ );+ }+ }+if (options.STOP_CONTAINERS) {printBold("⏳ Stopping containers");shell("docker compose -f ./e2e/test/scenarios/docker-compose.yml down");diff --git a/src/metabase/sample_data/impl.clj b/src/metabase/sample_data/impl.cljindex c6c939c6335..587117bb1b9 100644--- a/src/metabase/sample_data/impl.clj+++ b/src/metabase/sample_data/impl.clj@@ -18,11 +18,19 @@(def ^:private ^String sample-database-name "Sample Database")(def ^:private ^String sample-database-filename "sample-database.db.mv.db")+(defn- sample-db-dir-from-env+ "Change the folder from which we load the sample database, used locally to avoid E2E to use the same file used for local development"+ []+ (when-let [path (System/getenv "MB_INTERNAL_DO_NOT_USE_SAMPLE_DB_DIR")]+ (u.files/get-path path)))+;; Reuse the plugins directory for the destination to extract the sample database because it's pretty much guaranteed;; to exist and be writable.(defn- target-path[]- (u.files/append-to-path (plugins/plugins-dir) sample-database-filename))+ (let [base-dir (or (sample-db-dir-from-env)+ (plugins/plugins-dir))]+ (u.files/append-to-path base-dir sample-database-filename)))(defn- process-sample-db-path[base-path]