Skip to content

Commit

Permalink
refactored run to start-container because more accurate
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoKramer committed Mar 2, 2020
1 parent 04d51c0 commit 47fc68a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/bob/api/health.clj
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
(log/debugf (str "Health check succeeded!"))
(log/warn (str "Health check failed: " (clojure.string/join " and " failures) " not healthy")))))

(put-container-archive "8778328a32b6" "/home/timo/projects/bob/test.tar" "/root")
(defn start-heartbeat
"Starts a periodic heatbeat which performs a health check."
[]
Expand Down
3 changes: 1 addition & 2 deletions src/bob/execution/internals.clj
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@
(reaction-fn line)
(recur r)))))))

; TODO should be start-container?
(defn run
(defn start-container
"Synchronously starts up a previously built container by id.
Takes container-id and run-id which is the id of the build.
Expand Down
4 changes: 2 additions & 2 deletions src/bob/pipeline/internals.clj
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
pipeline)
result (next-step build-state step evars pipeline run-id)
id (update-pid (:id result) run-id)
id (let [result (e/run id run-id)]
id (let [result (e/start-container id run-id)]
(when (f/failed? result)
(log/debugf "Removing failed container %s" id)
(e/delete-container id))
Expand Down Expand Up @@ -198,7 +198,7 @@
_ (mark-image-for-gc image run-id)
id (e/create-container image first-step evars)
id (update-pid id run-id)
id (let [result (e/run id run-id)]
id (let [result (e/start-container id run-id)]
(when (f/failed? result)
(e/delete-container id))
result)
Expand Down
14 changes: 7 additions & 7 deletions test/bob/execution/internals_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@
; #'docker/invoke (constantly (char-array "foobar"))}
; #(is (= (future "foobar") (logs-live "12121212" (fn [log] (str log))))))))

(deftest container-runs
(testing "successful run"
(deftest container-starts
(testing "successful start"
(let [id "11235813213455"]
(with-redefs-fn {#'docker/invoke (fn [_ cid]
(tu/check-and-fail
Expand All @@ -127,9 +127,9 @@
:id)))
{:StatusCode 0})
#'logs-live (constantly true)}
#(is (= "112358132134" (run id "run-id"))))))
#(is (= "112358132134" (start-container id "run-id"))))))

(testing "successful run, non-zero exit"
(testing "successful start, non-zero exit"
(let [id "11235813213455"]
(with-redefs-fn {#'docker/invoke (fn [_ cid]
(tu/check-and-fail
Expand All @@ -138,13 +138,13 @@
:id)))
{:StatusCode 1})
#'logs-live (constantly true)}
#(let [result (run id "run-id")]
#(let [result (start-container id "run-id")]
(is (and (f/failed? result)))))))

(testing "unsuccessful run"
(testing "unsuccessful start"
(with-redefs-fn {#'logs-live (constantly true)
#'docker/invoke (fn [_ _] (throw (Exception. "Failed")))}
#(is (f/failed? (run "id" "run-id"))))))
#(is (f/failed? (start-container "id" "run-id"))))))

(deftest container-deletion
(testing "successful deletion of container"
Expand Down
14 changes: 7 additions & 7 deletions test/bob/pipeline/internals_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
#(and (= "id" id)
(= "id" run-id)))
"id")
#'e/run (fn [id run-id]
#'e/start-container (fn [id run-id]
(tu/check-and-fail
#(and (= "id" id)
(= "id" run-id)))
Expand Down Expand Up @@ -196,7 +196,7 @@
#(and (= "id" id)
(= "id" run-id)))
"id")
#'e/run (fn [id run-id]
#'e/start-container (fn [id run-id]
(tu/check-and-fail
#(and (= "id" id)
(= "id" run-id)))
Expand All @@ -215,7 +215,7 @@
nein (fn [& _] (throw (Exception. "shouldn't be called")))]
(with-redefs-fn {#'next-step nein
#'update-pid nein
#'e/run nein
#'e/start-container nein
#'docker/invoke nein
#'artifact/upload-artifact nein}
#(is (reduced? (exec-step "id" {} "dev:test" 1 (f/fail "shizz") test-step))))))
Expand All @@ -225,7 +225,7 @@
nein (fn [& _] (throw (Exception. "shouldn't be called")))]
(with-redefs-fn {#'next-step (constantly (f/fail "shizz"))
#'update-pid nein
#'e/run nein
#'e/start-container nein
#'docker/invoke nein
#'artifact/upload-artifact nein}
#(is (f/failed? (exec-step "id" {} "dev:test" 1 {:id "id"} test-step)))))))
Expand Down Expand Up @@ -290,7 +290,7 @@
#(and (= "id" id)
(= "run-id" run-id)))
"id")
#'e/run (fn [id run-id]
#'e/start-container (fn [id run-id]
(tu/check-and-fail
#(and (= "id" id)
(= "run-id" run-id)))
Expand Down Expand Up @@ -356,7 +356,7 @@
#(and (= "id" id)
(= "run-id" run-id)))
"id")
#'e/run (fn [id run-id]
#'e/start-container (fn [id run-id]
(tu/check-and-fail
#(and (= "id" id)
(= "run-id" run-id)))
Expand Down Expand Up @@ -404,7 +404,7 @@
#'resourceful-step nein
#'e/create-container nein
#'update-pid nein
#'e/run nein
#'e/start-container nein
#'reduce nein
#'db/update-run nein
#'mark-image-for-gc nein}
Expand Down

0 comments on commit 47fc68a

Please sign in to comment.