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

Harmonize Rack dependency and tests #27

Merged
merged 27 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ jobs:
matrix:
ruby:
- "2.7"
- "3.2"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this intentionall removed? Testing on a recent Ruby version seems useful.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because then the matrix turns into 4 versions - and I had some trouble loading older ActiveRecord on the newer Ruby versions. I presume what works on 2.7 will work on 3.x anyway, so it felt like a good comproimse

services:
mysql:
image: mysql:5.7
Expand Down Expand Up @@ -71,8 +70,8 @@ jobs:
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: RSpec
run: bundle exec rspec
- name: RSpec via Appraisal
run: bundle exec appraisal rspec
env:
MYSQL_HOST: 127.0.0.1
MYSQL_PORT: 3306
Expand Down
7 changes: 7 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appraise "rack-3" do
gem "rack", ">= 3.0"
end

appraise "rack-2" do
gem "rack", ">= 2.0", "< 3.0"
end
5 changes: 4 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ require "rspec/core/rake_task"
require "standard/rake"

RSpec::Core::RakeTask.new(:spec)

task default: :spec

if !ENV["APPRAISAL_INITIALIZED"]
julik marked this conversation as resolved.
Show resolved Hide resolved
task default: :appraisal
end
2 changes: 2 additions & 0 deletions gemfiles/.bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
BUNDLE_RETRY: "1"
julik marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions gemfiles/rack_2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rack", ">= 2.0", "< 3.0"

gemspec path: "../"
134 changes: 134 additions & 0 deletions gemfiles/rack_2.gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
PATH
remote: ..
specs:
idempo (1.2.2)
measurometer (~> 1.3)
msgpack
rack (< 4)

GEM
remote: https://rubygems.org/
specs:
activemodel (7.1.5)
activesupport (= 7.1.5)
activerecord (7.1.5)
activemodel (= 7.1.5)
activesupport (= 7.1.5)
timeout (>= 0.4.0)
activesupport (7.1.5)
base64
benchmark (>= 0.3)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
mutex_m
securerandom (>= 0.3)
tzinfo (~> 2.0)
appraisal (2.5.0)
bundler
rake
thor (>= 0.14.0)
ast (2.4.2)
base64 (0.2.0)
benchmark (0.3.0)
bigdecimal (3.1.8)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
diff-lcs (1.5.1)
drb (2.2.1)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
json (2.7.6)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
logger (1.6.1)
measurometer (1.3.0)
minitest (5.25.1)
msgpack (1.7.3)
mutex_m (0.2.0)
mysql2 (0.5.6)
parallel (1.26.3)
parser (3.3.5.1)
ast (~> 2.4.1)
racc
pg (1.5.9)
racc (1.8.1)
rack (2.2.9)
rack-test (2.1.0)
rack (>= 1.3)
rainbow (3.1.1)
rake (13.2.1)
redis (4.8.1)
regexp_parser (2.9.2)
rexml (3.3.9)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.2)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rubocop (1.64.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.33.1)
parser (>= 3.3.1.0)
rubocop-performance (1.21.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (1.13.0)
securerandom (0.3.1)
standard (1.37.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.64.0)
standard-custom (~> 1.0.0)
standard-performance (~> 1.4)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.4.0)
lint_roller (~> 1.1)
rubocop-performance (~> 1.21.0)
thor (1.3.2)
timeout (0.4.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.6.0)

PLATFORMS
ruby

DEPENDENCIES
activerecord
appraisal
idempo!
mysql2
pg
rack (>= 2.0, < 3.0)
rack-test
rake (~> 13.0)
redis (~> 4)
rspec (~> 3.0)
standard

BUNDLED WITH
2.1.4
7 changes: 7 additions & 0 deletions gemfiles/rack_3.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rack", ">= 3.0"

gemspec path: "../"
134 changes: 134 additions & 0 deletions gemfiles/rack_3.gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
PATH
remote: ..
specs:
idempo (1.2.2)
measurometer (~> 1.3)
msgpack
rack (< 4)

