From cc1ba5f9751967aa2ccc2b6273905d4199e8d619 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Sun, 5 Apr 2020 09:21:21 +1000 Subject: [PATCH] feat(can i deploy): put out a message while waiting for verification results to be published --- lib/pact_broker/client/can_i_deploy.rb | 5 +++++ spec/lib/pact_broker/client/can_i_deploy_spec.rb | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/pact_broker/client/can_i_deploy.rb b/lib/pact_broker/client/can_i_deploy.rb index 1d8c3257..a2f23c27 100644 --- a/lib/pact_broker/client/can_i_deploy.rb +++ b/lib/pact_broker/client/can_i_deploy.rb @@ -87,6 +87,7 @@ def fetch_matrix_with_retries if retry_while_unknown? check_if_retry_while_unknown_supported(matrix) if matrix.any_unknown? + $stderr.puts "Waiting for verification results to be published (up to #{wait_time} seconds)" matrix = Retry.until_truthy_or_max_times(retry_options) do fetch_matrix end @@ -120,6 +121,10 @@ def retry_tries options[:retry_while_unknown] end + def wait_time + retry_interval * retry_tries + end + def check_if_retry_while_unknown_supported(matrix) if !matrix.supports_unknown_count? raise PactBroker::Client::Error.new("This version of the Pact Broker does not provide a count of the unknown verification results. Please upgrade your Broker to >= v2.23.4") diff --git a/spec/lib/pact_broker/client/can_i_deploy_spec.rb b/spec/lib/pact_broker/client/can_i_deploy_spec.rb index ba657719..d397ea07 100644 --- a/spec/lib/pact_broker/client/can_i_deploy_spec.rb +++ b/spec/lib/pact_broker/client/can_i_deploy_spec.rb @@ -76,8 +76,18 @@ module Client end context "when any_unknown? is true" do + before do + allow($stderr).to receive(:puts) + allow(Retry).to receive(:until_truthy_or_max_times) + end + let(:any_unknown) { true } + it "puts a message to stderr" do + expect($stderr).to receive(:puts).with("Waiting for verification results to be published (up to 5 seconds)") + subject + end + it "retries the request" do expect(Retry).to receive(:until_truthy_or_max_times).with(hash_including(times: 1, sleep: 5, sleep_first: true)) subject