Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

Commit

Permalink
make build-duration public (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
flosell committed Feb 7, 2016
1 parent 293775e commit cdceaf4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The official release will have a defined and more stable API. If you are already
* `lambdacd.presentation.pipeline-state/overall-build-status`
* `lambdacd.presentation.pipeline-state/latest-most-recent-update`
* `lambdacd.presentation.pipeline-state/earliest-first-update`
* `lambdacd.presentation.pipeline-state/build-duration`
* UI: Link LambdaCD header to "/" to link back to overview in cases with multiple pipelines (#82)
* Bugs:
* `with-workspace` now creates temporary directories in the home-dir (#79)
Expand Down
2 changes: 1 addition & 1 deletion src/clj/lambdacd/presentation/pipeline_state.clj
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
(defn- interval-duration [interval]
(t/in-seconds interval))

(defn- build-duration [step-ids-and-results]
(defn build-duration [step-ids-and-results]
(->> step-ids-and-results
(vals)
(filter not-waiting?)
Expand Down
53 changes: 24 additions & 29 deletions test/clj/lambdacd/presentation/pipeline_state_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,6 @@
(is (= after-stop-time (:most-recent-update-at (first
(history-for {5 {'(0) {:status :success :most-recent-update-at stop-time :first-updated-at start-time}
'(1) {:status :success :most-recent-update-at after-stop-time :first-updated-at start-time}}})))))))
(testing "calculation of build duration"
(testing "the normal case"
(is (= 20 (:duration-in-sec (first
(history-for {7 {'(2) {:status :success :most-recent-update-at after-twenty-sec :first-updated-at after-ten-sec}
'(1) {:status :success :most-recent-update-at after-ten-sec :first-updated-at start-time}}}))))))
(testing "more than one minute"
(is (= 90 (:duration-in-sec (first
(history-for {7 {'(2) {:status :success :most-recent-update-at after-one-minute-and-30-sec :first-updated-at after-ten-sec}
'(1) {:status :success :most-recent-update-at after-ten-sec :first-updated-at start-time}}}))))))
(testing "can deal with hiccups in timestamps"
(is (= 0 (:duration-in-sec (first
(history-for {7 {'(1) {:status :success :most-recent-update-at start-time :first-updated-at after-ten-sec}}}))))))
(testing "retriggered pipeline takes as long as all intervals where the pipeline was active"
(is (= 40 (:duration-in-sec (first
(history-for {7 {'(1 2) {:status :success :most-recent-update-at after-thirty-sec :first-updated-at after-ten-sec :retrigger-mock-for-build-number 10}
'(2 2) {:status :success :most-recent-update-at after-one-minute-and-40-sec :first-updated-at after-one-minute-and-30-sec}
'(2) {:status :success :most-recent-update-at after-one-minute-and-40-sec :first-updated-at after-one-minute-and-30-sec}
'(1) {:status :success :most-recent-update-at after-ten-sec :first-updated-at start-time :retrigger-mock-for-build-number 10}}}))))))
(testing "steps that wait aren't considered"
(is (= 20 (:duration-in-sec (first
(history-for {7 {'(3) {:status :success :most-recent-update-at after-thirty-sec :first-updated-at after-twenty-sec}
'(2) {:status :success :most-recent-update-at after-twenty-sec :first-updated-at after-ten-sec :has-been-waiting true}
'(1) {:status :success :most-recent-update-at after-ten-sec :first-updated-at start-time :retrigger-mock-for-build-number 10}}}))))))
(testing "durations of child-steps aren't considered"
(is (= 20 (:duration-in-sec (first
(history-for {7 {'(1 2) {:status :success :most-recent-update-at after-thirty-sec :first-updated-at after-ten-sec}
'(2) {:status :success :most-recent-update-at after-twenty-sec :first-updated-at after-ten-sec}
'(1) {:status :success :most-recent-update-at after-ten-sec :first-updated-at start-time}}})))))))
(testing "that the build-status is accumulated correctly"
(testing "that a pipeline will be a failure once there is a failed step"
(is (= :failure (:status (first
Expand Down Expand Up @@ -144,4 +116,27 @@
'(1) {:status :success :most-recent-update-at stop-time :first-updated-at before-start-time :retrigger-mock-for-build-number 3}}))))
(testing "that nil is returned if the build wasn't retriggered"
(is (= nil (build-that-was-retriggered {'(2) {:status :success :most-recent-update-at stop-time :first-updated-at start-time}
'(1) {:status :success :most-recent-update-at stop-time :first-updated-at before-start-time}})))))
'(1) {:status :success :most-recent-update-at stop-time :first-updated-at before-start-time}})))))

(deftest build-duration-test
(testing "the normal case"
(is (= 20 (build-duration {'(2) {:status :success :most-recent-update-at after-twenty-sec :first-updated-at after-ten-sec}
'(1) {:status :success :most-recent-update-at after-ten-sec :first-updated-at start-time}}))))
(testing "more than one minute"
(is (= 90 (build-duration {'(2) {:status :success :most-recent-update-at after-one-minute-and-30-sec :first-updated-at after-ten-sec}
'(1) {:status :success :most-recent-update-at after-ten-sec :first-updated-at start-time}}))))
(testing "can deal with hiccups in timestamps"
(is (= 0 (build-duration {'(1) {:status :success :most-recent-update-at start-time :first-updated-at after-ten-sec}}))))
(testing "retriggered pipeline takes as long as all intervals where the pipeline was active"
(is (= 40 (build-duration {'(1 2) {:status :success :most-recent-update-at after-thirty-sec :first-updated-at after-ten-sec :retrigger-mock-for-build-number 10}
'(2 2) {:status :success :most-recent-update-at after-one-minute-and-40-sec :first-updated-at after-one-minute-and-30-sec}
'(2) {:status :success :most-recent-update-at after-one-minute-and-40-sec :first-updated-at after-one-minute-and-30-sec}
'(1) {:status :success :most-recent-update-at after-ten-sec :first-updated-at start-time :retrigger-mock-for-build-number 10}}))))
(testing "steps that wait aren't considered"
(is (= 20 (build-duration {'(3) {:status :success :most-recent-update-at after-thirty-sec :first-updated-at after-twenty-sec}
'(2) {:status :success :most-recent-update-at after-twenty-sec :first-updated-at after-ten-sec :has-been-waiting true}
'(1) {:status :success :most-recent-update-at after-ten-sec :first-updated-at start-time :retrigger-mock-for-build-number 10}}))))
(testing "durations of child-steps aren't considered"
(is (= 20 (build-duration {'(1 2) {:status :success :most-recent-update-at after-thirty-sec :first-updated-at after-ten-sec}
'(2) {:status :success :most-recent-update-at after-twenty-sec :first-updated-at after-ten-sec}
'(1) {:status :success :most-recent-update-at after-ten-sec :first-updated-at start-time}})))))

0 comments on commit cdceaf4

Please sign in to comment.