Sha256: ecc1e3be8eaa27b4527095f29d7409d1394507aeabc4e4898e1f1079f8080a7d
Contents?: true
Size: 1.84 KB
Versions: 3
Compression:
Stored size: 1.84 KB
Contents
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_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
Version data entries
3 entries across 3 versions & 1 rubygems