Skip to content

Instantly share code, notes, and snippets.

@camsaul
Last active March 19, 2018 22:37
Show Gist options
  • Save camsaul/9e2fe3b1edde76a01602f38830442438 to your computer and use it in GitHub Desktop.
Save camsaul/9e2fe3b1edde76a01602f38830442438 to your computer and use it in GitHub Desktop.
Debugging Clojure Expectations Tests (Metabase Codebase)
(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))))
@camsaul
Copy link
Author

camsaul commented Mar 19, 2018

Assumes you're using metabase.util

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment