diff options
author | Terence Lee <hone02@gmail.com> | 2012-09-18 08:35:05 +0300 |
---|---|---|
committer | Terence Lee <hone02@gmail.com> | 2012-09-18 08:35:05 +0300 |
commit | 31ec2665f41218f38291b31767f1f3f2b0977eb4 (patch) | |
tree | 667dde8b5143bbbfadcee2af5d848b41280e5dd5 | |
parent | cfa76075474c44e6c8b4580c16096ee535b30fa9 (diff) | |
download | bundler-31ec2665f41218f38291b31767f1f3f2b0977eb4.tar.gz |
use Net::HTTP's read_timeout setting instead
talked with @drbrain about net/http timeouts, and we decided it was
better than having to do a manual Timeout.
-rw-r--r-- | lib/bundler/fetcher.rb | 3 | ||||
-rw-r--r-- | spec/install/gems/dependency_api_spec.rb | 45 | ||||
-rw-r--r-- | spec/support/rubygems_ext.rb | 3 |
3 files changed, 41 insertions, 10 deletions
diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb index 6f9cce8fb1..120624b9df 100644 --- a/lib/bundler/fetcher.rb +++ b/lib/bundler/fetcher.rb @@ -46,6 +46,7 @@ module Bundler @remote_uri = remote_uri @has_api = true # will be set to false if the rubygems index is ever fetched @@connection ||= Net::HTTP::Persistent.new nil, :ENV + @@connection.read_timeout = 1 end # fetch a gem specification @@ -145,7 +146,7 @@ module Bundler begin Bundler.ui.debug "Fetching from: #{uri}" response = nil - Timeout.timeout(API_TIMEOUT) { response = @@connection.request(uri) } + response = @@connection.request(uri) rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, SocketError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::HTTP::Persistent::Error, Net::ProtocolError => e diff --git a/spec/install/gems/dependency_api_spec.rb b/spec/install/gems/dependency_api_spec.rb index 867674abf5..9e99c517d7 100644 --- a/spec/install/gems/dependency_api_spec.rb +++ b/spec/install/gems/dependency_api_spec.rb @@ -158,15 +158,44 @@ describe "gemcutter's dependency API" do out.should match(/Too many redirects/) end - it "timeouts when Gemcutter API takes too long to respond" do - gemfile <<-G - source "#{source_uri}" - gem "rack" - G + context "when Gemcutter API takes too long to respond" do + let(:port) { 2000 } + let(:server_uri) { "http://localhost:2000" } - bundle :install, :artifice => "endpoint_timeout" - out.should include("\nFetching full source index from #{source_uri}") - should_be_installed "rack 1.0.0" + before do + # need to hack, so we can require rack + old_gem_home = ENV['GEM_HOME'] + ENV['GEM_HOME'] = Spec::Path.base_system_gems.to_s + require 'rack' + ENV['GEM_HOME'] = old_gem_home + + require File.join(File.dirname(__FILE__), '../../support/artifice/endpoint_timeout') + require 'thread' + t = Thread.new { + server = Rack::Server.start(:app => EndpointTimeout, + :Host => '0.0.0.0', + :Port => port, + :server => 'webrick', + :AccessLog => []) + server.start + } + t.run + + # ensure server is started + require 'timeout' + Timeout.timeout(10) { sleep(0.1) until t.status == "sleep" } + end + + it "timeouts" do + gemfile <<-G + source "#{server_uri}" + gem "rack" + G + + bundle :install + out.should include("\nFetching full source index from #{server_uri}") + should_be_installed "rack 1.0.0" + end end context "when --full-index is specified" do diff --git a/spec/support/rubygems_ext.rb b/spec/support/rubygems_ext.rb index e06fa9bafc..cce0bf77a9 100644 --- a/spec/support/rubygems_ext.rb +++ b/spec/support/rubygems_ext.rb @@ -11,13 +11,14 @@ module Spec unless File.exist?("#{Path.base_system_gems}") FileUtils.mkdir_p(Path.base_system_gems) - puts "fetching fakeweb, artifice, sinatra, rake, and builder for the tests to use..." + puts "fetching fakeweb, artifice, sinatra, rake, rack, and builder for the tests to use..." `gem install fakeweb artifice --no-rdoc --no-ri` `gem install sinatra --version 1.2.7 --no-rdoc --no-ri` # Rake version has to be consistent for tests to pass `gem install rake --version 0.8.7 --no-rdoc --no-ri` # 3.0.0 breaks 1.9.2 specs `gem install builder --version 2.1.2 --no-rdoc --no-ri` + `gem install rack --no-rdoc --no-ri` end ENV['HOME'] = Path.home.to_s |