From 73e9a8a3b9650bfea0e0f24b1079bbf559e1ec1b Mon Sep 17 00:00:00 2001 From: Ngoc Khuat <qn.khuat@gmail.com> Date: Tue, 27 Aug 2024 19:16:05 +0700 Subject: [PATCH] Fix flaky test update-db-to-never-scan-values-on-demand-test (#47295) --- src/metabase/util/jvm.clj | 7 ++++++- test/metabase/api/database_test.clj | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/metabase/util/jvm.clj b/src/metabase/util/jvm.clj index ceef3af0f67..cdc46ea389e 100644 --- a/src/metabase/util/jvm.clj +++ b/src/metabase/util/jvm.clj @@ -302,7 +302,12 @@ (defn poll "Returns `(thunk)` if the result satisfies the `done?` predicate within the timeout and nil otherwise. - The default timeout is 1000ms and the default interval is 100ms." + The default timeout is 1000ms and the default interval is 100ms. + + (u/poll {:thunk (fn [] (upload!)) + :done (fn [response] (get-in response [:status :done])) + :timeout-ms 1000 + :interval-ms 100})" [{:keys [thunk done? timeout-ms interval-ms] :or {timeout-ms 1000 interval-ms 100}}] (let [start-time (System/currentTimeMillis)] diff --git a/test/metabase/api/database_test.clj b/test/metabase/api/database_test.clj index 1711e721943..44ef0cf7974 100644 --- a/test/metabase/api/database_test.clj +++ b/test/metabase/api/database_test.clj @@ -1268,7 +1268,6 @@ (:metadata_sync_schedule db))) (is (not= (-> schedule-map-for-last-friday-at-11pm u.cron/schedule-map->cron-string) (:cache_field_values_schedule db))))))))) - (deftest update-db-to-never-scan-values-on-demand-test (with-db-scheduler-setup! (with-test-driver-available! @@ -1277,7 +1276,11 @@ (testing "update db setting to never scan should remove scan field values trigger" (testing "sanity check that it has all triggers to begin with" (is (= (task.sync-databases-test/all-db-sync-triggers-name db) - (task.sync-databases-test/query-all-db-sync-triggers-name db)))) + ;; this is flaking and I suspect it's because the triggers is created async in + ;; post-insert hook of Database + (u/poll {:thunk #(task.sync-databases-test/query-all-db-sync-triggers-name db) + :done? not-empty + :timeout-ms 300})))) (mt/user-http-request :crowberto :put 200 (format "/database/%d" (:id db)) {:details {:let-user-control-scheduling true} :schedules {:metadata_sync schedule-map-for-weekly -- GitLab