Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

All timing information.

  • Loading branch information...
commit 49a3c8fa6751aa87b15bbebf8189d0139a55aebd 1 parent 7909169
@neotyk authored
View
17 src/clj/http/async/client/timing.clj
@@ -40,3 +40,20 @@
"Time it took (in milliseconds) from request execution to failure."
[response]
(/ (double (- @(:error-time response) @(:started-time response))) 1000000.0))
+
+(defn all-times
+ "All times that are already available, in milliseconds."
+ [response]
+ (let [start @(:started-time response)
+ get-nb (fn [k] (let [p (k response)] (when (realized? p) @p)))
+ status (get-nb :status-time)
+ headers (get-nb :headers-time)
+ body (get-nb :body-time)
+ done (get-nb :done-time)
+ error (get-nb :error-time)
+ safe-time (fn [t] (when t (/ (double (- t start)) 1000000.0)))]
+ {:status (safe-time status)
+ :headers (safe-time headers)
+ :body (safe-time body)
+ :done (safe-time done)
+ :error (safe-time error)}))
View
16 test/http/async/client/test.clj
@@ -804,7 +804,21 @@
(is (realized? (:error-time resp)))
(when (realized? (:error-time resp))
(is (< 0 (error-time resp))))))
- (testing "events partial order"
+ (testing "all timing - success response"
+ (let [resp (GET *client* "http://localhost:8123/body")
+ _ (await resp)
+ t (all-times resp)]
+ (are [k] (not (nil? (k t)))
+ :status :headers :body :done)
+ (is (nil? (:error t)))))
+ (testing "all timing - failed response"
+ (let [resp (GET *client* "http://incanters.do.not.exist.or.do.they/")
+ _ (await resp)
+ t (all-times resp)]
+ (is (not (nil? (:error t))))
+ (are [k] (nil? (k t))
+ :status :headers :body :done)))
+ (testing "events order"
(let [resp (GET *client* "http://localhost:8123/body")
_ (await resp)]
(is (< (status-time resp)
Please sign in to comment.
Something went wrong with that request. Please try again.