diff --git a/backend/junit/test/metabase/junit.clj b/backend/junit/test/metabase/junit.clj index e7e73bf0943199895dcdbc573caded413e1b7604..eb08b98aad70e91f65b537d7ab7758432f29eda4 100644 --- a/backend/junit/test/metabase/junit.clj +++ b/backend/junit/test/metabase/junit.clj @@ -5,7 +5,9 @@ [string :as str]] [metabase.util :as u] [pjstadig.print :as p] - [test-report-junit-xml.core :as junit-xml])) + [test-report-junit-xml.core :as junit-xml] + [test_report_junit_xml.shaded.clojure.data.xml :as xml]) + #_(:import org.apache.commons.lang3.StringEscapeUtils)) (defn- event-description [{:keys [file line context message]}] (str @@ -15,32 +17,35 @@ (when message (str "\n" message)))) +(defn- print-expected [expected actual] + (p/rprint "expected: ") + (pp/pprint expected) + (p/rprint " actual: ") + (pp/pprint actual) + (p/clear)) + (defn- result-output [{:keys [expected actual diffs message], :as event}] - (with-redefs [u/colorize? (constantly false)] - (with-out-str - (println (event-description event)) - ;; this code is adapted from `pjstadig.util` - (p/with-pretty-writer - (fn [] - (let [print-expected (fn [actual] - (p/rprint "expected: ") - (pp/pprint expected) - (p/rprint " actual: ") - (pp/pprint actual) - (p/clear))] - (if (seq diffs) - (doseq [[actual [a b]] diffs] - (print-expected actual) - (p/rprint " diff:") - (if a - (do (p/rprint " - ") - (pp/pprint a) - (p/rprint " + ")) - (p/rprint " + ")) - (when b - (pp/pprint b)) - (p/clear)) - (print-expected actual)))))))) + (let [s (with-out-str + (println (event-description event)) + ;; this code is adapted from `pjstadig.util` + (p/with-pretty-writer + (fn [] + (if (seq diffs) + (doseq [[actual [a b]] diffs] + (print-expected expected actual) + (p/rprint " diff:") + (if a + (do (p/rprint " - ") + (pp/pprint a) + (p/rprint " + ")) + (p/rprint " + ")) + (when b + (pp/pprint b)) + (p/clear)) + (print-expected expected actual)))))] + ;; remove ANSI color escape sequences, then encode things as character entities as needed + (u/decolorize s) + #_(-> s u/decolorize StringEscapeUtils/escapeXml11))) (defmulti format-result {:arglists '([event])} @@ -53,4 +58,4 @@ (defmethod format-result :fail [event] {:tag :failure - :content (result-output event)}) + :content (xml/cdata (result-output event))}) diff --git a/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar.jsx b/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar.jsx index 2c1af6cbed691814b7684224fd1c384436e06801..4dcad4c0588f36e1766b484ff5558de33011ce3d 100644 --- a/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar.jsx +++ b/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar.jsx @@ -148,11 +148,11 @@ const Column = ({ column, clickBehavior, onClick }) => ( <h4> {clickBehavior && clickBehavior.type === "crossfilter" ? (n => - t`${ngettext( + ngettext( msgid`${column.display_name} updates ${n} filter`, `${column.display_name} updates ${n} filters`, n, - )}`)(Object.keys(clickBehavior.parameterMapping).length) + ))(Object.keys(clickBehavior.parameterMapping).length) : clickBehavior && clickBehavior.type === "link" ? jt`${column.display_name} goes to ${( <LinkTargetName clickBehavior={clickBehavior} /> diff --git a/modules/drivers/google/project.clj b/modules/drivers/google/project.clj index cf94b367210ddb239d9e0af50d8fc2d51e9bf457..a7152cd0d05d44e2111c13529e73b87d342fabcc 100644 --- a/modules/drivers/google/project.clj +++ b/modules/drivers/google/project.clj @@ -11,6 +11,7 @@ {:provided {:dependencies [[org.clojure/clojure "1.10.1"] + [com.fasterxml.jackson.core/jackson-core "2.10.2"] ; Not sure why this is needed -- this is a dep of metabase-core [metabase-core "1.0.0-SNAPSHOT"]]} :install-for-building-drivers diff --git a/src/metabase/sync.clj b/src/metabase/sync.clj index a1c47f0bab2548e8beee5e5e56c64638a274b93b..1b23b6515ffd745ae7b7de3b80062cb326abc698 100644 --- a/src/metabase/sync.clj +++ b/src/metabase/sync.clj @@ -32,7 +32,6 @@ ;; Finally, update cached FieldValues (field-values/update-field-values! database))) - (s/defn sync-table! "Perform all the different sync operations synchronously for a given `table`." [table :- i/TableInstance] diff --git a/src/metabase/task/sync_databases.clj b/src/metabase/task/sync_databases.clj index 6d69111ca9528fb58cffc1d43be01adcc472b403..3d808aa692905c884d63baa5b0b7ec5ef53b1116 100644 --- a/src/metabase/task/sync_databases.clj +++ b/src/metabase/task/sync_databases.clj @@ -37,7 +37,7 @@ ;; The DisallowConcurrentExecution on the two defrecords below attaches an annotation to the generated class that will ;; constrain the job execution to only be one at a time. Other triggers wanting the job to run will misfire. -(defn sync-and-analyze-database +(defn- sync-and-analyze-database! "The sync and analyze database job, as a function that can be used in a test" [job-context] (when-let [database-id (job-context->database-id job-context)] @@ -49,12 +49,12 @@ (sync-metadata/sync-db-metadata! database) ;; only run analysis if this is a "full sync" database (when (:is_full_sync database) - (analyze/analyze-db! database)))) ) + (analyze/analyze-db! database))))) (jobs/defjob ^{org.quartz.DisallowConcurrentExecution true} SyncAndAnalyzeDatabase [job-context] - (sync-and-analyze-database job-context)) + (sync-and-analyze-database! job-context)) -(defn update-field-values +(defn- update-field-values! "The update field values job, as a function that can be used in a test" [job-context] (when-let [database-id (job-context->database-id job-context)] @@ -68,7 +68,7 @@ (log/info (trs "Skipping update, automatic Field value updates are disabled for Database {0}." database-id)))))) (jobs/defjob ^{org.quartz.DisallowConcurrentExecution true} UpdateFieldValues [job-context] - (update-field-values job-context)) + (update-field-values! job-context)) ;;; +----------------------------------------------------------------------------------------------------------------+ ;;; | TASK INFO AND GETTER FUNCTIONS | diff --git a/src/metabase/util.clj b/src/metabase/util.clj index 9e160e6863978f5cf57e84739632bbe88f02f997..fee5d04ed477670dd7d7a27293caf321df87fec0 100644 --- a/src/metabase/util.clj +++ b/src/metabase/util.clj @@ -223,6 +223,11 @@ (fn [_ x] (str x)))) +(defn decolorize + "Remove ANSI escape sequences from a String `s`." + ^String [s] + (some-> s (str/replace #"\[[;\d]*m" ""))) + (defn format-color "With one arg, converts something to a string and colorizes it. With two args, behaves like `format`, but colorizes the output. diff --git a/test/metabase/models/params/chain_filter_test.clj b/test/metabase/models/params/chain_filter_test.clj index 83a1e378945ae92d00e93b16c306cea18226759d..1a89e136088f05a1fb4ead761785d4c181250c39 100644 --- a/test/metabase/models/params/chain_filter_test.clj +++ b/test/metabase/models/params/chain_filter_test.clj @@ -13,65 +13,61 @@ ~@options)) (deftest chain-filter-test - (mt/test-drivers (mt/normal-drivers) - (testing "Show me expensive restaurants" - (is (= ["Dal Rae Restaurant" - "Lawry's The Prime Rib" - "Pacific Dining Car - Santa Monica" - "Sushi Nakazawa" - "Sushi Yasuda" - "Tanoshi Sushi & Sake Bar"] - (chain-filter venues.name {venues.price 4})))) - (testing "Show me categories that have expensive restaurants" + (testing "Show me expensive restaurants" + (is (= ["Dal Rae Restaurant" + "Lawry's The Prime Rib" + "Pacific Dining Car - Santa Monica" + "Sushi Nakazawa" + "Sushi Yasuda" + "Tanoshi Sushi & Sake Bar"] + (chain-filter venues.name {venues.price 4})))) + (testing "Show me categories that have expensive restaurants" + (is (= ["Japanese" "Steakhouse"] + (chain-filter categories.name {venues.price 4}))) + (testing "Should work with string versions of param values" (is (= ["Japanese" "Steakhouse"] - (chain-filter categories.name {venues.price 4}))) - (testing "Should work with string versions of param values" - (is (= ["Japanese" "Steakhouse"] - (chain-filter categories.name {venues.price "4"}))))) - (testing "Show me categories starting with s (case-insensitive) that have expensive restaurants" - (is (= ["Steakhouse"] - (chain-filter categories.name {venues.price 4, categories.name [:starts-with "s" {:case-sensitive false}]})))) - (testing "Show me cheap Thai restaurants" - (is (= ["Kinaree Thai Bistro" "Krua Siri"] - (chain-filter venues.name {venues.price 1, categories.name "Thai"})))) - (testing "Show me the categories that have cheap restaurants" - (is (= ["Asian" "BBQ" "Bakery" "Bar" "Burger" "Caribbean" "Deli" "Karaoke" "Mexican" "Pizza" "Southern" "Thai"] - (chain-filter categories.name {venues.price 1})))) - (testing "Show me cheap restaurants with the word 'taco' in their name (case-insensitive)" - (is (= ["Tacos Villa Corona" "Tito's Tacos"] - (chain-filter venues.name {venues.price 1, venues.name [:contains "tAcO" {:case-sensitive false}]})))) - (testing "Show me the first 3 expensive restaurants" - (is (= ["Dal Rae Restaurant" "Lawry's The Prime Rib" "Pacific Dining Car - Santa Monica"] - (chain-filter venues.name {venues.price 4} :limit 3)))) - (testing "Oh yeah, we actually support arbitrary MBQL filter clauses. Neat!" - (is (= ["Festa" "Fred 62"] - (chain-filter venues.name {venues.price [:between 2 3] - venues.name [:starts-with "f" {:case-sensitive false}]})))))) + (chain-filter categories.name {venues.price "4"}))))) + (testing "Show me categories starting with s (case-insensitive) that have expensive restaurants" + (is (= ["Steakhouse"] + (chain-filter categories.name {venues.price 4, categories.name [:starts-with "s" {:case-sensitive false}]})))) + (testing "Show me cheap Thai restaurants" + (is (= ["Kinaree Thai Bistro" "Krua Siri"] + (chain-filter venues.name {venues.price 1, categories.name "Thai"})))) + (testing "Show me the categories that have cheap restaurants" + (is (= ["Asian" "BBQ" "Bakery" "Bar" "Burger" "Caribbean" "Deli" "Karaoke" "Mexican" "Pizza" "Southern" "Thai"] + (chain-filter categories.name {venues.price 1})))) + (testing "Show me cheap restaurants with the word 'taco' in their name (case-insensitive)" + (is (= ["Tacos Villa Corona" "Tito's Tacos"] + (chain-filter venues.name {venues.price 1, venues.name [:contains "tAcO" {:case-sensitive false}]})))) + (testing "Show me the first 3 expensive restaurants" + (is (= ["Dal Rae Restaurant" "Lawry's The Prime Rib" "Pacific Dining Car - Santa Monica"] + (chain-filter venues.name {venues.price 4} :limit 3)))) + (testing "Oh yeah, we actually support arbitrary MBQL filter clauses. Neat!" + (is (= ["Festa" "Fred 62"] + (chain-filter venues.name {venues.price [:between 2 3] + venues.name [:starts-with "f" {:case-sensitive false}]}))))) (deftest multiple-values-test - (mt/test-drivers (mt/normal-drivers) - (testing "Chain filtering should support multiple values for a single parameter (as a vector or set of values)" - (testing "Show me restaurants with price = 1 or 2 with the word 'BBQ' in their name (case-sensitive)" - (is (= ["Baby Blues BBQ" "Beachwood BBQ & Brewing" "Bludso's BBQ"] - (chain-filter venues.name {venues.price #{1 2}, venues.name [:contains "BBQ"]})))) - (testing "Show me the possible values of price for Bakery *or* BBQ restaurants" - (is (= [1 2 3] - (chain-filter venues.price {categories.name ["Bakery" "BBQ"]}))))))) + (testing "Chain filtering should support multiple values for a single parameter (as a vector or set of values)" + (testing "Show me restaurants with price = 1 or 2 with the word 'BBQ' in their name (case-sensitive)" + (is (= ["Baby Blues BBQ" "Beachwood BBQ & Brewing" "Bludso's BBQ"] + (chain-filter venues.name {venues.price #{1 2}, venues.name [:contains "BBQ"]})))) + (testing "Show me the possible values of price for Bakery *or* BBQ restaurants" + (is (= [1 2 3] + (chain-filter venues.price {categories.name ["Bakery" "BBQ"]})))))) (deftest auto-parse-string-params-test - (mt/test-drivers (mt/normal-drivers) - (testing "Parameters that come in as strings (i.e., all of them that come in via the API) should work as intended" - (is (= ["Baby Blues BBQ" "Beachwood BBQ & Brewing" "Bludso's BBQ"] - (chain-filter venues.name {venues.price ["1" "2"], venues.name [:contains "BBQ"]})))))) + (testing "Parameters that come in as strings (i.e., all of them that come in via the API) should work as intended" + (is (= ["Baby Blues BBQ" "Beachwood BBQ & Brewing" "Bludso's BBQ"] + (chain-filter venues.name {venues.price ["1" "2"], venues.name [:contains "BBQ"]}))))) (deftest unrelated-params-test - (mt/test-drivers (mt/normal-drivers) - (testing "Parameters that are completely unrelated (don't apply to this Table) should just get ignored entirely" - ;; there is no way to join from venues -> users so users.id should get ignored - (binding [chain-filter/*enable-reverse-joins* false] - (is (= [1 2 3] - (chain-filter venues.price {categories.name ["Bakery" "BBQ"] - users.id [1 2 3]}))))))) + (testing "Parameters that are completely unrelated (don't apply to this Table) should just get ignored entirely" + ;; there is no way to join from venues -> users so users.id should get ignored + (binding [chain-filter/*enable-reverse-joins* false] + (is (= [1 2 3] + (chain-filter venues.price {categories.name ["Bakery" "BBQ"] + users.id [1 2 3]})))))) (deftest find-joins-test (mt/dataset airports @@ -119,40 +115,39 @@ (#'chain-filter/find-all-joins $$airport #{%region.name %municipality.name %region.id})))))))) (deftest multi-hop-test - (mt/test-drivers (mt/normal-drivers) - (mt/dataset airports - (testing "Should be able to filter against other tables with that require multiple joins\n" - (testing "single direct join: Airport -> Municipality" - (is (= ["San Francisco International Airport"] - (chain-filter airport.name {municipality.name ["San Francisco"]})))) - (testing "2 joins required: Airport -> Municipality -> Region" - (is (= ["Beale Air Force Base" - "Edwards Air Force Base" - "John Wayne Airport-Orange County Airport"] - (take 3 (chain-filter airport.name {region.name ["California"]}))))) - (testing "3 joins required: Airport -> Municipality -> Region -> Country" - (is (= ["Abraham Lincoln Capital Airport" - "Albuquerque International Sunport" - "Altus Air Force Base"] - (take 3 (chain-filter airport.name {country.name ["United States"]}))))) - (testing "4 joins required: Airport -> Municipality -> Region -> Country -> Continent" - (is (= ["Afonso Pena Airport" - "Alejandro Velasco Astete International Airport" - "Carrasco International /General C L Berisso Airport"] - (take 3 (chain-filter airport.name {continent.name ["South America"]}))))) - (testing "[backwards]" - (testing "single direct join: Municipality -> Airport" - (is (= ["San Francisco"] - (chain-filter municipality.name {airport.name ["San Francisco International Airport"]})))) - (testing "2 joins required: Region -> Municipality -> Airport" - (is (= ["California"] - (chain-filter region.name {airport.name ["San Francisco International Airport"]})))) - (testing "3 joins required: Country -> Region -> Municipality -> Airport" - (is (= ["United States"] - (chain-filter country.name {airport.name ["San Francisco International Airport"]})))) - (testing "4 joins required: Continent -> Region -> Municipality -> Airport" - (is (= ["North America"] - (chain-filter continent.name {airport.name ["San Francisco International Airport"]}))))))))) + (mt/dataset airports + (testing "Should be able to filter against other tables with that require multiple joins\n" + (testing "single direct join: Airport -> Municipality" + (is (= ["San Francisco International Airport"] + (chain-filter airport.name {municipality.name ["San Francisco"]})))) + (testing "2 joins required: Airport -> Municipality -> Region" + (is (= ["Beale Air Force Base" + "Edwards Air Force Base" + "John Wayne Airport-Orange County Airport"] + (take 3 (chain-filter airport.name {region.name ["California"]}))))) + (testing "3 joins required: Airport -> Municipality -> Region -> Country" + (is (= ["Abraham Lincoln Capital Airport" + "Albuquerque International Sunport" + "Altus Air Force Base"] + (take 3 (chain-filter airport.name {country.name ["United States"]}))))) + (testing "4 joins required: Airport -> Municipality -> Region -> Country -> Continent" + (is (= ["Afonso Pena Airport" + "Alejandro Velasco Astete International Airport" + "Carrasco International /General C L Berisso Airport"] + (take 3 (chain-filter airport.name {continent.name ["South America"]}))))) + (testing "[backwards]" + (testing "single direct join: Municipality -> Airport" + (is (= ["San Francisco"] + (chain-filter municipality.name {airport.name ["San Francisco International Airport"]})))) + (testing "2 joins required: Region -> Municipality -> Airport" + (is (= ["California"] + (chain-filter region.name {airport.name ["San Francisco International Airport"]})))) + (testing "3 joins required: Country -> Region -> Municipality -> Airport" + (is (= ["United States"] + (chain-filter country.name {airport.name ["San Francisco International Airport"]})))) + (testing "4 joins required: Continent -> Region -> Municipality -> Airport" + (is (= ["North America"] + (chain-filter continent.name {airport.name ["San Francisco International Airport"]})))))))) (deftest filterable-field-ids-test (mt/$ids diff --git a/test/metabase/task/sync_databases_test.clj b/test/metabase/task/sync_databases_test.clj index 024409ead39b87a0090fea036939c21892141aa5..7923444f69a88f93b86959744266b0f5f59e4222 100644 --- a/test/metabase/task/sync_databases_test.clj +++ b/test/metabase/task/sync_databases_test.clj @@ -5,13 +5,18 @@ (:require [clojure [string :as str] [test :refer :all]] + [metabase + [test :as mt] + [util :as u]] [metabase.models.database :refer [Database]] + [metabase.sync + [analyze :as sync.analyze] + [field-values :as sync.field-values] + [sync-metadata :as sync.metadata]] [metabase.task.sync-databases :as sync-db] [metabase.test.util :as tu] - [metabase.util :as u] [metabase.util.date-2 :as u.date] - [toucan.db :as db] - [toucan.util.test :as tt]) + [toucan.db :as db]) (:import [metabase.task.sync_databases SyncAndAnalyzeDatabase UpdateFieldValues])) (deftest annotations-test @@ -66,7 +71,7 @@ (deftest new-db-jobs-scheduled-test (is (= [sync-job fv-job] (with-scheduler-setup - (tt/with-temp Database [database {:engine :postgres}] + (mt/with-temp Database [database {:engine :postgres}] (current-tasks-for-db database)))))) ;; Check that a custom schedule is respected when creating a new Database @@ -74,7 +79,7 @@ (is (= [(assoc-in sync-job [:triggers 0 :cron-schedule] "0 30 4,16 * * ? *") (assoc-in fv-job [:triggers 0 :cron-schedule] "0 15 10 ? * 6#3")] (with-scheduler-setup - (tt/with-temp Database [database {:engine :postgres + (mt/with-temp Database [database {:engine :postgres :metadata_sync_schedule "0 30 4,16 * * ? *" ; 4:30 AM and PM daily :cache_field_values_schedule "0 15 10 ? * 6#3"}] ; 10:15 on the 3rd Friday of the Month (current-tasks-for-db database)))))) @@ -84,7 +89,7 @@ (is (= [(update sync-job :triggers empty) (update fv-job :triggers empty)] (with-scheduler-setup - (tt/with-temp Database [database {:engine :postgres}] + (mt/with-temp Database [database {:engine :postgres}] (db/delete! Database :id (u/get-id database)) (current-tasks-for-db database)))))) @@ -93,7 +98,7 @@ (is (= [(assoc-in sync-job [:triggers 0 :cron-schedule] "0 15 10 ? * MON-FRI") (assoc-in fv-job [:triggers 0 :cron-schedule] "0 11 11 11 11 ?")] (with-scheduler-setup - (tt/with-temp Database [database {:engine :postgres}] + (mt/with-temp Database [database {:engine :postgres}] (db/update! Database (u/get-id database) :metadata_sync_schedule "0 15 10 ? * MON-FRI" ; 10:15 AM every weekday :cache_field_values_schedule "0 11 11 11 11 ?") ; Every November 11th at 11:11 AM @@ -104,7 +109,7 @@ (is (= [sync-job (assoc-in fv-job [:triggers 0 :cron-schedule] "0 15 10 ? * MON-FRI")] (with-scheduler-setup - (tt/with-temp Database [database {:engine :postgres}] + (mt/with-temp Database [database {:engine :postgres}] (db/update! Database (u/get-id database) :cache_field_values_schedule "0 15 10 ? * MON-FRI") (current-tasks-for-db database))))) @@ -112,7 +117,7 @@ (is (= [(assoc-in sync-job [:triggers 0 :cron-schedule] "0 15 10 ? * MON-FRI") fv-job] (with-scheduler-setup - (tt/with-temp Database [database {:engine :postgres}] + (mt/with-temp Database [database {:engine :postgres}] (db/update! Database (u/get-id database) :metadata_sync_schedule "0 15 10 ? * MON-FRI") (current-tasks-for-db database)))))) @@ -126,7 +131,7 @@ (db/insert! Database {:engine :postgres, k "0 * ABCD"})))))) (testing "Check that you can't UPDATE a DB's schedule to something invalid" - (tt/with-temp Database [database {:engine :postgres}] + (mt/with-temp Database [database {:engine :postgres}] (doseq [k [:metadata_sync_schedule :cache_field_values_schedule]] (testing (format "Update %s" k) (is (thrown? @@ -145,9 +150,9 @@ (deftest check-orphaned-jobs-removed-test (testing "jobs for orphaned databases are removed during sync run" (with-scheduler-setup - (doseq [sync-fn [sync-db/update-field-values sync-db/sync-and-analyze-database]] + (doseq [sync-fn [#'sync-db/update-field-values! #'sync-db/sync-and-analyze-database!]] (testing (str sync-fn) - (tt/with-temp Database [database {:engine :postgres}] + (mt/with-temp Database [database {:engine :postgres}] (let [db-id (:id database)] (is (= [sync-job fv-job] (current-tasks-for-db database))) @@ -164,9 +169,7 @@ ;;; | CHECKING THAT SYNC TASKS RUN CORRECT FNS | ;;; +----------------------------------------------------------------------------------------------------------------+ -;; TODO - it would be nice if we could rework this test so we didn't have to wait for so long to see if things -;; happened or not -(defn- check-if-sync-processes-ran-for-db {:style/indent 0} [db-info] +(defn- check-if-sync-processes-ran-for-db {:style/indent 0} [waits db-info] (let [sync-db-metadata-ran? (promise) analyze-db-ran? (promise) update-field-values-ran? (promise)] @@ -174,42 +177,52 @@ metabase.sync.analyze/analyze-db! (fn [& _] (deliver analyze-db-ran? true)) metabase.sync.field-values/update-field-values! (fn [& _] (deliver update-field-values-ran? true))] (with-scheduler-setup - (tt/with-temp Database [database db-info] - {:ran-sync? (deref sync-db-metadata-ran? 1000 false) - :ran-analyze? (deref analyze-db-ran? 200 false) - :ran-update-field-values? (deref update-field-values-ran? 500 false)}))))) + (mt/with-temp Database [database db-info] + ;; deref the promises in parallel so they all get sufficient time to run. + (into {} (pmap (fn [[k promis]] + (let [wait-time-ms (or (get waits k) + (throw (ex-info (str "Don't know how long to wait for " k) {})))] + [k (deref promis wait-time-ms false)])) + {:ran-sync? sync-db-metadata-ran? + :ran-analyze? analyze-db-ran? + :ran-update-field-values? update-field-values-ran?}))))))) (defn- cron-schedule-for-next-year [] (format "0 15 10 * * ? %d" (inc (u.date/extract :year)))) (deftest check-sync-tasks-run-test - (testing "Make sure that a database that *is* marked full sync *will* get analyzed" - (is (= {:ran-sync? true, :ran-analyze? true, :ran-update-field-values? false} - (check-if-sync-processes-ran-for-db - {:engine :postgres - :metadata_sync_schedule "* * * * * ? *" - :cache_field_values_schedule (cron-schedule-for-next-year)})))) - - (testing "Make sure that a database that *isn't* marked full sync won't get analyzed" - (is (= {:ran-sync? true, :ran-analyze? false, :ran-update-field-values? false} - (check-if-sync-processes-ran-for-db - {:engine :postgres - :is_full_sync false - :metadata_sync_schedule "* * * * * ? *" - :cache_field_values_schedule (cron-schedule-for-next-year)})))) - - (testing "Make sure the update field values task calls `update-field-values!`" - (is (= {:ran-sync? false, :ran-analyze? false, :ran-update-field-values? true} - (check-if-sync-processes-ran-for-db - {:engine :postgres - :is_full_sync true - :metadata_sync_schedule (cron-schedule-for-next-year) - :cache_field_values_schedule "* * * * * ? *"})))) - - (testing "...but if DB is not \"full sync\" it should not get updated FieldValues" - (is (= {:ran-sync? false, :ran-analyze? false, :ran-update-field-values? false} - (check-if-sync-processes-ran-for-db - {:engine :postgres - :is_full_sync false - :metadata_sync_schedule (cron-schedule-for-next-year) - :cache_field_values_schedule "* * * * * ? *"}))))) + (u/profile "new" + (testing "Make sure that a database that *is* marked full sync *will* get analyzed" + (is (= {:ran-sync? true, :ran-analyze? true, :ran-update-field-values? false} + (check-if-sync-processes-ran-for-db + {:ran-sync? 3000, :ran-analyze? 3000, :ran-update-field-values? 500} + {:engine :postgres + :metadata_sync_schedule "* * * * * ? *" + :cache_field_values_schedule (cron-schedule-for-next-year)})))) + + (testing "Make sure that a database that *isn't* marked full sync won't get analyzed" + (is (= {:ran-sync? true, :ran-analyze? false, :ran-update-field-values? false} + (check-if-sync-processes-ran-for-db + {:ran-sync? 3000, :ran-analyze? 500, :ran-update-field-values? 500} + {:engine :postgres + :is_full_sync false + :metadata_sync_schedule "* * * * * ? *" + :cache_field_values_schedule (cron-schedule-for-next-year)})))) + + (testing "Make sure the update field values task calls `update-field-values!`" + (is (= {:ran-sync? false, :ran-analyze? false, :ran-update-field-values? true} + (check-if-sync-processes-ran-for-db + {:ran-sync? 500, :ran-analyze? 500, :ran-update-field-values? 3000} + {:engine :postgres + :is_full_sync true + :metadata_sync_schedule (cron-schedule-for-next-year) + :cache_field_values_schedule "* * * * * ? *"})))) + + (testing "...but if DB is not \"full sync\" it should not get updated FieldValues" + (is (= {:ran-sync? false, :ran-analyze? false, :ran-update-field-values? false} + (check-if-sync-processes-ran-for-db + {:ran-sync? 500, :ran-analyze? 500, :ran-update-field-values? 500} + {:engine :postgres + :is_full_sync false + :metadata_sync_schedule (cron-schedule-for-next-year) + :cache_field_values_schedule "* * * * * ? *"})))))) diff --git a/test/metabase/util_test.clj b/test/metabase/util_test.clj index f4e149475edead29d12bfcd77f25c893b0928ad9..7f7213424fa6961b2dbdfd51592802969c2509b6 100644 --- a/test/metabase/util_test.clj +++ b/test/metabase/util_test.clj @@ -7,6 +7,16 @@ [test :as mt] [util :as u]])) +(deftest decolorize-test + (is (= "[31mmessage[0m" + (u/colorize 'red "message"))) + (is (= "message" + (u/decolorize "[31mmessage[0m"))) + (is (= "message" + (u/decolorize (u/colorize 'red "message")))) + (is (= nil + (u/decolorize nil)))) + (defn- are+-message [expr arglist args] (pr-str (second diff --git a/test_resources/log4j2-test.xml b/test_resources/log4j2-test.xml index fdd87adecb90d41cecde3df655cbc82a2e626a62..20cc2d68c81f62ab76b84dcb2388079bf9fc7177 100644 --- a/test_resources/log4j2-test.xml +++ b/test_resources/log4j2-test.xml @@ -7,11 +7,6 @@ </Appenders> <Loggers> <Logger name="metabase" level="FATAL"/> - <Logger name="metabase.driver" level="INFO"/> - <Logger name="metabase.plugins" level="INFO"/> - <Logger name="metabase.test-setup" level="INFO"/> - <Logger name="metabase.test.data.datasets" level="INFO"/> - <Logger name="metabase.test.data" level="INFO"/> <Root level="ERROR"> <AppenderRef ref="Console"/>