Skip to content
Snippets Groups Projects
Unverified Commit 41773668 authored by Jeff Evans's avatar Jeff Evans Committed by GitHub
Browse files

Isolate BigQuery legacy and new driver test runs (#17626)

* Randomize BigQuery test view names

Use tu/random-name instead of a name based on the output of gensym

* Add extra prefix for legacy BigQuery driver created databases

* Update legacy BigQuery driver to have unique name for transient datasets

For those datasets created and destroyed by the legacy BigQuery driver QP tests, add an additional prefix so that it doesn't conflict with the new BigQuery driver tests
parent dd6f0cc4
No related merge requests found
......@@ -16,6 +16,7 @@
[metabase.sync :as sync]
[metabase.test :as mt]
[metabase.test.data.bigquery-cloud-sdk :as bigquery.tx]
[metabase.test.util :as tu]
[metabase.test.util.timezone :as tu.tz]
[metabase.util :as u]
[metabase.util.honeysql-extensions :as hx]
......@@ -487,7 +488,7 @@
(defn- do-with-datetime-timestamp-table [f]
(driver/with-driver :bigquery-cloud-sdk
(let [table-name (name (munge (gensym "table_")))]
(let [table-name (format "table_%s" (tu/random-name))]
(mt/with-temp-copy-of-db
(try
(bigquery.tx/execute!
......
......@@ -76,7 +76,7 @@
(defn- do-with-view [f]
(driver/with-driver :bigquery-cloud-sdk
(let [view-name (name (munge (gensym "view_")))]
(let [view-name (format "view_%s" (tu/random-name))]
(mt/with-temp-copy-of-db
(try
(bigquery.tx/execute!
......
......@@ -16,6 +16,7 @@
[metabase.sync :as sync]
[metabase.test :as mt]
[metabase.test.data.bigquery :as bigquery.tx]
[metabase.test.util :as tu]
[metabase.test.util.timezone :as tu.tz]
[metabase.util :as u]
[metabase.util.honeysql-extensions :as hx]
......@@ -223,27 +224,27 @@
(deftest remove-remark-test
(mt/test-driver :bigquery
(is (= (str
"SELECT `v3_test_data.venues`.`id` AS `id`,"
" `v3_test_data.venues`.`name` AS `name` "
"FROM `v3_test_data.venues` "
"LIMIT 1")
(tt/with-temp* [Database [db {:engine :bigquery
:details (assoc (:details (mt/db))
:include-user-id-and-hash false)}]
Table [table {:name "venues" :db_id (u/the-id db)}]
Field [_ {:table_id (u/the-id table)
:name "id"
:base_type "type/Integer"}]
Field [_ {:table_id (u/the-id table)
:name "name"
:base_type "type/Text"}]]
(query->native
{:database (u/the-id db)
:type :query
:query {:source-table (u/the-id table)
:limit 1}
:info {:executed-by 1000
:query-hash (byte-array [1 2 3 4])}}))))))
"SELECT `v3_test_data.venues`.`id` AS `id`,"
" `v3_test_data.venues`.`name` AS `name` "
"FROM `v3_test_data.venues` "
"LIMIT 1")
(tt/with-temp* [Database [db {:engine :bigquery
:details (assoc (:details (mt/db))
:include-user-id-and-hash false)}]
Table [table {:name "venues" :db_id (u/the-id db)}]
Field [_ {:table_id (u/the-id table)
:name "id"
:base_type "type/Integer"}]
Field [_ {:table_id (u/the-id table)
:name "name"
:base_type "type/Text"}]]
(query->native
{:database (u/the-id db)
:type :query
:query {:source-table (u/the-id table)
:limit 1}
:info {:executed-by 1000
:query-hash (byte-array [1 2 3 4])}}))))))
(deftest unprepare-params-test
(mt/test-driver :bigquery
......@@ -487,7 +488,7 @@
(defn- do-with-datetime-timestamp-table [f]
(driver/with-driver :bigquery
(let [table-name (name (munge (gensym "table_")))]
(let [table-name (format "table_%s" (tu/random-name))]
(mt/with-temp-copy-of-db
(try
(bigquery.tx/execute!
......
......@@ -58,7 +58,7 @@
(defn- do-with-view [f]
(driver/with-driver :bigquery
(let [view-name (name (munge (gensym "view_")))]
(let [view-name (format "view_%s" (tu/random-name))]
(mt/with-temp-copy-of-db
(try
(bigquery.tx/execute!
......
......@@ -33,10 +33,27 @@
;;; ----------------------------------------------- Connection Details -----------------------------------------------
;; keep track of databases we have already created
(def ^:private existing-datasets
(atom #{}))
(def ^:private current-dataset-version-prefix "v3_")
(defn- prefix-legacydriver-if-new
"Adds a legacydriver_ prefix to the db-name, if the `existing-dataset` atom does not contain it. This is to ensure
that transient datasets created and destroyed by these tests do not interfere with parallel test runs for the new
BigQuery driver (which are also creating and destroying datasets that would have the same name, if not for this
change). If the `db-name` is already an existing one, however, the assumption is it's not transient (i.e. not being
created and destroyed at test time), and hence, it can keep its name without modification."
[db-name]
(if (contains? @existing-datasets db-name)
db-name
(str/replace-first db-name current-dataset-version-prefix (str current-dataset-version-prefix "legacydriver_"))))
(defn- normalize-name ^String [db-or-table-or-field identifier]
(let [s (str/replace (name identifier) "-" "_")]
(case db-or-table-or-field
:db (str "v3_" s)
:db (prefix-legacydriver-if-new (str current-dataset-version-prefix s))
(:table :field) s)))
(def ^:private details
......@@ -325,10 +342,6 @@
:when (not (str/includes? dataset-name "checkins_interval_"))]
dataset-name))
;; keep track of databases we haven't created yet
(def ^:private existing-datasets
(atom #{}))
(defmethod tx/create-db! :bigquery [_ {:keys [database-name table-definitions]} & _]
{:pre [(seq database-name) (sequential? table-definitions)]}
;; fetch existing datasets if we haven't done so yet
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment