From d5f3a61890fac404bf7846523ce85269005946ec Mon Sep 17 00:00:00 2001 From: Moritz Heidkamp Date: Thu, 18 Sep 2025 14:02:24 +0200 Subject: [PATCH 1/2] Fix dropped errors in tests Also, make test-alt a bit more reliable and make the exception messages distinct so that a dropped error can easily be matched up with the deferred. --- test/manifold/deferred_test.clj | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/test/manifold/deferred_test.clj b/test/manifold/deferred_test.clj index 9475afa..be44310 100644 --- a/test/manifold/deferred_test.clj +++ b/test/manifold/deferred_test.clj @@ -287,21 +287,27 @@ (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 100) 1) 2))) - (is (= 2 @(d/alt (d/future (Thread/sleep 10) (throw (Exception. "boom"))) 2))) + (let [ef (d/future (Thread/sleep 100) (throw (Exception. "boom 1")))] + ;; to silence dropped error detection + (d/catch ef identity) + (is (= 2 @(d/alt ef 2)))) (is (thrown-with-msg? Exception #"boom" - @(d/alt (d/future (throw (Exception. "boom"))) (d/future (Thread/sleep 10))))) + @(d/alt (d/future (throw (Exception. "boom 2"))) + (d/future (Thread/sleep 100))))) (testing "uniformly distributed" (let [results (atom {}) From ec01b4aa811c9c88a9a5224b9a1f92ade149e855 Mon Sep 17 00:00:00 2001 From: Moritz Heidkamp Date: Wed, 1 Oct 2025 11:14:14 +0200 Subject: [PATCH 2/2] Make test-alt fully deterministic Involving `d/future` makes these tests needlessly flaky. By decoupling the `d/alt` invocation from dereferencing its result, we can deterministically control the order of events. --- test/manifold/deferred_test.clj | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/test/manifold/deferred_test.clj b/test/manifold/deferred_test.clj index be44310..5677356 100644 --- a/test/manifold/deferred_test.clj +++ b/test/manifold/deferred_test.clj @@ -298,16 +298,24 @@ (deftest test-alt (is (#{1 2 3} @(d/alt 1 2 3))) - (is (= 2 @(d/alt (d/future (Thread/sleep 100) 1) 2))) - - (let [ef (d/future (Thread/sleep 100) (throw (Exception. "boom 1")))] - ;; to silence dropped error detection - (d/catch ef identity) - (is (= 2 @(d/alt ef 2)))) - - (is (thrown-with-msg? Exception #"boom" - @(d/alt (d/future (throw (Exception. "boom 2"))) - (d/future (Thread/sleep 100))))) + (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 {})