Skip to content

Commit b494e2c

Browse files
committed
Add JRuby support and automated gem release workflow
1 parent 6346bd3 commit b494e2c

19 files changed

Lines changed: 378 additions & 232 deletions

File tree

.github/workflows/push.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Push gem to RubyGems
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
push:
13+
if: github.repository == 'httprb/http'
14+
runs-on: ubuntu-latest
15+
16+
environment:
17+
name: rubygems.org
18+
url: https://rubygems.org/gems/http
19+
20+
permissions:
21+
contents: write
22+
id-token: write
23+
24+
strategy:
25+
matrix:
26+
ruby: [ ruby, jruby ]
27+
28+
steps:
29+
- uses: actions/checkout@v6
30+
31+
- uses: ruby/setup-ruby@v1
32+
with:
33+
ruby-version: ${{ matrix.ruby }}
34+
bundler-cache: true
35+
36+
- uses: rubygems/release-gem@v1
37+
env:
38+
HTTP_PLATFORM: ${{ matrix.ruby == 'jruby' && 'java' || '' }}
39+
40+
- name: Create GitHub release
41+
run: |
42+
tag_name="$(git describe --tags --abbrev=0)"
43+
gh release create "${tag_name}" --verify-tag --generate-notes
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
if: matrix.ruby == 'ruby'

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: [ main ]
88

99
env:
10-
BUNDLE_WITHOUT: "development"
10+
BUNDLE_WITHOUT: "development:sig"
1111

1212
jobs:
1313
test:
@@ -27,3 +27,4 @@ jobs:
2727

2828
- name: bundle exec rake test
2929
run: bundle exec rake test
30+
timeout-minutes: 10

Gemfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@ group :test do
2323
gem "simplecov", require: false
2424
gem "simplecov-lcov", require: false
2525

26-
gem "minitest-memory"
26+
gem "minitest-memory", platform: :mri
2727
gem "minitest-mock"
2828
gem "minitest-strict"
2929

3030
gem "mutant-minitest"
3131

32-
gem "steep"
3332
gem "yardstick"
3433
end
3534

35+
group :sig do
36+
gem "steep"
37+
end
38+
3639
group :doc do
3740
gem "kramdown"
3841
gem "yard"

http.gemspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ Gem::Specification.new do |spec|
4040
spec.add_dependency "http-cookie", "~> 1.0"
4141
spec.add_dependency "http-form_data", "~> 2.2"
4242

43-
# Use native llhttp for MRI (more performant) and llhttp-ffi for other interpreters (better compatibility)
44-
if RUBY_ENGINE == "ruby"
45-
spec.add_dependency "llhttp", "~> 0.6.1"
46-
else
43+
if RUBY_ENGINE == "jruby"
44+
spec.platform = "java" if ENV["HTTP_PLATFORM"] == "java"
4745
spec.add_dependency "llhttp-ffi", "~> 0.5.1"
46+
else
47+
spec.add_dependency "llhttp", "~> 0.6.1"
4848
end
4949
end

lib/http/options.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ def assign_options(env)
231231
# @api private
232232
# @return [void]
233233
def argument_error!(message)
234-
raise(Error, message, caller(1..-1))
234+
error = Error.new(message)
235+
error.set_backtrace(caller(1) || [])
236+
raise error
235237
end
236238
end
237239
end

test/http/base64_test.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

33
require "test_helper"
4-
require "base64"
54

65
describe HTTP::Base64 do
76
cover "HTTP::Base64*"
@@ -16,10 +15,10 @@
1615
assert_equal "aGVsbG8=", encoder.send(:encode64, "hello")
1716
end
1817

19-
it "produces output decodable by standard Base64" do
18+
it "produces output that round-trips back to the original input" do
2019
input = "user:password"
2120

22-
assert_equal input, Base64.strict_decode64(encoder.send(:encode64, input))
21+
assert_equal input, encoder.send(:encode64, input).unpack1("m0")
2322
end
2423

2524
it "encodes empty string" do

test/http/client_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def on_error(request, error)
407407

408408
assert_raises(HTTP::TimeoutError) do
409409
client.use(test_feature: feature_instance)
410-
.timeout(0.025)
410+
.timeout(0.01)
411411
.request(:post, sleep_url)
412412
end
413413

@@ -420,7 +420,7 @@ def on_error(request, error)
420420
sleep_url = "#{dummy.endpoint}/sleep"
421421
feature_instance = feature_class.new
422422

423-
TCPSocket.stub(:open, ->(*) { sleep 1 }) do
423+
TCPSocket.stub(:open, ->(*) { sleep 0.1 }) do
424424
assert_raises(HTTP::ConnectTimeoutError) do
425425
client.use(test_feature: feature_instance)
426426
.timeout(0.001)

test/http/headers/normalizer_test.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@
2828
assert normalized_headers.none?(&:frozen?)
2929
end
3030

31-
it "allocates minimal memory for normalization of the same header" do
32-
normalizer.call("accept") # Ensure normalizer is pre-allocated
33-
34-
# On first call it is expected to allocate during normalization
35-
assert_allocations(Array: 1, MatchData: 1, String: 6) do
36-
normalizer.call("content_type")
37-
end
38-
39-
# On subsequent call it is expected to only allocate copy of a cached string
40-
assert_allocations(Array: 0, MatchData: 0, String: 1) do
41-
normalizer.call("content_type")
31+
if RUBY_ENGINE == "ruby"
32+
it "allocates minimal memory for normalization of the same header" do
33+
normalizer.call("accept") # Ensure normalizer is pre-allocated
34+
35+
# On first call it is expected to allocate during normalization
36+
assert_allocations(Array: 1, MatchData: 1, String: 6) do
37+
normalizer.call("content_type")
38+
end
39+
40+
# On subsequent call it is expected to only allocate copy of a cached string
41+
assert_allocations(Array: 0, MatchData: 0, String: 1) do
42+
normalizer.call("content_type")
43+
end
4244
end
4345
end
4446

test/http/retriable/performer_test.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,19 @@ def response(**options)
233233
end
234234

235235
describe "delay option" do
236-
let(:timing_slack) { 0.05 }
236+
it "sleeps for the calculated delay" do
237+
slept_values = []
238+
performer = HTTP::Retriable::Performer.new(delay: 0.123, tries: 2, should_retry: ->(*) { true })
239+
performer.define_singleton_method(:sleep) { |d| slept_values << d }
240+
241+
assert_raises(HTTP::OutOfRetriesError) do
242+
performer.perform(client, request) { response }
243+
end
244+
245+
assert_equal [0.123], slept_values
246+
end
247+
248+
let(:timing_slack) { 0.5 }
237249

238250
it "can be a positive number" do
239251
time, = measure_wait do

test/http/session_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185

186186
describe "thread safety" do
187187
it "can be shared across threads without errors" do
188-
shared_session = HTTP.headers("Accept" => "text/html").timeout(5)
188+
shared_session = HTTP.headers("Accept" => "text/html").timeout(15)
189189
errors = []
190190
mutex = Mutex.new
191191

0 commit comments

Comments
 (0)