Skip to content

Commit

Permalink
All timing information.
Browse files Browse the repository at this point in the history
  • Loading branch information
neotyk committed May 5, 2012
1 parent 7909169 commit 49a3c8f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/clj/http/async/client/timing.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)}))
16 changes: 15 additions & 1 deletion test/http/async/client/test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 49a3c8f

Please sign in to comment.