Skip to content

test/bundle/formula_installer_spec: avoid slow brew link#21203

Merged
MikeMcQuaid merged 1 commit intomainfrom
test-bundle-avoid-link
Dec 10, 2025
Merged

test/bundle/formula_installer_spec: avoid slow brew link#21203
MikeMcQuaid merged 1 commit intomainfrom
test-bundle-avoid-link

Conversation

@cho-m
Copy link
Copy Markdown
Member

@cho-m cho-m commented Dec 9, 2025

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

We probably should look into improving performance here as brew bundle can now directly interact with Homebrew::Cmd::Link. So it should no longer need to create another brew instance, which requires subshell and then another Ruby adding a noticeable overhead.


However, in the mean time, we can avoid running this code for testcases that aren't verifying link behavior providing a significant speed up on one of slowest test files:

Before:

Top 3 slowest examples (15.17 seconds, 26.6% of total time):
  Homebrew::Bundle::FormulaInstaller when the formula is installed when the postinstall option is provided when formula has changed reports a failure
    5.13 seconds ./test/bundle/formula_installer_spec.rb:246
  Homebrew::Bundle::FormulaInstaller when the formula is installed with an always restart_service option with a skipped installation restart service
    5.02 seconds ./test/bundle/formula_installer_spec.rb:93
  Homebrew::Bundle::FormulaInstaller when the formula is installed when the postinstall option is provided when formula has changed runs the postinstall command
    5.02 seconds ./test/bundle/formula_installer_spec.rb:240

Took 58 seconds

After:

Top 3 slowest examples (1.3 seconds, 8.2% of total time):
  Homebrew::Bundle::FormulaInstaller.outdated_formulae calls Homebrew
    0.49262 seconds ./test/bundle/formula_installer_spec.rb:317
  Homebrew::Bundle::FormulaInstaller#restart_service_needed? is false by default
    0.46559 seconds ./test/bundle/formula_installer_spec.rb:559
  Homebrew::Bundle::FormulaInstaller#start_service_needed? when a service is already started is false with {restart_service: :always}
    0.34286 seconds ./test/bundle/formula_installer_spec.rb:502

Took 16 seconds

Copilot AI review requested due to automatic review settings December 9, 2025 21:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves test performance by avoiding slow brew link subprocess calls in tests that don't verify linking behavior. The changes mock Homebrew::Bundle.brew("link", ...) in three test contexts that focus on service management and postinstall behavior, reducing the test file execution time from 58 seconds to 16 seconds.

  • Adds mocking to avoid subprocess overhead in non-link-related tests
  • Achieves ~72% reduction in test execution time (58s → 16s)
  • Follows established testing patterns by using allow stubs for non-verified behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Great work!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Dec 10, 2025
Merged via the queue into main with commit 4708b2f Dec 10, 2025
43 checks passed
@MikeMcQuaid MikeMcQuaid deleted the test-bundle-avoid-link branch December 10, 2025 10:11
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.

3 participants