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

RFC: kondo lint to enforce naming convention for thread not safe defn/defmacro in tests #37126

Merged
merged 8 commits into from Jan 22, 2024

Conversation

qnkhuat
Copy link
Contributor

@qnkhuat qnkhuat commented Dec 27, 2023

This adds a lint to force defn / defmacro to have a name that ends with ! if it contains not thread safe calls like mt/with-temp!.

Screenshot 2023-12-27 at 16 43 37

This is the first step to pursue this RFC from Cam. The goal here is to make identifying "parallelable" tests easier. To achieve that, we should adopt a convention name for any function / macro that cannot be used in parallel tests to have the name end with !.

Once we have this, it'll be easy to write a kondo to suggest whether or not a deftest can be paralleled.

This lint will only be used in test namespaces.

One more thing, the reason I enforce this lint on defn is because most of the time, we write macros in this pattern

(defn do-magic-happens-here
  [thunk]
  (thunk))

(defmacro magic-happens-here
  [& body]
  `(do-magic-happens-here (fn [] ~@body)))

so, to make sure we cover all macros, we should make all functions recognizable as safe / not safe.

@metabase-bot metabase-bot bot added the .Team/BackendComponents also known as BEC label Dec 27, 2023
@qnkhuat qnkhuat requested a review from a team December 27, 2023 09:51
Copy link

cypress bot commented Dec 27, 2023

1 failed test on run #1097 ↗︎

1 2197 155 0 Flakiness 0
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.

Details:

RFC: kondo lint to enforce naming convention for thread not safe defn/defmacro i...
Project: Metabase e2e Commit: e3e7a71baf
Status: Failed Duration: 15:05 💡
Started: Dec 27, 2023 10:56 AM Ended: Dec 27, 2023 11:11 AM

Review all test suite changes for PR #37126 ↗︎

@@ -595,11 +595,11 @@
metabase.related-test/with-world macros.metabase.related-test/with-world
metabase.shared.util.namespaces/import-fn macros.metabase.shared.util.namespaces/import-fn
metabase.test.data.users/with-group-for-user macros.metabase.test.data.users/with-group-for-user
metabase.test.util/with-temp-env-var-value macros.metabase.test.util/with-temp-env-var-value
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 changed this one macro as an example

Copy link
Member

@camsaul camsaul left a comment

Choose a reason for hiding this comment

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

Big fan of this.

The main thing that stopped me from going any further with my previous PR was just that so many things needed to be fixed -- maybe we can have the linter ignore some of the test helpers that we know are missing ! for the time being, and we can fix them in follow-on PRs.

We should also make sure this respects #_:clj-kondo/ignore forms, because there are some legitimate cases where you might want to use with-redefs in something without marking it as !, for example functions that respect test-helpers-set-global-values!. Normally they would be thread-safe, but then they'd have a thread-unsafe behavior if used inside test-helpers-set-global-values!. That's ok tho because test-helpers-set-global-values! itself ends in a !

Copy link

replay-io bot commented Jan 22, 2024

StatusIn Progress ↗︎ 51 / 52
Commitda588d5
Results
2226 Passed

@qnkhuat
Copy link
Contributor Author

qnkhuat commented Jan 22, 2024

@camsaul yes, it does work if with :clj-kondo/ignore

@qnkhuat qnkhuat added the no-backport Do not backport this PR to any branch label Jan 22, 2024
@qnkhuat qnkhuat enabled auto-merge (squash) January 22, 2024 08:09
@qnkhuat qnkhuat merged commit 9723e46 into master Jan 22, 2024
109 of 110 checks passed
@qnkhuat qnkhuat deleted the ngoc-kondo-lint-enforce-exclamation branch January 22, 2024 08:40
Copy link

@qnkhuat 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