mount

ido 2017-10-24T13:31:59.000299Z

hey @tolitius, I have a question regarding unit testing. we have a project that it's api is basically core.async/channels. you push a message on one side, and pull the result on another. so far so good. now, as one could expect, each test does exactly this (>!! c-in msg) (process) (<!! c-out) (assertions msg). for that, we used (use-fixtures :each common-mocks-fixture) where common-mocks-fixture is swapping the kafka consumer and producer of the service with just a map with a channel. as such: (defn common-mocks-fixture [test-fn] (start-mocks) (test-fn) (mount/stop) `(defn start-mocks [] (-> (only common-test-states) ; this is just a set of states (mount/swap-states common-test-swaps) ;see below start))` `(def common-test-swaps {#'kc/alglaunches-mi-consumer {:start (fn [] {:channel (chan 1)}) :stop #(close! (:channel kc/alglaunches-mi-consumer))} #'kp/pre-matches-producer {:start (fn [] {:channel (chan 1)}) :stop #(close! (:channel kp/pre-matches-producer))}})` This theoretically should work, but still. if a test calls (process) that leaves a message in the outgoing channel, the next test fails. any clue what are we doing wrong?

tolitius 2017-10-24T14:10:43.000704Z

hey @ido (I am driving: i.e. typing slow), but why do you have anonymous :stop functions? why not:

:stop (close! (:channel kc/alglaunches-mi-consumer))
:stop (close! (:channel kp/pre-matches-producer))
by quickly looking at it I suspect these channels are simply don't close between tests

tolitius 2017-10-24T14:12:05.000187Z

also :start could be

:start {:channel (chan 1)}

tolitius 2017-10-24T14:12:33.000271Z

i.e. https://github.com/tolitius/mount#value-of-values