Fork me on GitHub
#core-async
<
2016-05-14
>
mpuppe14:05:08

Hi, I’m wondering how I could write tests for functions that use core.async. Say I have the following function:

(defn foo
  []
  (go
    (a/<! (a/timeout 1000))
    42))
There is a similar question on Stack Overflow: http://stackoverflow.com/q/30766215 Is it possible to write a test, that * fails if the channel returned by foo does not provide any value within 5 seconds, * fails if the channel provides anything else than 42, * fails if the channel does not close after providing 42, * does not block other tests from running? (That’s the hard part!)

hiredman19:05:07

looking at the example in the stack overflow post, my immediate reaction is his mistake is using the go macro in a test

hiredman19:05:53

use the blocking <!! and >!! and alts!!!!! (or however many bangs it is) in tests

hiredman19:05:30

there is no reason not to, and your tests will be simpler for it