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

View file

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