GEM
remote: https://rubygems.org/
specs:
activemodel (7.1.5)
activesupport (= 7.1.5)
activerecord (7.1.5)
activemodel (= 7.1.5)
activesupport (= 7.1.5)
timeout (>= 0.4.0)
activesupport (7.1.5)
base64
benchmark (>= 0.3)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
mutex_m
securerandom (>= 0.3)
tzinfo (~> 2.0)
appraisal (2.5.0)
bundler
rake
thor (>= 0.14.0)
ast (2.4.2)
base64 (0.2.0)
benchmark (0.3.0)
bigdecimal (3.1.8)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
diff-lcs (1.5.1)
drb (2.2.1)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
json (2.7.6)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
logger (1.6.1)
measurometer (1.3.0)
minitest (5.25.1)
msgpack (1.7.3)
mutex_m (0.2.0)
mysql2 (0.5.6)
parallel (1.26.3)
parser (3.3.5.1)
ast (~> 2.4.1)
racc
pg (1.5.9)
racc (1.8.1)
rack (3.1.8)
rack-test (2.1.0)
rack (>= 1.3)
rainbow (3.1.1)
rake (13.2.1)
redis (4.8.1)
regexp_parser (2.9.2)
rexml (3.3.9)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.2)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rubocop (1.64.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.33.1)
parser (>= 3.3.1.0)
rubocop-performance (1.21.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (1.13.0)
securerandom (0.3.1)
standard (1.37.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.64.0)
standard-custom (~> 1.0.0)
standard-performance (~> 1.4)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.4.0)
lint_roller (~> 1.1)
rubocop-performance (~> 1.21.0)
thor (1.3.2)
timeout (0.4.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.6.0)

PLATFORMS
ruby

DEPENDENCIES
activerecord
appraisal
idempo!
mysql2
pg
rack (>= 3.0)
rack-test
rake (~> 13.0)
redis (~> 4)
rspec (~> 3.0)
standard

BUNDLED WITH
2.1.4
5 changes: 3 additions & 2 deletions idempo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ Gem::Specification.new do |spec|
# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features|gemfiless)/}) }
julik marked this conversation as resolved.
Show resolved Hide resolved
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "msgpack"
spec.add_dependency "measurometer", "~> 1.3"
spec.add_dependency "rack", "< 4"

spec.add_development_dependency "rack", "~> 3"
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "redis", "~> 4"
Expand All @@ -47,6 +47,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "mysql2"
spec.add_development_dependency "pg"
spec.add_development_dependency "standard"
spec.add_development_dependency "appraisal"

# For more information and examples about making a new gem, checkout our
# guide at: https://bundler.io/guides/creating_gem.html
Expand Down
18 changes: 10 additions & 8 deletions lib/idempo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ def call(env)

expires_in_seconds = (headers.delete("X-Idempo-Persist-For-Seconds") || @persist_for_seconds).to_i

# In some cases `body` could respond to to_ary. In this case, we don't need to call .close on body afterwards.
# In some cases `body` could respond to to_ary. In this case, we don't need to
# call .close on the body afterwards, as it is supposed to self-close as per Rack 3.0 SPEC
#
# @see https://github.com/rack/rack/blob/main/SPEC.rdoc#the-body-
body = body.to_ary if rack_v3? && body.respond_to?(:to_ary)
body = body.to_ary if body.respond_to?(:to_ary)

if response_may_be_persisted?(status, headers, body)
# Body is replaced with a cached version since a Rack response body is not rewindable
Expand All @@ -83,10 +84,6 @@ def call(env)

private

def rack_v3?
Gem::Version.new(Rack.release) >= Gem::Version.new("3.0")
end

def from_persisted_response(marshaled_response)
if marshaled_response[-2..] != ":1"
raise Error, "Unknown serialization of the marshaled response"
Expand Down Expand Up @@ -127,10 +124,15 @@ def response_may_be_persisted?(status, headers, body)
end

def body_size_within_limit?(response_headers, body)
return response_headers["Content-Length"].to_i <= SAVED_RESPONSE_BODY_SIZE_LIMIT if response_headers["Content-Length"]
lowercase_response_headers = response_headers.map do |(k, v)|
[k.downcase, v]
end.to_h
julik marked this conversation as resolved.
Show resolved Hide resolved

return false unless body.is_a?(Array) # Arbitrary iterable of unknown size
if response_headers["content-length"]
julik marked this conversation as resolved.
Show resolved Hide resolved
return lowercase_response_headers["content-length"].to_i <= SAVED_RESPONSE_BODY_SIZE_LIMIT
end

return false unless body.is_a?(Array) # Arbitrary iterable of unknown size
sum_of_string_bytesizes(body) <= SAVED_RESPONSE_BODY_SIZE_LIMIT
end

Expand Down
Loading
Loading