From 198efefb0521f89fa82111402a60ec67006cbc56 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Tue, 8 Aug 2017 15:02:44 +1000 Subject: [PATCH] fix(windows): Add retries for flakiness demonstrated on windows builds for pact-go --- .../set_up_provider_state.rb | 18 ++++++++++++- .../set_up_provider_state_retry_spec.rb | 26 +++++++++++++++++++ .../dodgey-provider-state-setup-server.rb | 9 +++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 spec/lib/pact/provider_verifier/set_up_provider_state_retry_spec.rb create mode 100644 spec/support/dodgey-provider-state-setup-server.rb diff --git a/lib/pact/provider_verifier/set_up_provider_state.rb b/lib/pact/provider_verifier/set_up_provider_state.rb index b9abb20..a762f3e 100644 --- a/lib/pact/provider_verifier/set_up_provider_state.rb +++ b/lib/pact/provider_verifier/set_up_provider_state.rb @@ -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 diff --git a/spec/lib/pact/provider_verifier/set_up_provider_state_retry_spec.rb b/spec/lib/pact/provider_verifier/set_up_provider_state_retry_spec.rb new file mode 100644 index 0000000..dc26dc4 --- /dev/null +++ b/spec/lib/pact/provider_verifier/set_up_provider_state_retry_spec.rb @@ -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 diff --git a/spec/support/dodgey-provider-state-setup-server.rb b/spec/support/dodgey-provider-state-setup-server.rb new file mode 100644 index 0000000..e3c7a4c --- /dev/null +++ b/spec/support/dodgey-provider-state-setup-server.rb @@ -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