Bound PostgreSQL dead-peer detection for writer fencing
build / build (push) Failing after 1m43s

This commit is contained in:
2026-10-07 14:05:22 +02:00
parent 952b179d9a
commit 756ab7c65b
3 changed files with 60 additions and 0 deletions
+19
View File
@@ -13,6 +13,18 @@
(is (= :result (query :insert-price {:price 1})))
(is (= [connection :insert-price {:price 1}] @seen))))
(deftest server-session-has-bounded-dead-peer-detection
(let [connection (Object.)
calls (atom [])]
(with-redefs [jdbc/execute-one! (fn [conn sql] (swap! calls conj [conn sql]))]
(writer/configure-session! connection))
(is (= (mapv #(vector connection [%])
["SET tcp_keepalives_idle = 60"
"SET tcp_keepalives_interval = 10"
"SET tcp_keepalives_count = 3"
"SET tcp_user_timeout = 90000"])
@calls))))
(deftest postgres-session-fencing
;; Optional disposable PostgreSQL integration test; never use production here.
(if-let [url (System/getenv "BTCDATA_TEST_JDBC_URL")]
@@ -22,6 +34,13 @@
first-writer (ig/init-key :writer/query-fn opts)]
(try
(is (= 1 (:healthy (first-writer :check {}))))
(let [connection (:connection (meta first-writer))]
(doseq [[setting expected] [["tcp_keepalives_idle" "60"]
["tcp_keepalives_interval" "10"]
["tcp_keepalives_count" "3"]
["tcp_user_timeout" "90000"]]]
(is (= expected (:value (jdbc/execute-one! connection
["select current_setting(?) as value" setting]))))))
(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.