diff --git a/app/logical/downloads/file.rb b/app/logical/downloads/file.rb index b6e1b71f6..6205c0488 100644 --- a/app/logical/downloads/file.rb +++ b/app/logical/downloads/file.rb @@ -2,6 +2,7 @@ module Downloads class File class Error < Exception ; end + attr_reader :tries attr_accessor :source, :content_type, :file_path def initialize(source, file_path) @@ -77,7 +78,6 @@ module Downloads end # http.request_get end # http.start rescue Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::EIO, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, IOError => x - puts x.inspect @tries += 1 if @tries < 3 retry diff --git a/test/unit/downloads/file_test.rb b/test/unit/downloads/file_test.rb index 740f1ee92..689012d82 100644 --- a/test/unit/downloads/file_test.rb +++ b/test/unit/downloads/file_test.rb @@ -13,6 +13,19 @@ module Downloads @tempfile.close end + context "that fails" do + setup do + Net::HTTP.stubs(:start).raises(Errno::ETIMEDOUT) + end + + should "retry three times" do + assert_raises(Errno::ETIMEDOUT) do + @download.http_get_streaming {} + end + assert_equal(3, @download.tries) + end + end + should "stream a file from an HTTP source" do @download.http_get_streaming do |resp| assert_equal("200", resp.code)