Skip to content

Commit d4e2129

Browse files
committed
no need to check if already hooked
robert.hooke/add-hook handles repeated calls nicely
1 parent 0780287 commit d4e2129

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/clj_http_hystrix/core.clj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,4 @@
134134
"Activate clj-http-hystrix to wrap all clj-http client requests as
135135
hystrix commands."
136136
[]
137-
(when-not (some-> (meta http/request) :robert.hooke/hooks deref (contains? #'wrap-hystrix))
138-
(hooke/add-hook #'http/request #'wrap-hystrix)))
137+
(hooke/add-hook #'http/request #'wrap-hystrix))

test/clj_http_hystrix/core_test.clj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[clj-http.client :as http]
55
[clojure.java.io :refer [resource]]
66
[clojure.tools.logging :refer [warn error]]
7+
[robert.hooke :as hooke]
78
[rest-cljer.core :refer [rest-driven]]
89
[midje.sweet :refer :all])
910
(:import [java.net SocketTimeoutException]
@@ -171,3 +172,14 @@
171172
(predicate {} {:status 101}) => false
172173
(predicate {} {:status 202}) => false
173174
(predicate {} {:status 299}) => false))
175+
176+
(defn get-hooks []
177+
(some-> http/request meta :robert.hooke/hooks deref))
178+
179+
(fact "add-hook can be safely called more than once"
180+
(count (get-hooks)) => 1
181+
(get (get-hooks) #'wrap-hystrix) => #'wrap-hystrix
182+
;call add-hook a few more times and ensure only one hook is present
183+
(add-hook), (add-hook), (add-hook)
184+
(count (get-hooks)) => 1
185+
(get (get-hooks) #'wrap-hystrix) => #'wrap-hystrix)

0 commit comments

Comments
 (0)