Skip to content

Commit

Permalink
Test against unreleased version of the http gem
Browse files Browse the repository at this point in the history
Pointed temporarily to a patched version in my own repo to work around a circular require warning.
  • Loading branch information
hakanensari committed Dec 13, 2024
1 parent f251526 commit 87abb7f
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ jobs:
strategy:
matrix:
ruby: ["3.2", "3.3"]
appraisal: [http-5, http-github]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- run: bundle exec rake test
- run: bundle exec appraisal install
- run: bundle exec appraisal ${{ matrix.appraisal }} rake test

coverage:
if: github.event_name == 'push'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Gemfile.lock
.yardoc
coverage
doc
gemfiles/*.gemfile.lock
pkg
selling-partner-api-models
test/config.json
9 changes: 9 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

appraise "http-5" do
gem "http", "~> 5.0"
end

appraise "http-github" do
gem "http", github: "hakanensari/http", branch: "circular-require"
end
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source "https://rubygems.org"
gemspec

group :development do
gem "appraisal"
gem "minitest"
gem "rake"
gem "rubocop"
Expand Down
25 changes: 25 additions & 0 deletions gemfiles/http_5.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "http", "~> 5.0"

group :development do
gem "appraisal"
gem "minitest"
gem "rake"
gem "rubocop"
gem "rubocop-minitest"
gem "rubocop-performance"
gem "rubocop-rake"
gem "rubocop-shopify"
gem "simplecov"
gem "vcr"
gem "webmock"
gem "yard"
gem "commonmarker", "~> 0.23.10"
gem "fiddle"
gem "rdoc"
end

gemspec path: "../"
25 changes: 25 additions & 0 deletions gemfiles/http_github.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "http", github: "hakanensari/http", branch: "circular-require"

group :development do
gem "appraisal"
gem "minitest"
gem "rake"
gem "rubocop"
gem "rubocop-minitest"
gem "rubocop-performance"
gem "rubocop-rake"
gem "rubocop-shopify"
gem "simplecov"
gem "vcr"
gem "webmock"
gem "yard"
gem "commonmarker", "~> 0.23.10"
gem "fiddle"
gem "rdoc"
end

gemspec path: "../"
6 changes: 3 additions & 3 deletions lib/peddler/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def meter(rate_limit)
# HTTP v6.0 will implement retriable. Until then, point to their GitHub repo, or it's a no-op.
# https://github.com/httprb/http/pull/790
delay = sandbox? ? 0.2 : 1.0 / rate_limit
retriable(delay: delay, retry_statuses: [429])
retriable(delay: delay, tries: 3, retry_statuses: [429])

self
end
Expand All @@ -96,8 +96,8 @@ def meter(rate_limit)
# @param (see Performer#initialize)
# @return [self]
[:via, :use, :retriable].each do |method|
define_method(method) do |*args, &block|
@http = http.send(method, *args, &block) if http.respond_to?(method)
define_method(method) do |*args, **kwargs, &block|
@http = http.send(method, *args, **kwargs, &block) if http.respond_to?(method)
self
end
end
Expand Down
14 changes: 9 additions & 5 deletions test/peddler/api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,26 @@ def test_chainable_http_methods
end

def test_rate_limit_noop
skip("HTTP implements retriable") if @api.http.respond_to?(:retriable)
initial_http_object_id = @api.http.object_id
@api.meter(1.0).http

assert_equal(initial_http_object_id, @api.http.object_id)
assert_equal(initial_http_object_id, @api.meter(1.0).http.object_id)
end

def test_rate_limit
skip("HTTP v6.0 not released yet")
skip("HTTP doesn't implement retriable") unless @api.http.respond_to?(:retriable)
@api.meter(1.0)

assert_kind_of(HTTP::Retriable::Client, @api.http)
end

def test_custom_rate_limit
skip("HTTP v6.0 not released yet")
skip("HTTP doesn't expose retriable arguments")
# http.instance_variable_get(:@performer).instance_variable_get(:@delay_calculator).instance_variable_get(:@delay)
end

def test_sandbox_rate_limit
skip("HTTP v6.0 not released yet")
skip("HTTP doesn't expose retriable arguments")
end

def test_client_error
Expand Down
4 changes: 2 additions & 2 deletions test/peddler/errors/quota_exceeded_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "helper"

require "peddler/apis/product_pricing_v0"

module Peddler
Expand All @@ -11,7 +10,8 @@ class QuotaExceededTest < Minitest::Test

# I depleted quota before recording this test.
def test_quota_exceeded
error = assert_raises(QuotaExceeded) do
error_class = api.http.respond_to?(:retriable) ? HTTP::OutOfRetriesError : QuotaExceeded
error = assert_raises(error_class) do
api.get_pricing("A1F83G8C2ARO7P", "Asin", asins: ["188864544X"])
end
assert_equal(429, error.response.status)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 87abb7f

Please sign in to comment.