Add test for concurrent fetching

This commit is contained in:
Douglas Eichelberger 2025-02-03 06:40:13 -08:00
parent d74f503158
commit f5d2d30f5b
5 changed files with 26 additions and 2 deletions

View File

@ -14,4 +14,26 @@ RSpec.describe Homebrew::Cmd::FetchCmd do
expect(HOMEBREW_CACHE/"testball--0.1.tbz").to be_a_symlink
expect(HOMEBREW_CACHE/"testball--0.1.tbz").to exist
end
it "concurrently downloads formula URLs", :integration_test do
setup_test_formula "testball1"
setup_test_formula "testball2"
expect { brew "fetch", "testball1", "testball2", "--concurrency=2" }.to be_a_success
expect(HOMEBREW_CACHE/"testball1--0.1.tbz").to be_a_symlink
expect(HOMEBREW_CACHE/"testball1--0.1.tbz").to exist
expect(HOMEBREW_CACHE/"testball2--0.1.tbz").to be_a_symlink
expect(HOMEBREW_CACHE/"testball2--0.1.tbz").to exist
end
it "errors when concurrently downloading to the same destination", :integration_test do
# This test will fail if the fetch is not performed concurrently.
# N.B. this test relies on how we set up test formulae, see the `integration_test` shared context.
setup_test_formula "testball1"
setup_test_formula "testball3"
expect { brew "fetch", "testball1", "testball3", "--concurrency=2" }.to be_a_failure
.and output(/Error:.*process has already locked/).to_stderr
end
end

View File

@ -134,10 +134,12 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
bottle_block: nil, tab_attributes: nil)
case name
when /^testball/
# Use a different tarball for testball2 to avoid lock errors when writing concurrency tests
prefix = (name == "testball2") ? "testball2" : "testball"
tarball = if OS.linux?
TEST_FIXTURE_DIR/"tarballs/testball-0.1-linux.tbz"
TEST_FIXTURE_DIR/"tarballs/#{prefix}-0.1-linux.tbz"
else
TEST_FIXTURE_DIR/"tarballs/testball-0.1.tbz"
TEST_FIXTURE_DIR/"tarballs/#{prefix}-0.1.tbz"
end
content = <<~RUBY
desc "Some test"