aboutsummaryrefslogtreecommitdiffstats
path: root/test/rubygems/test_gem_request_connection_pools.rb
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-14 03:30:02 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-14 03:30:02 +0000
commit4de117a61517e839f2c45eaf45d56fc243d6d5b2 (patch)
tree7cb5af7a7eb513e5dddf5e343746b1611e628387 /test/rubygems/test_gem_request_connection_pools.rb
parente548c09d429a5136285ea81aed418685359ed124 (diff)
downloadruby-4de117a61517e839f2c45eaf45d56fc243d6d5b2.tar.gz
* lib/rubygems: Update to RubyGems 2.4.1 master(713ab65)
Complete history at: https://github.com/rubygems/rubygems/blob/master/History.txt#L3-L216 * test/rubygems: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rubygems/test_gem_request_connection_pools.rb')
-rw-r--r--test/rubygems/test_gem_request_connection_pools.rb120
1 files changed, 120 insertions, 0 deletions
diff --git a/test/rubygems/test_gem_request_connection_pools.rb b/test/rubygems/test_gem_request_connection_pools.rb
new file mode 100644
index 0000000000..1cf6b27979
--- /dev/null
+++ b/test/rubygems/test_gem_request_connection_pools.rb
@@ -0,0 +1,120 @@
+require 'rubygems/test_case'
+require 'rubygems/request'
+require 'timeout'
+
+class TestGemRequestConnectionPool < Gem::TestCase
+ class FakeHttp
+ def initialize *args
+ end
+
+ def start
+ end
+ end
+
+ def setup
+ super
+ @old_client = Gem::Request::ConnectionPools.client
+ Gem::Request::ConnectionPools.client = FakeHttp
+
+ @proxy = URI 'http://proxy.example'
+ end
+
+ def teardown
+ Gem::Request::ConnectionPools.client = @old_client
+ super
+ end
+
+ def test_checkout_same_connection
+ uri = URI.parse('http://example/some_endpoint')
+
+ pools = Gem::Request::ConnectionPools.new nil, []
+ pool = pools.pool_for uri
+ conn = pool.checkout
+ pool.checkin conn
+
+ assert_equal conn, pool.checkout
+ end
+
+ def test_to_proxy_eh
+ pools = Gem::Request::ConnectionPools.new nil, []
+
+ env_no_proxy = %w[
+ 1.no-proxy.example
+ 2.no-proxy.example
+ ]
+
+ no_proxy = pools.send :no_proxy?, '2.no-proxy.example', env_no_proxy
+
+ assert no_proxy, 'match'
+
+ no_proxy = pools.send :no_proxy?, 'proxy.example', env_no_proxy
+
+ refute no_proxy, 'mismatch'
+ end
+
+ def test_to_proxy_eh_wildcard
+ pools = Gem::Request::ConnectionPools.new nil, []
+
+ env_no_proxy = %w[
+ .no-proxy.example
+ ]
+
+ no_proxy = pools.send :no_proxy?, '2.no-proxy.example', env_no_proxy
+
+ assert no_proxy, 'wildcard matching subdomain'
+
+ no_proxy = pools.send :no_proxy?, 'no-proxy.example', env_no_proxy
+
+ assert no_proxy, 'wildcard matching dotless domain'
+
+ no_proxy = pools.send :no_proxy?, 'proxy.example', env_no_proxy
+
+ refute no_proxy, 'wildcard mismatch'
+ end
+
+ def test_net_http_args
+ pools = Gem::Request::ConnectionPools.new nil, []
+
+ net_http_args = pools.send :net_http_args, URI('http://example'), nil
+
+ assert_equal ['example', 80], net_http_args
+ end
+
+ def test_net_http_args_proxy
+ pools = Gem::Request::ConnectionPools.new nil, []
+
+ net_http_args = pools.send :net_http_args, URI('http://example'), @proxy
+
+ assert_equal ['example', 80, 'proxy.example', 80, nil, nil], net_http_args
+ end
+
+ def test_net_http_args_no_proxy
+ orig_no_proxy, ENV['no_proxy'] = ENV['no_proxy'], 'example'
+
+ pools = Gem::Request::ConnectionPools.new nil, []
+
+ net_http_args = pools.send :net_http_args, URI('http://example'), @proxy
+
+ assert_equal ['example', 80, nil, nil], net_http_args
+
+ ensure
+ ENV['no_proxy'] = orig_no_proxy
+ end
+
+ def test_thread_waits_for_connection
+ uri = URI.parse('http://example/some_endpoint')
+ pools = Gem::Request::ConnectionPools.new nil, []
+ pool = pools.pool_for uri
+
+ pool.checkout
+
+ t1 = Thread.new {
+ timeout(1) do
+ pool.checkout
+ end
+ }
+ assert_raises(Timeout::Error) do
+ t1.join
+ end
+ end
+end