Skip to content

Commit

Permalink
feat: update message when waiting for verification results
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Apr 16, 2020
1 parent 0ec991c commit 68df012
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/pact_broker/client/can_i_deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ 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)"
results = matrix.unknown_count == 1 ? "result" : "results"
$stderr.puts "Waiting for #{matrix.unknown_count} verification #{results} to be published (maximum of #{wait_time} seconds)"
matrix = Retry.until_truthy_or_max_times(retry_options) do
fetch_matrix
end
Expand Down
6 changes: 5 additions & 1 deletion lib/pact_broker/client/matrix/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize hash

def any_unknown?
if supports_unknown_count?
self[:summary][:unknown] > 0
unknown_count > 0
else
false
end
Expand All @@ -21,6 +21,10 @@ def supports_unknown_count?
!!(self[:summary] && Integer === self[:summary][:unknown] )
end

def unknown_count
supports_unknown_count? ? self[:summary][:unknown] : nil
end

def reason
self[:summary][:reason]
end
Expand Down
18 changes: 13 additions & 5 deletions spec/lib/pact_broker/client/can_i_deploy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ module Client
let(:matrix_options) { {} }
let(:pact_broker_client_options) { { foo: 'bar' } }
let(:matrix_client) { instance_double('PactBroker::Client::Matrix') }
let(:matrix) { instance_double('Matrix::Resource', deployable?: true, reason: 'some reason', any_unknown?: any_unknown, supports_unknown_count?: supports_unknown_count) }
let(:any_unknown) { false }
let(:matrix) do
instance_double('Matrix::Resource',
deployable?: true,
reason: 'some reason',
any_unknown?: any_unknown,
supports_unknown_count?: supports_unknown_count,
unknown_count: unknown_count)
end
let(:unknown_count) { 0 }
let(:any_unknown) { unknown_count > 0 }
let(:supports_unknown_count) { true }
let(:retry_while_unknown) { 0 }
let(:options) { { output: 'text', retry_while_unknown: retry_while_unknown, retry_interval: 5} }
let(:options) { { output: 'text', retry_while_unknown: retry_while_unknown, retry_interval: 5 } }


before do
Expand Down Expand Up @@ -81,10 +89,10 @@ module Client
allow(Retry).to receive(:until_truthy_or_max_times)
end

let(:any_unknown) { true }
let(:unknown_count) { 1 }

it "puts a message to stderr" do
expect($stderr).to receive(:puts).with("Waiting for verification results to be published (up to 5 seconds)")
expect($stderr).to receive(:puts).with("Waiting for 1 verification result to be published (maximum of 5 seconds)")
subject
end

Expand Down

0 comments on commit 68df012

Please sign in to comment.