Skip to content
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

Prioritise gems with higher version for fetching metadata, and stop fetching once we find a valid candidate #4843

Merged
merged 1 commit into from Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/rubygems/resolver/installer_set.rb
Expand Up @@ -77,11 +77,11 @@ def add_always_install(dependency)
newest = found.last

unless @force
found_matching_metadata = found.select do |spec|
found_matching_metadata = found.reverse.find do |spec|
metadata_satisfied?(spec)
end

if found_matching_metadata.empty?
if found_matching_metadata.nil?
if newest
ensure_required_ruby_version_met(newest.spec)
ensure_required_rubygems_version_met(newest.spec)
Expand All @@ -92,7 +92,7 @@ def add_always_install(dependency)
raise exc
end
else
newest = found_matching_metadata.last
newest = found_matching_metadata
end
end

Expand Down
18 changes: 18 additions & 0 deletions test/rubygems/test_gem_resolver_installer_set.rb
Expand Up @@ -64,6 +64,24 @@ def test_add_always_install_prerelease
assert_equal %w[a-1], set.always_install.map {|s| s.full_name }
end

def test_add_always_install_prerelease_github_problem
spec_fetcher do |fetcher|
fetcher.gem 'a', 1
end

# Github has an issue in which it will generate a misleading prerelease output in its RubyGems server API and
# returns a 0 version for the gem while it doesn't exist.
@fetcher.data["#{@gem_repo}prerelease_specs.#{Gem.marshal_version}.gz"] = util_gzip(Marshal.dump([
Gem::NameTuple.new('a', Gem::Version.new(0), 'ruby'),
]))

set = Gem::Resolver::InstallerSet.new :both

set.add_always_install dep('a')

assert_equal %w[a-1], set.always_install.map {|s| s.full_name }
end

def test_add_always_install_prerelease_only
spec_fetcher do |fetcher|
fetcher.gem 'a', '3.a'
Expand Down