-
-
Save gtrak/562db53028a9a9a0218c to your computer and use it in GitHub Desktop.
This file contains 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
(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