diff --git a/Library/Homebrew/test/cmd/fetch_spec.rb b/Library/Homebrew/test/cmd/fetch_spec.rb index 7b0cc3de7a..c264a66147 100644 --- a/Library/Homebrew/test/cmd/fetch_spec.rb +++ b/Library/Homebrew/test/cmd/fetch_spec.rb @@ -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 diff --git a/Library/Homebrew/test/support/fixtures/tarballs/testball2-0.1-linux.tbz b/Library/Homebrew/test/support/fixtures/tarballs/testball2-0.1-linux.tbz new file mode 100644 index 0000000000..5ca2be071f Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/tarballs/testball2-0.1-linux.tbz differ diff --git a/Library/Homebrew/test/support/fixtures/tarballs/testball2-0.1-patches.tgz b/Library/Homebrew/test/support/fixtures/tarballs/testball2-0.1-patches.tgz new file mode 100644 index 0000000000..4b43f535e8 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/tarballs/testball2-0.1-patches.tgz differ diff --git a/Library/Homebrew/test/support/fixtures/tarballs/testball2-0.1.tbz b/Library/Homebrew/test/support/fixtures/tarballs/testball2-0.1.tbz new file mode 100644 index 0000000000..c7e1af1f4e Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/tarballs/testball2-0.1.tbz differ diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index 1d7edccdea..8c5c1740d2 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -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"