1
Shindo.tests('Excon request idempotencey') do
4
@connection = Excon.new('http://127.0.0.1:9292', :mock => true)
8
# flush any existing stubs after each test
12
tests("Non-idempotent call with an erroring socket").raises(Excon::Errors::SocketError) do
14
Excon.stub({:method => :get}) { |params|
16
if run_count <= 3 # First 3 calls fail.
17
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
19
{:body => params[:body], :headers => params[:headers], :status => 200}
23
@connection.request(:method => :get, :path => '/some-path')
26
tests("Idempotent request with socket erroring first 3 times").returns(200) do
28
Excon.stub({:method => :get}) { |params|
30
if run_count <= 3 # First 3 calls fail.
31
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
33
{:body => params[:body], :headers => params[:headers], :status => 200}
37
response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path')
41
tests("Idempotent request with socket erroring first 5 times").raises(Excon::Errors::SocketError) do
43
Excon.stub({:method => :get}) { |params|
45
if run_count <= 5 # First 5 calls fail.
46
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
48
{:body => params[:body], :headers => params[:headers], :status => 200}
52
response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path')
56
tests("Lowered retry limit with socket erroring first time").returns(200) do
58
Excon.stub({:method => :get}) { |params|
60
if run_count <= 1 # First call fails.
61
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
63
{:body => params[:body], :headers => params[:headers], :status => 200}
67
response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 2)
71
tests("Lowered retry limit with socket erroring first 3 times").raises(Excon::Errors::SocketError) do
73
Excon.stub({:method => :get}) { |params|
75
if run_count <= 3 # First 3 calls fail.
76
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
78
{:body => params[:body], :headers => params[:headers], :status => 200}
82
response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 2)
86
tests("Raised retry limit with socket erroring first 5 times").returns(200) do
88
Excon.stub({:method => :get}) { |params|
90
if run_count <= 5 # First 5 calls fail.
91
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
93
{:body => params[:body], :headers => params[:headers], :status => 200}
97
response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 8)
101
tests("Raised retry limit with socket erroring first 9 times").raises(Excon::Errors::SocketError) do
103
Excon.stub({:method => :get}) { |params|
105
if run_count <= 9 # First 9 calls fail.
106
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
108
{:body => params[:body], :headers => params[:headers], :status => 200}
112
response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 8)
116
tests("Retry limit in constructor with socket erroring first 5 times").returns(200) do
118
Excon.stub({:method => :get}) { |params|
120
if run_count <= 5 # First 5 calls fail.
121
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
123
{:body => params[:body], :headers => params[:headers], :status => 200}
127
response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 6)