-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle rate limiting by sleeping required amount
- Loading branch information
Showing
2 changed files
with
42 additions
and
23 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
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 |
---|---|---|
|
@@ -71,5 +71,29 @@ def test_succeeds_when_reponse_is_a_201 | |
|
||
@client.lookup_user_by_email("[email protected]") | ||
end | ||
|
||
def test_handles_sleeping | ||
counter = 0 | ||
|
||
stub_request(:get, /slack.com/).to_return do | ||
counter += 1 | ||
if counter == 1 | ||
{ status: 429, headers: { "Retry-After" => "1" } } | ||
else | ||
{ status: 201, body: JSON.dump(ok: true) } | ||
end | ||
end | ||
|
||
@client.lookup_user_by_email("[email protected]") | ||
end | ||
|
||
def test_fails_sleeping | ||
stub_request(:get, /slack.com/) | ||
.to_return(status: 429, headers: { "Retry-After" => "0" }) | ||
|
||
assert_raises(Net::HTTPError) do | ||
@client.lookup_user_by_email("[email protected]") | ||
end | ||
end | ||
end | ||
end |