Skip to content

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

Fix flaky metabase-enterprise.dependencies.api-test (#71024)

Ben Grabow0abb871d3f2e
diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj
index 66a4ac380d9..7ea1fa7c411 100644
--- a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj
@@ -3,6 +3,7 @@
[clojure.test :refer :all]
[medley.core :as m]
[metabase-enterprise.dependencies.api :as deps.api]
+ [metabase-enterprise.dependencies.async :as dependencies.async]
[metabase-enterprise.dependencies.core :as dependencies]
[metabase-enterprise.dependencies.events]
[metabase-enterprise.dependencies.findings :as dependencies.findings]
@@ -130,6 +131,19 @@
[card-id]
(dependencies.findings/upsert-analysis! (t2/select-one :model/Card :id card-id)))
+; dependencies.async/submit! effectively awaits all pending tasks on the executor.
+; Those tasks would be executed regardless; this is just changing the timing to be
+; less problematic for multiple test runs in sequence.
+#_{:clj-kondo/ignore [:metabase/validate-deftest]}
+(use-fixtures :each
+ (fn drained-dependency-async-executor-fixture [t]
+ (try
+ (t)
+ (finally
+ ;; Drain the single-threaded async executor to ensure all pending dependency
+ ;; work completes before model cleanup deletes cards, avoiding lock timeouts.
+ @(dependencies.async/submit! (fn [] nil))))))
+
(deftest check-card-test
(testing "POST /api/ee/dependencies/check-card"
(mt/with-premium-features #{:dependencies}
@@ -2687,7 +2701,7 @@
names (mapv #(get-in % [:data :name]) response)]
(is (= ["B Dependent - countsorttest" "A Dependent - countsorttest"] names))))))))))
-(deftest ^:parallel broken-requires-id-and-type-test
+(deftest broken-requires-id-and-type-test
(testing "GET /api/ee/dependencies/graph/broken - requires id and type parameters"
(mt/with-premium-features #{:dependencies}
(testing "missing both id and type returns 400"