Skip to content
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

Handle additional variations of rate limit error messages #182

Merged
merged 2 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## HEAD

- Handle additional variations of rate limit error messages (https://github.com/heroku/hatchet/pull/182)
- Add `HATCHET_DEFAULT_STACK` for configuring the default stack (https://github.com/heroku/hatchet/pull/184)
- Fix typo in the reaper `"Duplicate destroy attempted"` message (https://github.com/heroku/hatchet/pull/175)
- Set `init.defaultBranch` in ci:setup to suppress `git init` warning in Git 2.30+ (https://github.com/heroku/hatchet/issues/172)
Expand Down
2 changes: 1 addition & 1 deletion lib/hatchet/git_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def push_without_retry!
output = git_push_heroku_yall
rescue FailedDeploy => e
case e.output
when /reached the API rate limit/, /429 Too Many Requests/
when /reached the API rate limit/, /429 Too Many Requests/, /HTTP 429/, /HTTP code = 429/
throw(:throttle)
else
raise e unless @allow_failure
Expand Down
52 changes: 50 additions & 2 deletions spec/unit/shell_throttle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def throttle.sleep(value)
end

describe "git push throttle" do
it "rate throttles `git push` " do
it "rate throttles `git push` with output variation 1" do
app = Hatchet::GitApp.new("default_ruby")
def app.git_push_heroku_yall
@_git_push_heroku_yall_call_count ||= 0
Expand All @@ -67,7 +67,7 @@ def app.what_is_git_push_heroku_yall_call_count; @_git_push_heroku_yall_call_cou
expect(app.what_is_git_push_heroku_yall_call_count).to be(2)
end

it "rate throttles `git push` with different output" do
it "rate throttles `git push` with output variation 2" do
app = Hatchet::GitApp.new("default_ruby")
def app.git_push_heroku_yall
@_git_push_heroku_yall_call_count ||= 0
Expand All @@ -90,5 +90,53 @@ def app.what_is_git_push_heroku_yall_call_count; @_git_push_heroku_yall_call_cou

expect(app.what_is_git_push_heroku_yall_call_count).to be(2)
end

it "rate throttles `git push` with output variation 3" do
app = Hatchet::GitApp.new("default_ruby")
def app.git_push_heroku_yall
@_git_push_heroku_yall_call_count ||= 0
@_git_push_heroku_yall_call_count += 1
if @_git_push_heroku_yall_call_count >= 2
"Success"
else
raise Hatchet::App::FailedDeployError.new(
self,
"message",
output: "error: RPC failed; HTTP 429 curl 22 The requested URL returned error: 429"
)
end
end

def app.sleep_called?; @sleep_called; end
def app.what_is_git_push_heroku_yall_call_count; @_git_push_heroku_yall_call_count; end

app.push_without_retry!

expect(app.what_is_git_push_heroku_yall_call_count).to be(2)
end

it "rate throttles `git push` with output variation 4" do
app = Hatchet::GitApp.new("default_ruby")
def app.git_push_heroku_yall
@_git_push_heroku_yall_call_count ||= 0
@_git_push_heroku_yall_call_count += 1
if @_git_push_heroku_yall_call_count >= 2
"Success"
else
raise Hatchet::App::FailedDeployError.new(
self,
"message",
output: "error: RPC failed; result=22, HTTP code = 429"
)
end
end

def app.sleep_called?; @sleep_called; end
def app.what_is_git_push_heroku_yall_call_count; @_git_push_heroku_yall_call_count; end

app.push_without_retry!

expect(app.what_is_git_push_heroku_yall_call_count).to be(2)
end
end
end