add test case for download retry

This commit is contained in:
albert
2013-03-22 19:15:12 -04:00
parent a4b67fa072
commit d1127da13f
2 changed files with 14 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ module Downloads
class File class File
class Error < Exception ; end class Error < Exception ; end
attr_reader :tries
attr_accessor :source, :content_type, :file_path attr_accessor :source, :content_type, :file_path
def initialize(source, file_path) def initialize(source, file_path)
@@ -77,7 +78,6 @@ module Downloads
end # http.request_get end # http.request_get
end # http.start end # http.start
rescue Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::EIO, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, IOError => x rescue Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::EIO, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, IOError => x
puts x.inspect
@tries += 1 @tries += 1
if @tries < 3 if @tries < 3
retry retry

View File

@@ -13,6 +13,19 @@ module Downloads
@tempfile.close @tempfile.close
end 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 should "stream a file from an HTTP source" do
@download.http_get_streaming do |resp| @download.http_get_streaming do |resp|
assert_equal("200", resp.code) assert_equal("200", resp.code)