Restart btcdata when its fenced database session closes
pr / test (pull_request) Successful in 1m14s
pr / test (pull_request) Successful in 1m14s
This commit is contained in:
@@ -4,8 +4,18 @@
|
||||
|
||||
(def disabled-stream {:state (atom {:enabled? false}) :latest-price (atom nil)})
|
||||
|
||||
(deftest healthcheck-is-process-only
|
||||
(is (= 200 (:status (health/healthcheck! {})))))
|
||||
(deftest liveness-check-is-local-and-detects-lost-writer
|
||||
(let [closed? (atom false)
|
||||
connection (proxy [java.sql.Connection] []
|
||||
(isClosed [] @closed?))
|
||||
query-fn (with-meta (fn [& _] (throw (Exception. "Must not query database")))
|
||||
{:connection connection})]
|
||||
(is (= 200 (:status (health/healthcheck! query-fn {}))))
|
||||
(reset! closed? true)
|
||||
(is (= 503 (:status (health/healthcheck! query-fn {}))))
|
||||
(is (= "writer session closed"
|
||||
(get-in (health/healthcheck! query-fn {}) [:body :reason]))))
|
||||
(is (= 503 (:status (health/healthcheck! (fn [& _]) {})))))
|
||||
|
||||
(deftest readiness-check-tests-database
|
||||
(let [called (atom nil)
|
||||
|
||||
@@ -13,6 +13,13 @@
|
||||
(is (= :result (query :insert-price {:price 1})))
|
||||
(is (= [connection :insert-price {:price 1}] @seen))))
|
||||
|
||||
(deftest session-liveness-fails-closed
|
||||
(is (false? (writer/session-live? (fn [& _]))))
|
||||
(let [connection (proxy [java.sql.Connection] []
|
||||
(isClosed [] (throw (java.sql.SQLException. "broken"))))]
|
||||
(is (false? (writer/session-live? (with-meta (fn [& _])
|
||||
{:connection connection}))))))
|
||||
|
||||
(deftest server-session-has-bounded-dead-peer-detection
|
||||
(let [connection (Object.)
|
||||
calls (atom [])]
|
||||
@@ -44,7 +51,9 @@
|
||||
(is (thrown-with-msg? clojure.lang.ExceptionInfo #"Another btcdata writer"
|
||||
(ig/init-key :writer/query-fn opts)))
|
||||
;; Closing the owning session cannot transparently reconnect for writes.
|
||||
(is (writer/session-live? first-writer))
|
||||
(.close (:connection (meta first-writer)))
|
||||
(is (false? (writer/session-live? first-writer)))
|
||||
(is (thrown? Exception (first-writer :check {})))
|
||||
(let [replacement (ig/init-key :writer/query-fn opts)]
|
||||
(try
|
||||
|
||||
Reference in New Issue
Block a user