-
Notifications
You must be signed in to change notification settings - Fork 53
Speed up tests #408
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
Speed up tests #408
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #408 +/- ##
=======================================
Coverage 90.69% 90.69%
=======================================
Files 14 14
Lines 849 849
=======================================
Hits 770 770
Misses 79 79 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, looks good! I've had to go through and make similar changes a handful of times for our own tests. Little stuff like this can make all the difference.
@@ -34,9 +34,9 @@ def ms_id | |||
|
|||
module TestUtil | |||
def self.reset_animals! | |||
Cat.clear_index!(true) | |||
Cat.clear_index! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly did the true
do? Is this just a style cleanup or are there perf implications?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clear_index!
and a lot of other methods in this gem have a single argument that is a synchronous
flag, i. e. whether to await the resulting task. This absolutely has performance implications (although not all that many since awaiting is not really avoidable).
I often write descriptions in git commits, here's the one on the commit of this change:
Unnecessary awaits should be avoided, generally these methods are meant
to be called at the beginning of the test and for best performance we
should wait on tasks right before an assertion.
So the performance implication is being lazy and putting off the await for as long as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also confusion like this is why I really don't like flags, consider this method signature:
def ms_reindex!(batch_size = MeiliSearch::Rails::IndexSettings::DEFAULT_BATCH_SIZE, synchronous = false)
Not only is the first argument just a magic number (in most cases), but the second argument is a flag. And because we do not encourage the use of await
, we have the flag come second so specifying only the flag takes this form:
Color.ms_reindex!(MeiliSearch::Rails::IndexSettings::DEFAULT_BATCH_SIZE, true)
I would argue this does not look great.
In concert with a specific batch size, you get this borderline incomprehensible method call:
Color.ms_reindex!(50, true)
In conclusion, I would really like to change these methods :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, thanks for the writeup. Agreed on the method signature. kwargs
are definitely preferred IMO as well.
Unnecessary awaits should be avoided, generally these methods are meant to be called at the beginning of the test and for best performance we should wait on tasks right before an assertion.
Use insert_all instead of running callbacks, remove unnecessary awaits.
54e8edc
to
9f01362
Compare
WalkthroughTest setup code across several spec and support files was updated to remove the Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test Case
participant Model as Model (e.g. Book, Color)
participant Index as Search Index
Test->>Model: insert_all(records)
Test->>Model: clear_index!()
Model->>Index: Clear index (default settings)
Test->>Model: reindex!() (if needed)
Model->>Index: Reindex matching records
Test->>Model: Run assertions
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 RuboCop (1.73)spec/safe_index_spec.rbError: The spec/support/models/animals.rbError: The spec/model_methods_spec.rbError: The
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (8)
🔇 Additional comments (10)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bors merge
In preparation for adding more tests, which itself is in preparation for some serious refactoring.
Summary by CodeRabbit