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

Commit

Permalink
Use new state protocols in lambdacd.state.internal.pipeline-state-upd…
Browse files Browse the repository at this point in the history
…ater-test and reformat it #131
  • Loading branch information
flosell committed Oct 22, 2016
1 parent 0b02adc commit 8b690d0
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions test/clj/lambdacd/state/internal/pipeline_state_updater_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,43 @@
(:refer-clojure :exclude [alias update])
(:require [clojure.test :refer :all]
[lambdacd.state.internal.pipeline-state-updater :refer :all]
[lambdacd.internal.pipeline-state :refer [PipelineStateComponent]]
[lambdacd.state.protocols :as protocols]
[lambdacd.testsupport.test-util :as tu]
[lambdacd.testsupport.data :refer [some-ctx-with some-ctx]]
[lambdacd.event-bus :as event-bus]))

(deftest pipeline-state-updater-test
(testing "that we tap into the event bus update the pipeline state with its information"
(let [updates (atom [])
pipeline-state (reify PipelineStateComponent
(update [self build-number step-id step-result]
(swap! updates #(conj %1 [build-number step-id step-result]))))
ctx (some-ctx-with :pipeline-state-component pipeline-state)]
(testing "that we tap into the event bus update the pipeline state with its information"
(let [updates (atom [])
pipeline-state (reify protocols/StepResultUpdateConsumer
(consume-step-result-update [self build-number step-id step-result]
(swap! updates #(conj %1 [build-number step-id step-result]))))
ctx (some-ctx-with :pipeline-state-component pipeline-state)]

(event-bus/publish ctx :step-result-updated {:build-number 1 :step-id [1 2] :step-result {:status :running}})
(event-bus/publish ctx :step-result-updated {:build-number 2 :step-id [1 2] :step-result {:status :success}})
(event-bus/publish ctx :step-result-updated {:build-number 1 :step-id [1 2] :step-result {:status :running :foo :bar}})
(event-bus/publish ctx :step-result-updated {:build-number 1 :step-id [1 2] :step-result {:status :running}})
(event-bus/publish ctx :step-result-updated {:build-number 2 :step-id [1 2] :step-result {:status :success}})
(event-bus/publish ctx :step-result-updated {:build-number 1 :step-id [1 2] :step-result {:status :running :foo :bar}})

(wait-for (= 3 (count @updates)))
(is (= [[1 [1 2] {:status :running}]
[2 [1 2] {:status :success}]
[1 [1 2] {:status :running :foo :bar}]] @updates))))
(testing "shutdown behavior"
(testing "that the pipeline-state-updater can be stopped with a message on the event bus"
(let [pipeline-state (reify PipelineStateComponent
(update [_ _ _ _]
(throw (Exception. "no update expected"))))
ctx (some-ctx-with :pipeline-state-component pipeline-state)
updater-finished-ch (start-pipeline-state-updater ctx)]
(tu/call-with-timeout 1000 (stop-pipeline-state-updater (assoc ctx :pipeline-state-updater updater-finished-ch)))
(is (not= {:status :timeout} (tu/get-or-timeout updater-finished-ch :timeout 1000)))))
(testing "that stopping is idempotent"
(let [pipeline-state (reify PipelineStateComponent
(update [_ _ _ _]
(throw (Exception. "no update expected"))))
ctx (some-ctx-with :pipeline-state-component pipeline-state)
updater-finished-ch (start-pipeline-state-updater ctx)]
(tu/call-with-timeout 1000 (stop-pipeline-state-updater (assoc ctx :pipeline-state-updater updater-finished-ch)))
(tu/call-with-timeout 1000 (stop-pipeline-state-updater (assoc ctx :pipeline-state-updater updater-finished-ch)))
(is (not= {:status :timeout} (tu/get-or-timeout updater-finished-ch :timeout 1000)))
(tu/call-with-timeout 1000 (stop-pipeline-state-updater (assoc ctx :pipeline-state-updater updater-finished-ch)))))))
(wait-for (= 3 (count @updates)))
(is (= [[1 [1 2] {:status :running}]
[2 [1 2] {:status :success}]
[1 [1 2] {:status :running :foo :bar}]] @updates))))
(testing "shutdown behavior"
(testing "that the pipeline-state-updater can be stopped with a message on the event bus"
(let [pipeline-state (reify protocols/StepResultUpdateConsumer
(consume-step-result-update [_ _ _ _]
(throw (Exception. "no update expected"))))
ctx (some-ctx-with :pipeline-state-component pipeline-state)
updater-finished-ch (start-pipeline-state-updater ctx)]
(tu/call-with-timeout 1000 (stop-pipeline-state-updater (assoc ctx :pipeline-state-updater updater-finished-ch)))
(is (not= {:status :timeout} (tu/get-or-timeout updater-finished-ch :timeout 1000)))))
(testing "that stopping is idempotent"
(let [pipeline-state (reify protocols/StepResultUpdateConsumer
(consume-step-result-update [_ _ _ _]
(throw (Exception. "no update expected"))))
ctx (some-ctx-with :pipeline-state-component pipeline-state)
updater-finished-ch (start-pipeline-state-updater ctx)]
(tu/call-with-timeout 1000 (stop-pipeline-state-updater (assoc ctx :pipeline-state-updater updater-finished-ch)))
(tu/call-with-timeout 1000 (stop-pipeline-state-updater (assoc ctx :pipeline-state-updater updater-finished-ch)))
(is (not= {:status :timeout} (tu/get-or-timeout updater-finished-ch :timeout 1000)))
(tu/call-with-timeout 1000 (stop-pipeline-state-updater (assoc ctx :pipeline-state-updater updater-finished-ch)))))))

0 comments on commit 8b690d0

Please sign in to comment.