Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

wait up to 10 seconds for worker to stop (#62288)

dpsutton85ed69c790af
diff --git a/src/metabase/util/queue.clj b/src/metabase/util/queue.clj
index acf26a694d5..8f09a69b020 100644
--- a/src/metabase/util/queue.clj
+++ b/src/metabase/util/queue.clj
@@ -19,7 +19,15 @@
[metabase.util.malli.schema :as ms])
(:import
(java.time Duration Instant)
- (java.util.concurrent ArrayBlockingQueue BlockingQueue DelayQueue Delayed ScheduledExecutorService SynchronousQueue TimeUnit)))
+ (java.util.concurrent
+ ArrayBlockingQueue
+ BlockingQueue
+ DelayQueue
+ Delayed
+ ExecutorService
+ ScheduledExecutorService
+ SynchronousQueue
+ TimeUnit)))
(set! *warn-on-reflection* true)
@@ -193,10 +201,12 @@
"Stops the listener previously started with (listen!).
If there is no running listener with the given name, it is a no-op"
[listener-name :- :string]
- (if-let [executor (get @listeners listener-name)]
+ (if-let [^ExecutorService executor (get @listeners listener-name)]
(do
(log/infof "Stopping listener %s..." listener-name)
(cp/shutdown! executor)
+ ;; wait up to 10 seconds for executor to stop. Largely for CI/tests FAIL in (listener-handler-test) (queue_test.clj:178)
+ (.awaitTermination executor 10 TimeUnit/SECONDS)
(swap! listeners dissoc listener-name)
(log/infof "Stopping listener %s...done" listener-name))
diff --git a/test/metabase/channel/email_test.clj b/test/metabase/channel/email_test.clj
index 3430431b495..ecc8d8f670e 100644
--- a/test/metabase/channel/email_test.clj
+++ b/test/metabase/channel/email_test.clj
@@ -139,6 +139,11 @@
emails (get @inbox address)]
(boolean (some #(re-find regex %) (map :subject emails)))))
+(defn email-subjects
+ [user-or-email]
+ (let [address (if (string? user-or-email) user-or-email (:username (test.users/user->credentials user-or-email)))]
+ (into #{} (map :subject) (get @inbox address))))
+
(defn received-email-body?
"Indicate whether a user received an email whose body matches the `regex`. First argument should be a keyword
like :rasta, or an email address string."
diff --git a/test/metabase/session/models/session_test.clj b/test/metabase/session/models/session_test.clj
index bbadfa01faf..c735c296f5f 100644
--- a/test/metabase/session/models/session_test.clj
+++ b/test/metabase/session/models/session_test.clj
@@ -123,7 +123,7 @@
(deftest login-email-fall-back-name-test
(mt/test-helpers-set-global-values!
(let [original-maybe-send (var-get #'metabase.login-history.record/maybe-send-login-from-new-device-email)
- new-login-email (fn [user-id]
+ new-login-email (fn [user-id email]
(mt/with-fake-inbox
(with-redefs [request/geocode-ip-addresses (fn [ip-addresses]
(into {} (for [ip-address ip-addresses]
@@ -146,25 +146,24 @@
:device_id device
:timestamp #t "2021-04-02T15:52:00-07:00[US/Pacific]"
:device_description "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML like Gecko) Chrome/89.0.4389.86 Safari/537.36"})
- (ffirst (vals @mt/inbox)))))))]
+ (mt/email-subjects email))))))]
(testing "Use first name if exists"
- (mt/with-temp [:model/User {user-id :id} {:first_name "Ngoc"
- :last_name "Khuat"}]
- (is (= "We've Noticed a New Metabase Login, Ngoc"
- (:subject (new-login-email user-id))))))
+ (mt/with-temp [:model/User {user-id :id
+ email :email} {:first_name "Ngoc"
+ :last_name "Khuat"}]
+ (is (contains? (new-login-email user-id email) "We've Noticed a New Metabase Login, Ngoc"))))
(testing "fallback to last name if user has no first_name"
- (mt/with-temp [:model/User {user-id :id} {:first_name nil
- :last_name "Khuat"}]
- (is (= "We've Noticed a New Metabase Login, Khuat"
- (:subject (new-login-email user-id))))))
+ (mt/with-temp [:model/User {user-id :id email :email} {:first_name nil :last_name "Khuat"}]
+ (is (contains? (new-login-email user-id email)
+ "We've Noticed a New Metabase Login, Khuat"))))
(testing "Else Use email if both first_name and last_name are null"
- (mt/with-temp [:model/User {user-id :id} {:first_name nil
- :last_name nil
- :email "[email protected]"}]
- (is (= "We've Noticed a New Metabase Login, [email protected]"
- (:subject (new-login-email user-id)))))))))
+ (mt/with-temp [:model/User {user-id :id email :email} {:first_name nil
+ :last_name nil
+ :email "[email protected]"}]
+ (is (contains? (new-login-email user-id email)
+ "We've Noticed a New Metabase Login, [email protected]")))))))
(deftest create-session-test
(mt/with-temp [:model/User {user-id :id}]
diff --git a/test/metabase/test.clj b/test/metabase/test.clj
index 451238eb31f..2192bb04d03 100644
--- a/test/metabase/test.clj
+++ b/test/metabase/test.clj
@@ -147,6 +147,7 @@
received-email-body?
received-email-subject?
regex-email-bodies
+ email-subjects
reset-inbox!
summarize-multipart-email
summarize-multipart-single-email