Skip to content
Snippets Groups Projects
Commit 4e6bd7c3 authored by Simon Belak's avatar Simon Belak
Browse files

Merge branch 'master' of github.com:metabase/metabase into xray-insights-batch1

parents 98aa5bc3 914255b5
No related branches found
No related tags found
No related merge requests found
......@@ -121,7 +121,8 @@
:uberjar-name "metabase.jar"
:ring {:handler metabase.core/app
:init metabase.core/init!
:destroy metabase.core/destroy}
:destroy metabase.core/destroy
:reload-paths ["src"]}
:eastwood {:exclude-namespaces [:test-paths
metabase.driver.generic-sql] ; ISQLDriver causes Eastwood to fail. Skip this ns until issue is fixed: https://github.com/jonase/eastwood/issues/191
:add-linters [:unused-private-vars
......@@ -147,16 +148,16 @@
:exclusions [org.clojure/clojure
org.clojure/tools.namespace]]]
:env {:mb-run-mode "dev"}
:jvm-opts ["-Dlogfile.path=target/log"
"-Xms1024m" ; give JVM a decent heap size to start with
"-Xmx2048m"] ; hard limit of 2GB so we stop hitting the 4GB container limit on CircleCI
:jvm-opts ["-Dlogfile.path=target/log"]
:aot [metabase.logger]} ; Log appender class needs to be compiled for log4j to use it
:reflection-warnings {:global-vars {*warn-on-reflection* true}} ; run `lein check-reflection-warnings` to check for reflection warnings
:expectations {:injections [(require 'metabase.test-setup)]
:resource-paths ["test_resources"]
:env {:mb-test-setting-1 "ABCDEFG"
:mb-run-mode "test"}
:jvm-opts ["-Duser.timezone=UTC"
:jvm-opts ["-Xms1024m" ; give JVM a decent heap size to start with
"-Xmx2048m" ; hard limit of 2GB so we stop hitting the 4GB container limit on CircleCI
"-Duser.timezone=UTC"
"-Dmb.db.in.memory=true"
"-Dmb.jetty.join=false"
"-Dmb.jetty.port=3010"
......
(ns expectation-options
"Namspace expectations will automatically load before running a tests")
(defn- tables-with-data->error-msg
"Function that takes a list of modes and whill query each. If records are found, return a string with an error
message"
[models-to-check]
(for [model models-to-check
:let [instances-found (count (model))
more-than-one? (> 1 instances-found)]
:when (< 0 instances-found)]
(str "Found '" instances-found "' instance" (when more-than-one? "s")
" of '" (:name model) "' that " (if more-than-one? "were" "was")
" not cleaned up.")))
(def ^:private models-to-check
"Add models from `metabase.models.*` to the following vector to have the `check-table-cleanup` function below error
if any instances of that model are found after each test finishes."
[])
(defn check-table-cleanup
"Function that will run around each test. This function is usually a noop, but it useful for helping to debug stale
data in local development. Modify the private `models-to-check` var to check if there are any rows in the given
model's table after each expectation. If a row is found, the relevant information will be written to standard out
and the test run will exit"
{:expectations-options :in-context}
[test-fn]
(let [result (test-fn)]
;; The typical case is no models-to-check, this then becomes a noop
(when (seq models-to-check)
(let [{:keys [file line]} (-> test-fn meta :the-var meta)
error-msgs (tables-with-data->error-msg models-to-check)]
(when (seq error-msgs)
(println "\n-----------------------------------------------------")
(doseq [error-msg error-msgs]
(println error-msg))
(println "-----------------------------------------------------")
(printf "\nStale test rows found in tables, check '%s' at line '%s'\n\n" file line)
(flush)
;; I found this necessary as throwing an exception would show the exception, but the test run would hang and
;; you'd have to Ctrl-C anyway
(System/exit 1))))
result))
......@@ -28,6 +28,7 @@
[user :refer [User]]]
[metabase.test.data :as data]
[metabase.test.data.datasets :refer [*driver*]]
[toucan.db :as db]
[toucan.util.test :as test])
(:import java.util.TimeZone
[org.joda.time DateTime DateTimeZone]
......@@ -451,3 +452,13 @@
"Invokes `BODY` with the JVM timezone set to `DTZ`"
[dtz & body]
`(call-with-jvm-tz ~dtz (fn [] ~@body)))
(defmacro with-model-cleanup
"This will delete all rows found for each model in `MODEL-SEQ`. This calls `delete!`, so if the model has defined
any `pre-delete` behavior, that will be preserved."
[model-seq & body]
`(try
~@body
(finally
(doseq [model# ~model-seq]
(db/delete! model#)))))
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