Skip to content
Snippets Groups Projects
Commit 43e97e13 authored by Ryan Senior's avatar Ryan Senior
Browse files

Force connection pool reset before running db tz tests [ci drivers]

It's possible that database connections checked back into the pool
could still have session timezones associated with them. This can
cause the database timezone tests to failure. This will reset the
connection pool before the test runs to ensure that doesn't happen.
parent 550b19f4
No related branches found
No related tags found
No related merge requests found
......@@ -5,8 +5,13 @@
[metabase.driver
[generic-sql :as sql]
[oracle :as oracle]]
[metabase.models.setting :as setting]
[metabase.test.data.datasets :refer [expect-with-engine]]
[metabase.models
[database :refer [Database]]
[setting :as setting]]
[metabase.test.data :as data]
[metabase.test.data
[dataset-definitions :as defs]
[datasets :refer [expect-with-engine]]]
[metabase.test.util :as tu])
(:import metabase.driver.oracle.OracleDriver))
......@@ -68,6 +73,4 @@
(expect-with-engine :oracle
"UTC"
(do
(setting/set! :report-timezone "")
(tu/db-timezone-id)))
(tu/db-timezone-id))
......@@ -10,6 +10,7 @@
[driver :as driver]
[task :as task]
[util :as u]]
[metabase.driver.generic-sql :as sql]
[metabase.models
[card :refer [Card]]
[collection :refer [Collection]]
......@@ -436,16 +437,27 @@
{:cron-schedule (.getCronExpression ^CronTrigger trigger)
:data (into {} (.getJobDataMap trigger))}))))}))))))
(defn- clear-connection-pool
"It's possible that a previous test ran and set the session's timezone to something, then returned the session to
the pool. Sometimes that connection's session can remain intact and subsequent queries will continue in that
timezone. That causes problems for tests that we can determine the database's timezone. This function will reset the
connections in the connection pool for `db` to ensure that we get fresh session with no timezone specified"
[db]
(when-let [conn-pool (:datasource (sql/db->pooled-connection-spec db))]
(.softResetAllUsers conn-pool)))
(defn db-timezone-id
"Return the timezone id from the test database. Must be called with `metabase.test.data.datasets/*driver*` bound,
such as via `metabase.test.data.datasets/with-engine`"
[]
(assert (bound? #'*driver*))
(data/dataset test-data
(-> (driver/current-db-time *driver* (data/db))
.getChronology
.getZone
.getID)))
(let [db (data/db)]
(clear-connection-pool db)
(data/dataset test-data
(-> (driver/current-db-time *driver* db)
.getChronology
.getZone
.getID))))
(defn call-with-jvm-tz
"Invokes the thunk `F` with the JVM timezone set to `DTZ`, puts the various timezone settings back the way it found
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment