Skip to content

Commit

Permalink
Add streaming test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Aug 13, 2024
1 parent c47d7ea commit 85a1705
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions test/async/http/faraday/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ def get_response(url = bound_url, path = '/index', adapter_options: {})

expect(response.body).to be == 'text=Hello+World'
end

it "can use a ::Protocol::HTTP::Body::Readable body" do
readable = ::Protocol::HTTP::Body::File.new(File.open(__FILE__, 'r'), 0...128)

response = Faraday.new do |builder|
builder.adapter :async_http
end.post(bound_url, readable)

expect(response.body).to be == File.read(__FILE__, 128)
end
end
Expand All @@ -155,6 +155,41 @@ def get_response(url = bound_url, path = '/index', adapter_options: {})
expect(config_block_invoked).to be == true
end
end

with "a streaming response" do
let(:app) do
Protocol::HTTP::Middleware.for do |request|
body = ::Async::HTTP::Body::Writable.new

Async do
3.times do |i|
body.write("chunk#{i}")
end
ensure
body.close
end

Protocol::HTTP::Response[200, {}, body]
end
end

it "can stream response" do
client = Faraday.new do |builder|
builder.adapter :async_http
end

chunks = []

response = client.get(bound_url) do |request|
request.options.on_data = proc do |chunk|
chunks << chunk
end
end

expect(response.body).to be_nil
expect(chunks).to be == ["chunk0", "chunk1", "chunk2"]
end
end
end

with "a remote http server" do
Expand Down

0 comments on commit 85a1705

Please sign in to comment.