Last active
March 19, 2018 22:37
-
-
Save camsaul/9e2fe3b1edde76a01602f38830442438 to your computer and use it in GitHub Desktop.
Debugging Clojure Expectations Tests (Metabase Codebase)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def current-test-name (atom nil)) | |
(defonce my-redef | |
(do (let [orig-fn @#'expectations/test-name] | |
(intern 'expectations 'test-name | |
(fn [metta] | |
(u/prog1 (orig-fn metta) | |
(reset! current-test-name <>) | |
(println "Now we're going to run:" <>))))) | |
:ok)) | |
(defn in-context | |
{:expectations-options :in-context} | |
[f] | |
(u/prog1 (deref (future (f)) | |
(* 15 1000) | |
::timeout) | |
(when (= ::timeout <>) | |
(println (format "Test %s timed out after 15 seconds." @current-test-name)) | |
(println "STACKTRACES:") | |
(doseq [[^Thread thread, stacktrace] (Thread/getAllStackTraces)] | |
(when (seq stacktrace) | |
(println (u/pprint-to-str 'blue (cons (.getName thread) stacktrace))))) | |
(System/exit -1)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assumes you're using
metabase.util