Skip to content

Commit 85a1705

Browse files
committed
Add streaming test.
1 parent c47d7ea commit 85a1705

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

test/async/http/faraday/adapter.rb

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ def get_response(url = bound_url, path = '/index', adapter_options: {})
128128

129129
expect(response.body).to be == 'text=Hello+World'
130130
end
131-
131+
132132
it "can use a ::Protocol::HTTP::Body::Readable body" do
133133
readable = ::Protocol::HTTP::Body::File.new(File.open(__FILE__, 'r'), 0...128)
134-
134+
135135
response = Faraday.new do |builder|
136136
builder.adapter :async_http
137137
end.post(bound_url, readable)
138-
138+
139139
expect(response.body).to be == File.read(__FILE__, 128)
140140
end
141141
end
@@ -155,6 +155,41 @@ def get_response(url = bound_url, path = '/index', adapter_options: {})
155155
expect(config_block_invoked).to be == true
156156
end
157157
end
158+
159+
with "a streaming response" do
160+
let(:app) do
161+
Protocol::HTTP::Middleware.for do |request|
162+
body = ::Async::HTTP::Body::Writable.new
163+
164+
Async do
165+
3.times do |i|
166+
body.write("chunk#{i}")
167+
end
168+
ensure
169+
body.close
170+
end
171+
172+
Protocol::HTTP::Response[200, {}, body]
173+
end
174+
end
175+
176+
it "can stream response" do
177+
client = Faraday.new do |builder|
178+
builder.adapter :async_http
179+
end
180+
181+
chunks = []
182+
183+
response = client.get(bound_url) do |request|
184+
request.options.on_data = proc do |chunk|
185+
chunks << chunk
186+
end
187+
end
188+
189+
expect(response.body).to be_nil
190+
expect(chunks).to be == ["chunk0", "chunk1", "chunk2"]
191+
end
192+
end
158193
end
159194

160195
with "a remote http server" do

0 commit comments

Comments
 (0)