Skip to content

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Speed up tests #408

wants to merge 2 commits into from

Conversation

ellnix
Copy link
Collaborator

@ellnix ellnix commented Mar 16, 2025

In preparation for adding more tests, which itself is in preparation for some serious refactoring.

ellnix added 2 commits March 16, 2025 23:10
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.
Copy link

codecov bot commented Mar 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.54%. Comparing base (5450df2) to head (54e8edc).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #408   +/-   ##
=======================================
  Coverage   89.54%   89.54%           
=======================================
  Files          13       13           
  Lines         775      775           
=======================================
  Hits          694      694           
  Misses         81       81           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@wesharper wesharper left a 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!

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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 :)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants