Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
niwinz committed Oct 21, 2023
1 parent 52a37f9 commit 6cc14a7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
35 changes: 28 additions & 7 deletions src/promesa/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@
(:import
java.lang.reflect.Method
java.time.Duration
java.util.concurrent.CancellationException
java.util.concurrent.CompletionException
java.util.concurrent.CompletionStage
java.util.concurrent.CountDownLatch
java.util.concurrent.locks.ReentrantLock
;; java.util.function.BiConsumer
;; java.util.function.BiFunction
;; java.util.function.Consumer
;; java.util.function.Function
;; java.util.function.Supplier
)))
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
java.util.concurrent.locks.ReentrantLock)))

#?(:clj (set! *warn-on-reflection* true))

Expand All @@ -45,6 +42,30 @@
(.thenCompose ^CompletionStage it
^java.util.function.Function f-identity)))

#?(:clj
(defn completion-exception?
{:no-doc true}
[e]
(instance? CompletionException e)))

#?(:clj
(defn execution-exception?
{:no-doc true}
[e]
(instance? ExecutionException e)))

#?(:clj
(defn cancellation-exception?
{:no-doc true}
[e]
(instance? CancellationException e)))

#?(:clj
(defn timeout-exception?
{:no-doc true}
[e]
(instance? TimeoutException e)))

#?(:clj
(defn unwrap-completion-exception
{:no-doc true}
Expand Down
16 changes: 8 additions & 8 deletions test/promesa/tests/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
[promesa.tests.util :refer [promise-ok promise-ko normalize-to-value]]
[promesa.core :as p :include-macros true]
[promesa.protocols :as pt]
[promesa.exec :as px])
#?(:clj
(:import
java.util.concurrent.CancellationException
java.util.concurrent.TimeoutException)))
[promesa.util :as pu]
[promesa.exec :as px]))

;; --- Core Interface Tests

Expand Down Expand Up @@ -262,7 +259,9 @@
#?(:clj
(let [v1 (p/await p1)]
(t/is (p/rejected? p1))
(t/is (= "foobar" (ex-message v1))))
(t/is (pu/execution-exception? v1))
(t/is (= "clojure.lang.ExceptionInfo: foobar {}" (ex-message v1)))
(t/is (= "foobar" (ex-message (ex-cause v1)))))
:cljs
(t/async done
(p/finally p1 (fn [v c]
Expand Down Expand Up @@ -496,7 +495,8 @@
(p/timeout 50))]
#?(:clj
(let [v1 (p/await p1)]
(t/is (instance? TimeoutException v1)))
(t/is (pu/execution-exception? v1))
(t/is (pu/timeout-exception? (ex-cause v1))))

:cljs
(t/async done
Expand Down Expand Up @@ -816,7 +816,7 @@
(t/is (p/rejected? c1))
(t/is (= @c2 2))
(t/is (= v2 2))
(t/is (instance? CancellationException v1)))
(t/is (pu/cancellation-exception? v1)))

:cljs
(t/async done
Expand Down

0 comments on commit 6cc14a7

Please sign in to comment.