Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions test/manifold/deferred_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -287,21 +287,35 @@
(deftest test-finally
(let [target-d (d/deferred)
d (d/deferred)
fd (d/finally
d
(fn []
(d/success! target-d ::delivered)))]
fd (-> d
(d/finally
(fn []
(d/success! target-d ::delivered)))
;; to silence dropped error detection
(d/catch identity))]
(d/error! d (Exception.))
(is (= ::delivered (deref target-d 0 ::not-delivered)))))

(deftest test-alt
(is (#{1 2 3} @(d/alt 1 2 3)))
(is (= 2 @(d/alt (d/future (Thread/sleep 10) 1) 2)))

(is (= 2 @(d/alt (d/future (Thread/sleep 10) (throw (Exception. "boom"))) 2)))

(is (thrown-with-msg? Exception #"boom"
@(d/alt (d/future (throw (Exception. "boom"))) (d/future (Thread/sleep 10)))))
(let [d (d/deferred)
a (d/alt d 2)]
(d/success! d 1)
(is (= 2 @a)))

(let [d (d/deferred)
a (d/alt d 2)]
(doto d
(d/error! (Exception. "boom 1"))
;; to silence dropped error detection
(d/catch identity))
(is (= 2 @a)))

(let [e (d/error-deferred (Exception. "boom 2"))
d (d/deferred)
a (d/alt e d)]
(d/success! d 1)
(is (thrown-with-msg? Exception #"boom" @a)))

(testing "uniformly distributed"
(let [results (atom {})
Expand Down