-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent infinite loop in
Command::Base#step
& add configurable wait…
… time (#217)
- Loading branch information
Showing
4 changed files
with
109 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,7 @@ RSpec/ExampleLength: | |
|
||
RSpec/MultipleExpectations: | ||
Enabled: false | ||
|
||
RSpec/NestedGroups: | ||
Enabled: true | ||
Max: 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
describe Command::Base do | ||
let(:config) { instance_double(Command::Config) } | ||
let(:command) { described_class.new(config) } | ||
|
||
around do |example| | ||
suppress_output { example.run } | ||
end | ||
|
||
describe "#step" do | ||
let(:message) { "test message" } | ||
let(:common_options) { { abort_on_error: false } } | ||
|
||
context "with retry_on_failure: true" do | ||
let(:options) { common_options.merge(retry_on_failure: true, wait: 0) } | ||
|
||
it "retries block until success" do | ||
run_count = 0 | ||
|
||
command.step(message, **options) do | ||
run_count += 1 | ||
true if run_count == 3 | ||
end | ||
|
||
expect(run_count).to eq(3) | ||
end | ||
|
||
it "does not exceed default max_retry_count" do | ||
run_count = 0 | ||
|
||
command.step(message, **options) do | ||
run_count += 1 | ||
false | ||
end | ||
|
||
expect(run_count).to eq(1001) | ||
end | ||
|
||
context "with max_retry_count option" do # rubocop:disable RSpec/MultipleMemoizedHelpers | ||
let(:options_with_max_retry_count) { common_options.merge(retry_on_failure: true, wait: 0, max_retry_count: 1) } | ||
|
||
it "retries block specified times" do | ||
run_count = 0 | ||
|
||
command.step(message, **options_with_max_retry_count) do | ||
run_count += 1 | ||
false | ||
end | ||
|
||
expect(run_count).to eq(2) | ||
end | ||
end | ||
end | ||
|
||
context "with retry_on_failure: false" do | ||
let(:options) { common_options.merge(retry_on_failure: false) } | ||
|
||
it "does not retry block" do | ||
run_count = 0 | ||
|
||
command.step(message, **options) do | ||
run_count += 1 | ||
false | ||
end | ||
|
||
expect(run_count).to eq(1) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters