Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for sample database having sync scheduled #41752

Merged
merged 5 commits into from
Apr 24, 2024

Conversation

calherries
Copy link
Contributor

@calherries calherries commented Apr 23, 2024

Follow-up to #40066

This PR adds a test for the sample database getting its sync scheduled as if it were a normal database that was added after the initial metabase setup.

Previously this didn't really need test coverage because the sample database was being inserted using t2/insert!, and the sync tasks were scheduled in the after-insert hooks. Now we're inserting the sample database in a migration without using t2/insert!, we should test this specifically. The jobs are being scheduled because we're using t2/update! to update the sample database details outside of the migration, but that seems like a pretty shaky guarantee and could be changed in the future, so this PR adds the test coverage.

@metabase-bot metabase-bot bot added the .Team/BackendComponents also known as BEC label Apr 23, 2024
@calherries calherries requested a review from a team April 23, 2024 19:48
@@ -269,26 +270,6 @@

(def ^:private monthly-schedule {:schedule_type "monthly" :schedule_day "fri" :schedule_frame "last"})

(defn- all-db-sync-triggers-name
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved these functions to metabase.task.sync-databases-test because they were being used in a few places. And since they mostly depend on that namespace it felt natural to put them there.

@calherries calherries added the no-backport Do not backport this PR to any branch label Apr 23, 2024
test/metabase/task/sync_databases_test.clj Outdated Show resolved Hide resolved
test/metabase/task/sync_databases_test.clj Outdated Show resolved Hide resolved
(let [db (t2/instance :model/Database db)]
(assert (some? (#'task/scheduler)) "makes sure the scheduler is initialized!")
(->> (for [task-info @#'task.sync-databases/all-tasks]
(keep #(when (= (.getName ^TriggerKey (#'task.sync-databases/trigger-key db task-info)) (:key %))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can lift the left hand side of the comparison out of the loop into a :let in the for expression. I also think map-filter is more elegant than this keep construction, it'll let you just use a set as the predicate and avoid repeating the key getter.

Comment on lines +61 to +62
flatten
set)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice and clear but I try to avoid flatten given how complex a function it is. If this was application code I would probably use (reduce into #{}) instead.

@crisptrutski
Copy link
Contributor

Like this reorganization and the crisp test 🍏

@calherries
Copy link
Contributor Author

@crisptrutski your comments are on code that I'm moving, not code that I'm changing. All I did was copy+paste from one namespace to another. Following the principle that code refactoring like this is pretty low-value and we don't need to clean up code that we move, I'm going to ignore them for now. I'll accept the grammar suggestions though, because they're no brainers

Grammar fixes

Co-authored-by: Chris Truter <crisptrutski@users.noreply.github.com>
Base automatically changed from sample-db-data-perms to master April 24, 2024 07:58
@calherries calherries merged commit 325b982 into master Apr 24, 2024
106 checks passed
@calherries calherries deleted the sample-database-schedule-sync-test-2 branch April 24, 2024 09:10
Copy link

@calherries Did you forget to add a milestone to the issue for this PR? When and where should I add a milestone?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-backport Do not backport this PR to any branch .Team/BackendComponents also known as BEC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants