Skip to content

Commit

Permalink
Fix tests on the main branch (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
slvrtrn authored May 28, 2024
1 parent 08500c1 commit 6375feb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
13 changes: 7 additions & 6 deletions src/metabase/driver/clickhouse.clj
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,26 @@
(fn [^java.sql.Connection conn]
(with-open [stmt (.prepareStatement conn "SELECT value='1' FROM system.settings WHERE name='cloud_mode'")
rset (.executeQuery stmt)]
(when (.next rset)
(.getBoolean rset 1))))))
(if (.next rset)
(.getBoolean rset 1)
false)))))
;; cache the results for 48 hours; TTL is here only to eventually clear out old entries
:ttl/threshold (* 48 60 60 1000)))

(defmethod sql-jdbc.conn/connection-details->spec :clickhouse
[_ details]
(cond-> (connection-details->spec* details)
(try (cloud? details)
(catch java.sql.SQLException _e
false))
(catch java.sql.SQLException _e
false))
;; select_sequential_consistency guarantees that we can query data from any replica in CH Cloud
;; immediately after it is written
(assoc :select_sequential_consistency true)))

(defmethod driver/database-supports? [:clickhouse :uploads] [_driver _feature db]
(try (cloud? (:details db))
(catch java.sql.SQLException _e
false)))
(catch java.sql.SQLException _e
false)))

(defmethod driver/can-connect? :clickhouse
[driver details]
Expand Down
22 changes: 13 additions & 9 deletions test/metabase/driver/clickhouse_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,19 @@
{}))))))

(deftest clickhouse-connection-fails-test
(mt/test-driver :clickhouse
(mt/with-temp [:model/Database db {:details (assoc (mt/db) :password "wrongpassword") :engine :clickhouse}]
(testing "Sense check that checking the cloud mode fails with a SQLException."
(is (thrown? java.sql.SQLException (#'clickhouse/cloud? (:details db)))))
(testing "`driver/database-supports?` succeeds even if the connection fails."
(is (false? (driver/database-supports? :clickhouse :uploads db))))
(testing (str "`sql-jdbc.conn/connection-details->spec` succeeds even if the connection fails, "
"and doesn't include the `select_sequential_consistency` parameter.")
(is (nil? (:select_sequential_consistency (sql-jdbc.conn/connection-details->spec :clickhouse (:details db)))))))))
(mt/test-driver
:clickhouse
(let [details (merge (tx/dbdef->connection-details
:clickhouse :db
{:database-name "mb_test_connection_fails"})
{:password "wrong"})]
(testing "sense check that checking the cloud mode fails with a SQLException."
(is (thrown? java.sql.SQLException (#'clickhouse/cloud? details))))
(testing "`driver/database-supports?` succeeds even if the connection fails."
(is (false? (driver/database-supports? :clickhouse :uploads details))))
(testing (str "`sql-jdbc.conn/connection-details->spec` succeeds even if the connection fails, "
"and doesn't include the `select_sequential_consistency` parameter.")
(is (nil? (:select_sequential_consistency (sql-jdbc.conn/connection-details->spec :clickhouse details))))))))

(deftest ^:parallel clickhouse-tls
(mt/test-driver
Expand Down

0 comments on commit 6375feb

Please sign in to comment.