From ccf58b93ebfa557a38cc0c77c99ee96c92e0b048 Mon Sep 17 00:00:00 2001 From: Zakir Dzhamaliddinov Date: Thu, 22 Aug 2024 16:10:03 +0300 Subject: [PATCH] Review fixes --- lib/command/base.rb | 8 ++++---- spec/command/base_spec.rb | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/command/base.rb b/lib/command/base.rb index 881728e0..c31ebddc 100644 --- a/lib/command/base.rb +++ b/lib/command/base.rb @@ -474,7 +474,7 @@ def step_finish(success, abort_on_error: true) end end - def step(message, abort_on_error: true, retry_on_failure: false, max_retry_count: Float::INFINITY, wait: 1) # rubocop:disable Metrics/MethodLength + def step(message, abort_on_error: true, retry_on_failure: false, max_retry_count: 1000, wait: 1) # rubocop:disable Metrics/MethodLength progress.print("#{message}...") Shell.use_tmp_stderr do @@ -482,15 +482,15 @@ def step(message, abort_on_error: true, retry_on_failure: false, max_retry_count begin if retry_on_failure - run_count = 0 - while !success && run_count < max_retry_count + retry_count = 0 + while !success && retry_count <= max_retry_count success = yield break if success progress.print(".") Kernel.sleep(wait) - run_count += 1 + retry_count += 1 end else success = yield diff --git a/spec/command/base_spec.rb b/spec/command/base_spec.rb index 61ca91ff..7fdb23e2 100644 --- a/spec/command/base_spec.rb +++ b/spec/command/base_spec.rb @@ -3,9 +3,8 @@ require "spec_helper" describe Command::Base do - subject(:command) { described_class.new(config) } - let(:config) { instance_double(Command::Config) } + let(:command) { described_class.new(config) } around do |example| suppress_output { example.run } @@ -25,7 +24,7 @@ true if run_count == 3 end - expect(run_count).to eq 3 + expect(run_count).to eq(3) end context "with max_retry_count option" do @@ -39,7 +38,7 @@ false end - expect(run_count).to eq 1 + expect(run_count).to eq(1 + 1) # 1 run and 1 retry after fail end end end @@ -55,7 +54,7 @@ false end - expect(run_count).to eq 1 + expect(run_count).to eq(1) end end end