Skip to content

Instantly share code, notes, and snippets.

@gtrak
Created October 27, 2012 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gtrak/562db53028a9a9a0218c to your computer and use it in GitHub Desktop.
Save gtrak/562db53028a9a9a0218c to your computer and use it in GitHub Desktop.
(defn report-exception
"We can't just throw exceptions from fixtures because it screws everything
and hangs the main test runner thread. But, we can steal the reporting
method from clojure.test, which is what this is."
[e]
(report {:type :error, :message e
:expected nil, :actual e}))
(defn check-agent-exceptions
"HOF"
[running-agent]
(fn [f]
(let [prior (error-handler running-agent)
exceptions (atom [])]
(set-error-handler! running-agent (fn [a e] (swap! exceptions conj e)))
(f)
(await running-agent)
(set-error-handler! running-agent prior)
(if-not (empty? @exceptions)
(report-exception (ex-info "Exceptions found in agent"
{:agent running-agent
:errors @exceptions}))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment