Sha256: 0a8a0c246c28891cfa9a71ada815873c4f37b1f456c0389807fd0b21df9bd033
Contents?: true
Size: 1.67 KB
Versions: 5
Compression:
Stored size: 1.67 KB
Contents
require File.expand_path("../../helper", __FILE__) module Middleware class RetryTest < Faraday::TestCase def setup @times_called = 0 end def conn(*retry_args) Faraday.new do |b| b.request :retry, *retry_args b.adapter :test do |stub| stub.post('/unstable') { @times_called += 1 @explode.call @times_called } end end end def test_unhandled_error @explode = lambda {|n| raise "boom!" } assert_raises(RuntimeError) { conn.post("/unstable") } assert_equal 1, @times_called end def test_handled_error @explode = lambda {|n| raise Errno::ETIMEDOUT } assert_raises(Errno::ETIMEDOUT) { conn.post("/unstable") } assert_equal 3, @times_called end def test_legacy_max_retries @explode = lambda {|n| raise Errno::ETIMEDOUT } assert_raises(Errno::ETIMEDOUT) { conn(1).post("/unstable") } assert_equal 2, @times_called end def test_new_max_retries @explode = lambda {|n| raise Errno::ETIMEDOUT } assert_raises(Errno::ETIMEDOUT) { conn(:max => 3).post("/unstable") } assert_equal 4, @times_called end def test_interval @explode = lambda {|n| raise Errno::ETIMEDOUT } started = Time.now assert_raises(Errno::ETIMEDOUT) { conn(:max => 2, :interval => 0.1).post("/unstable") } assert_in_delta 0.2, Time.now - started, 0.03 end def test_custom_exceptions @explode = lambda {|n| raise "boom!" } assert_raises(RuntimeError) { conn(:exceptions => StandardError).post("/unstable") } assert_equal 3, @times_called end end end
Version data entries
5 entries across 5 versions & 1 rubygems