Skip to content

Commit

Permalink
fix(windows): Add retries for flakiness demonstrated on windows build…
Browse files Browse the repository at this point in the history
…s for pact-go
  • Loading branch information
bethesque committed Aug 8, 2017
1 parent f682b02 commit 198efef
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/pact/provider_verifier/set_up_provider_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,23 @@ def call
attr_reader :provider_state, :consumer

def post_to_provider_state
connection = Faraday.new(:url => provider_states_setup_url)
verbose = verbose?
connection = Faraday.new(:url => provider_states_setup_url) do | faraday |
# Have encountered flakiness on windows build for pact-go
# Using retries as a hacky solution to try and get around this
# until/if we can work out what the underlying cause is.
# https://github.com/pact-foundation/pact-go/issues/42
# eg. https://ci.appveyor.com/project/mefellows/pact-go/build/25#L1202

faraday.request :retry, max: 2, interval: 0.05,
interval_randomness: 0.5, backoff_factor: 2,
methods:[:post],
exceptions: [Faraday::ConnectionFailed]

faraday.response :logger if verbose
faraday.adapter Faraday.default_adapter
end

connection.post do |req|
req.headers["Content-Type"] = "application/json"
add_custom_provider_header req
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'pact/provider_verifier/set_up_provider_state'
require 'json'
require 'webmock/rspec'

module Pact
module ProviderVerifier
describe SetUpProviderState do
let(:provider_states_setup_url) { 'http://localhost:2000' }
let(:provider_state) { 'some state' }
let(:consumer) { 'Foo' }
let(:options) { {} }

subject { SetUpProviderState.call(provider_state, consumer, options) }

before do
ENV['PROVIDER_STATES_SETUP_URL'] = provider_states_setup_url
stub_request(:any, 'http://localhost:2000').to_raise(Errno::ECONNRESET.new).times(2)
.then.to_return(status: 200)
end

it "makes a HTTP request to the configured URL with a JSON body containing the consumer and provider state names" do
subject
end
end
end
end
9 changes: 9 additions & 0 deletions spec/support/dodgey-provider-state-setup-server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'socket'

server = TCPServer.new 2000 # Server bind to port 2000
loop do
client = server.accept # Wait for a client to connect
puts "ACCEPTED connection"
client.puts "HTTP/1.1 200 OK"
client.close
end

0 comments on commit 198efef

Please sign in to comment.