Reset default download queue between specs - #23424
Open
MikeMcQuaid wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a test-suite flake caused by Homebrew.default_download_queue memoising a queue object across examples: if a spec stubs DownloadQueue.new on first use, the memoised value can remain an RSpec double and later trigger RSpec::Mocks::OutsideOfExampleError via the at_exit shutdown hook.
Changes:
- Add
Homebrew.reset_default_download_queueto clear the memoised default queue between examples. - Reset the memoised default download queue in
spec_helper.rbafter each example. - Add an ordered regression spec to ensure a stubbed queue from one example does not leak into the next.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Library/Homebrew/test/spec_helper.rb | Resets the memoised default download queue after each example to prevent RSpec double leakage. |
| Library/Homebrew/test/download_queue_spec.rb | Adds an ordered regression spec covering the memoisation leak across examples. |
| Library/Homebrew/download_queue.rb | Introduces a reset helper for the memoised default download queue. |
馃挕 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- `Homebrew.default_download_queue` memoizes its queue on the `Homebrew` module, so an example stubbing `Homebrew::DownloadQueue.new` at first use leaked an RSpec double into later examples and the `at_exit` shutdown hook, randomly crashing test runs with `RSpec::Mocks::OutsideOfExampleError` after every example passed. - Shut down and drop the memoized queue after every example instead. A leaked double is only dropped as it cannot receive `shutdown` outside the per-example rspec-mocks lifecycle. - Add ordered regression specs covering the leak and the reset.
MikeMcQuaid
force-pushed
the
fix-rspec-mocks-lifecycle
branch
from
August 4, 2026 11:10
c9bd5b5 to
2f8502f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Homebrew.default_download_queuememoizes its queue on theHomebrewmodule, so an example stubbingHomebrew::DownloadQueue.newat first use leaked an RSpec double into later examples and theat_exitshutdown hook, randomly crashing test runs withRSpec::Mocks::OutsideOfExampleErrorafter every example passed.shutdownin thearoundhook'sensurewould itself run outside the rspec-mocks lifecycle.brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?Claude Fable 5 Max with local review and testing.