Enable context handling on tests.

This makes the test exection more similar to the real
environment. Each test is executed in the eventloop
thread pool.
This commit is contained in:
Andrey Antukh 2020-02-06 09:46:24 +01:00
parent da29f8db86
commit f37c9a5adb
2 changed files with 17 additions and 9 deletions

View file

@ -17,7 +17,10 @@
[uxbox.util.blob :as blob]
[uxbox.util.uuid :as uuid]
[uxbox.util.storage :as ust]
[uxbox.config :as cfg]))
[uxbox.config :as cfg]
[vertx.util :as vu]))
(def ^:dynamic *context* nil)
(defn state-init
[next]
@ -33,7 +36,8 @@
(mount/swap {#'uxbox.config/config config})
(mount/start))
(try
(next)
(binding [*context* (vu/get-or-create-context uxbox.core/system)]
(next))
(finally
(mount/stop)))))
@ -120,13 +124,17 @@
(catch Exception e#
[(handle-error e#) nil])))
(defmacro try-on!
[expr]
`(try
(let [result# (deref ~expr)]
{:error nil
:result result#})
(let [d# (p/deferred)]
(->> #(p/finally ~expr (fn [v# e#]
(if e#
(p/reject! d# e#)
(p/resolve! d# v#))))
(vu/run-on-context! *context*))
(array-map :error nil
:result (deref d#)))
(catch Exception e#
{:error (handle-error e#)
:result nil})))

View file

@ -96,8 +96,7 @@
:width 800
:height 800}
out (with-redefs [vc/*context* (vc/get-or-create-context system)]
(th/try-on! (sm/handle data)))]
out (th/try-on! (sm/handle data))]
;; (th/print-result! out)
@ -110,7 +109,8 @@
(t/is (string? (get-in out [:result :path])))
(t/is (string? (get-in out [:result :thumb-path])))
(t/is (string? (get-in out [:result :uri])))
(t/is (string? (get-in out [:result :thumb-uri])))))
(t/is (string? (get-in out [:result :thumb-uri])))
))
(t/deftest mutation-import-image-file-from-collection
(let [user @(th/create-user db/pool 1)