Fork me on GitHub

Thanks for your answer. The go blocks really are not necessary. I’ve written the following test:

(deftest foo-test
  (let [to-chan1 (a/timeout 5000)
        foo-chan (foo)
        [v1 ch1] (a/alts!! [foo-chan to-chan1])
        to-chan2 (a/timeout 100)
        [v2 ch2] (a/alts!! [to-chan2 foo-chan])]
    (is (not= ch1 to-chan1) "Channel provides a value within 5 seconds.")
    (is (= v1 42) "Channel provides 42.")
    (is (and (= ch2 foo-chan) (nil? v2))
        "Channel closes after providing the first value.")))
But it may block the test thread for up to 5 seconds. Is there any way around that?


if whatever is writing to the channel takes five seconds to do that, and and you want to test that, it will take five seconds to test