mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00

Every time a gem is not found in the Compact Index API, RubyGems will
fallback to the full index, which is very slow. This is unnecessary
because both indexes should be providing the same gems, so if a gem
can't be found in the Compact Index API, it won't be found in the full
index.
We _do_ want a fallback to the full index, whenever the Compact Index
API is not implemented. To detect that, we check that the API responds
to the "/versions" endpoint, just like Bundler does.
Before:
```
$ time gem install fooasdsfafs
ERROR: Could not find a valid gem 'fooasdsfafs' (>= 0) in any repository
gem 20,77s user 0,59s system 96% cpu 22,017 total
```
After:
```
$ time gem install fooasdsfafs
ERROR: Could not find a valid gem 'fooasdsfafs' (>= 0) in any repository
gem 5,02s user 0,09s system 91% cpu 5,568 total
```
c0d6b9eea7
50 lines
1.2 KiB
Ruby
50 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "helper"
|
|
require "rubygems/source"
|
|
|
|
class TestGemSourceSubpathProblem < Gem::TestCase
|
|
def tuple(*args)
|
|
Gem::NameTuple.new(*args)
|
|
end
|
|
|
|
def setup
|
|
super
|
|
|
|
@gem_repo = "http://gems.example.com/private"
|
|
|
|
spec_fetcher
|
|
|
|
@source = Gem::Source.new(@gem_repo)
|
|
|
|
util_make_gems
|
|
end
|
|
|
|
def test_dependency_resolver_set
|
|
response = Gem::Net::HTTPResponse.new "1.1", 200, "OK"
|
|
response.uri = Gem::URI("http://example")
|
|
|
|
@fetcher.data["#{@gem_repo}/versions"] = response
|
|
|
|
set = @source.dependency_resolver_set
|
|
|
|
assert_kind_of Gem::Resolver::APISet, set
|
|
end
|
|
|
|
def test_fetch_spec
|
|
@fetcher.data["#{@gem_repo}/#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}.rz"] = Zlib::Deflate.deflate(Marshal.dump(@a1))
|
|
|
|
spec = @source.fetch_spec tuple("a", Gem::Version.new(1), "ruby")
|
|
assert_equal @a1.full_name, spec.full_name
|
|
end
|
|
|
|
def test_load_specs
|
|
@fetcher.data["#{@gem_repo}/latest_specs.#{Gem.marshal_version}.gz"] = util_gzip(Marshal.dump([
|
|
Gem::NameTuple.new(@a1.name, @a1.version, "ruby"),
|
|
Gem::NameTuple.new(@b2.name, @b2.version, "ruby"),
|
|
]))
|
|
|
|
released = @source.load_specs(:latest).map(&:full_name)
|
|
assert_equal %W[a-1 b-2], released
|
|
end
|
|
end
|