Skip to content
Snippets Groups Projects
Unverified Commit d2e706ec authored by Raimon Grau's avatar Raimon Grau Committed by GitHub
Browse files

disable settings cache to fix flakiness (#14541)

parent da8fd268
No related branches found
No related tags found
No related merge requests found
......@@ -10,11 +10,13 @@
[metabase.db.connection :as mdb.connection]
[metabase.db.spec :as db.spec]
[metabase.driver :as driver]
[metabase.models :refer [Setting Database]]
[metabase.models :refer [Database Setting]]
[metabase.models.setting :as setting]
[metabase.test :as mt]
[metabase.test.data.interface :as tx]
[metabase.util.encryption-test :as eu]
[metabase.util.files :as u.files]
[metabase.util.i18n.impl :as i18n.impl]
[toucan.db :as db]))
(deftest dump-deletes-target-db-files-tests
......@@ -69,36 +71,38 @@
h2-file-default-enc (format "/tmp/out-%s.db" (mt/random-name))
db-name (str "test_" (mt/random-name))]
(mt/test-drivers #{:h2 :postgres :mysql}
(binding [mdb.connection/*db-type* driver/*driver*
mdb.connection/*jdbc-spec* (persistent-jdbcspec driver/*driver* db-name)
db/*db-connection* (persistent-jdbcspec driver/*driver* db-name)
db/*quoting-style* driver/*driver*]
(when-not (= driver/*driver* :h2)
(tx/create-db! driver/*driver* {:database-name db-name}))
(load-from-h2/load-from-h2! h2-fixture-db-file)
(eu/with-secret-key "89ulvIGoiYw6mNELuOoEZphQafnF/zYe+3vT+v70D1A="
(db/insert! Setting {:key "my-site-admin", :value "baz"})
(db/update! Database 1 {:details "{\"db\":\"/tmp/test.db\"}"})
(dump-to-h2/dump-to-h2! h2-file-plaintext {:dump-plaintext? true})
(dump-to-h2/dump-to-h2! h2-file-enc {:dump-plaintext? false})
(dump-to-h2/dump-to-h2! h2-file-default-enc))
(with-redefs [i18n.impl/site-locale-from-setting-fn (atom (constantly false))]
(binding [setting/*disable-cache* true
mdb.connection/*db-type* driver/*driver*
mdb.connection/*jdbc-spec* (persistent-jdbcspec driver/*driver* db-name)
db/*db-connection* (persistent-jdbcspec driver/*driver* db-name)
db/*quoting-style* driver/*driver*]
(when-not (= driver/*driver* :h2)
(tx/create-db! driver/*driver* {:database-name db-name}))
(load-from-h2/load-from-h2! h2-fixture-db-file)
(eu/with-secret-key "89ulvIGoiYw6mNELuOoEZphQafnF/zYe+3vT+v70D1A="
(db/insert! Setting {:key "my-site-admin", :value "baz"})
(db/update! Database 1 {:details "{\"db\":\"/tmp/test.db\"}"})
(dump-to-h2/dump-to-h2! h2-file-plaintext {:dump-plaintext? true})
(dump-to-h2/dump-to-h2! h2-file-enc {:dump-plaintext? false})
(dump-to-h2/dump-to-h2! h2-file-default-enc))
(testing "decodes settings and dashboard.details"
(jdbc/with-db-connection [target-conn (copy.h2/h2-jdbc-spec h2-file-plaintext)]
(is (= "baz" (:value (first (jdbc/query target-conn "select value from SETTING where key='my-site-admin';")))))
(is (= "{\"db\":\"/tmp/test.db\"}"
(:details (first (jdbc/query target-conn "select details from metabase_database where id=1;")))))))
(testing "decodes settings and dashboard.details"
(jdbc/with-db-connection [target-conn (copy.h2/h2-jdbc-spec h2-file-plaintext)]
(is (= "baz" (:value (first (jdbc/query target-conn "select value from SETTING where key='my-site-admin';")))))
(is (= "{\"db\":\"/tmp/test.db\"}"
(:details (first (jdbc/query target-conn "select details from metabase_database where id=1;")))))))
(testing "when flag is set to false, encrypted settings and dashboard.details are still encrypted"
(jdbc/with-db-connection [target-conn (copy.h2/h2-jdbc-spec h2-file-enc)]
(is (not (= "baz"
(:value (first (jdbc/query target-conn "select value from SETTING where key='my-site-admin';"))))))
(is (not (= "{\"db\":\"/tmp/test.db\"}"
(:details (first (jdbc/query target-conn "select details from metabase_database where id=1;"))))))))
(testing "when flag is set to false, encrypted settings and dashboard.details are still encrypted"
(jdbc/with-db-connection [target-conn (copy.h2/h2-jdbc-spec h2-file-enc)]
(is (not (= "baz"
(:value (first (jdbc/query target-conn "select value from SETTING where key='my-site-admin';"))))))
(is (not (= "{\"db\":\"/tmp/test.db\"}"
(:details (first (jdbc/query target-conn "select details from metabase_database where id=1;"))))))))
(testing "defaults to not decrypting"
(jdbc/with-db-connection [target-conn (copy.h2/h2-jdbc-spec h2-file-default-enc)]
(is (not (= "baz"
(:value (first (jdbc/query target-conn "select value from SETTING where key='my-site-admin';"))))))
(is (not (= "{\"db\":\"/tmp/test.db\"}"
(:details (first (jdbc/query target-conn "select details from metabase_database where id=1;")))))))))))))
(testing "defaults to not decrypting"
(jdbc/with-db-connection [target-conn (copy.h2/h2-jdbc-spec h2-file-default-enc)]
(is (not (= "baz"
(:value (first (jdbc/query target-conn "select value from SETTING where key='my-site-admin';"))))))
(is (not (= "{\"db\":\"/tmp/test.db\"}"
(:details (first (jdbc/query target-conn "select details from metabase_database where id=1;"))))))))))))))
......@@ -6,14 +6,12 @@
[metabase.cmd.dump-to-h2 :as dump-to-h2]
[metabase.cmd.load-from-h2 :as load-from-h2]
[metabase.db.connection :as mdb.connection]
[metabase.db.setup :as mdb.setup]
[metabase.db.spec :as db.spec]
[metabase.driver :as driver]
[metabase.models.setting :as setting]
[metabase.util.i18n.impl :as i18n.impl]
[metabase.test :as mt]
[metabase.test.data.interface :as tx]
[toucan.db :as db]
[toucan.util.test :as tt]))
[metabase.test.data.interface :as tx]))
(defn- abs-path
[path]
......@@ -24,9 +22,10 @@
(let [h2-fixture-db-file (abs-path "frontend/test/__runner__/test_db_fixture.db")
h2-file (abs-path "/tmp/out.db")
db-name "dump-test"]
(mt/test-drivers #{:postgres :mysql :h2}
(mt/test-drivers #{:mysql :postgres :h2}
(h2/delete-existing-h2-database-files! h2-file)
(binding [mdb.connection/*db-type* driver/*driver*
(binding [setting/*disable-cache* true
mdb.connection/*db-type* driver/*driver*
mdb.connection/*jdbc-spec* (if (= driver/*driver* :h2)
{:subprotocol "h2"
:subname (format "mem:%s;DB_CLOSE_DELAY=10" (mt/random-name))
......@@ -36,10 +35,11 @@
((case driver/*driver*
:postgres db.spec/postgres
:mysql db.spec/mysql) details)))]
(when-not (= driver/*driver* :h2)
(tx/create-db! driver/*driver* {:database-name db-name}))
(load-from-h2/load-from-h2! h2-fixture-db-file)
(dump-to-h2/dump-to-h2! h2-file)
(is (not (compare-h2-dbs/different-contents?
h2-file
h2-fixture-db-file))))))))
(with-redefs [i18n.impl/site-locale-from-setting-fn (atom (constantly false))]
(when-not (= driver/*driver* :h2)
(tx/create-db! driver/*driver* {:database-name db-name}))
(load-from-h2/load-from-h2! h2-fixture-db-file)
(dump-to-h2/dump-to-h2! h2-file)
(is (not (compare-h2-dbs/different-contents?
h2-file
h2-fixture-db-file)))))))))
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