Skip to content

Commit

Permalink
Merge pull request #54 from sue445/feature/integration_retry
Browse files Browse the repository at this point in the history
Add retryable to all API call
  • Loading branch information
sue445 committed Jun 13, 2018
2 parents 4680c7b + 06e96cc commit ce06400
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
21 changes: 14 additions & 7 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
end

it "successful real http connection" do # rubocop:disable RSpec/ExampleLength
category_and_boards = Itest5ch::Board.all
category_and_boards = Retryable.with_context(:default) do
Itest5ch::Board.all
end

expect(category_and_boards).to be_an_instance_of(Hash)

Expand All @@ -21,7 +23,13 @@

board = boards.sample

threads = board.threads
thread_exception_cb = proc do |_exception|
puts "Error: #{board.json_url}"
end

threads = Retryable.with_context(:default, exception_cb: thread_exception_cb) do
board.threads
end

aggregate_failures do
expect(threads).not_to be_empty
Expand All @@ -30,14 +38,13 @@

thread = threads.sample

exception_cb = proc do |_exception|
comment_exception_cb = proc do |_exception|
puts "Error: #{thread.json_url}"
end

comments =
Retryable.retryable(tries: 5, on: JSON::ParserError, exception_cb: exception_cb) do
thread.comments
end
comments = Retryable.with_context(:default, exception_cb: comment_exception_cb) do
thread.comments
end

aggregate_failures do
expect(comments).not_to be_empty
Expand Down
16 changes: 16 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
require "active_support/time"
require "rspec-parameterized"
require "retryable"
require "open-uri"

Dir["#{__dir__}/support/**/*.rb"].each {|f| require f }

Expand Down Expand Up @@ -137,3 +138,18 @@ def spec_dir
c.syntax = :expect
end
end

Retryable.configure do |config|
retryable_errors = [
JSON::ParserError,
Net::OpenTimeout,
Net::ReadTimeout,
OpenURI::HTTPError,
]

config.contexts[:default] = {
on: retryable_errors,
sleep: 1,
tries: 5,
}
end

0 comments on commit ce06400

Please sign in to comment.