-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Refactor] Improve Retryer specs #86
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,37 +78,30 @@ | |
expect(on_retry_calls).to equal(retries) | ||
end | ||
|
||
{ | ||
GRPC::AlreadyExists => false, | ||
GRPC::Cancelled => false, | ||
GRPC::FailedPrecondition => false, | ||
GRPC::InvalidArgument => false, | ||
GRPC::NotFound => false, | ||
GRPC::PermissionDenied => false, | ||
GRPC::Unauthenticated => false, | ||
GRPC::Unimplemented => false, | ||
StandardError => true, | ||
GRPC::Unknown => true, | ||
GRPC::Unavailable => true | ||
}.each do |error_class, expect_retry| | ||
it "#{expect_retry ? 'does' : 'does not'} retry #{error_class}" do | ||
on_retry_calls = 0 | ||
retried = false | ||
on_retry = Proc.new { | ||
on_retry_calls += 1 | ||
} | ||
|
||
begin | ||
described_class.with_retries(on_retry: on_retry) do | ||
if !retried | ||
retried = true | ||
raise error_class.new("nope") | ||
described_class::DO_NOT_RETRY_ERRORS.each do |error_class| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd advise against this change because it assumes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @drewhoskins-stripe do you have a failure mode in mind? Would it be someone adding an error to the list that should be retryable instead? But there isn't a great way to test against that unless you run test all possible error classes, which is not a real solution. The retry case is covered by the spec above this one, but I see now that it's a bit different, I'll add the missing bit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually looking at this again… the retry case is identical to the spec above because of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are not the same test. In one case, you retry a few times. In this one, you don't retry at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yep, it's a bit subtle but worth discussing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't get it. In the current version you would retry once and then throw, which is no different from say I agree that having a "contract" in place is beneficial, it practise what would happen is whoever removes an error from the list will also update the spec with an equal change. But there's another side to it — someone might add an error to the list and not update the spec. In this case the spec will not fail and the contract gets broken. That can probably be solved by a specific test that checks which exact errors are listed as non-retriable |
||
context "when #{error_class} is raised" do | ||
let(:error) { error_class.new('nope') } | ||
let(:on_retry) { Proc.new {} } | ||
|
||
it 'does not retry' do | ||
calls = 0 | ||
|
||
expect do | ||
described_class.with_retries do | ||
calls += 1 | ||
raise error | ||
end | ||
end | ||
rescue => e | ||
expect(e.class).to eq(error_class) | ||
ensure | ||
expect(on_retry_calls).to equal(expect_retry ? 1 : 0) | ||
end.to raise_error(error) | ||
|
||
expect(calls).to eq(1) | ||
end | ||
|
||
it 'does not call on_retry' do | ||
allow(on_retry).to receive(:call).and_call_original | ||
|
||
described_class.with_retries(on_retry: on_retry) { raise error } rescue nil | ||
|
||
expect(on_retry).not_to have_received(:call) | ||
end | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