add test case for download retry
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user