Skip to content

Commit

Permalink
Merge pull request #113 from treasure-data/validate-status-only-on-fi…
Browse files Browse the repository at this point in the history
…rst-chunk

validate HTTP status only on first chunk
  • Loading branch information
nurse committed Sep 21, 2017
2 parents 64c6797 + 501af8e commit beaea27
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/td/client/api/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,12 @@ def job_result_download(job_id, format='msgpack', autodecode=true)
current_total_chunk_size = 0
infl = nil
begin # LOOP of Network/Server errors
first_chunk_p = true
response = client.get(url, params, header) do |res, chunk|
validate_response_status(res, current_total_chunk_size)
# Validate only on first chunk
validate_response_status(res, current_total_chunk_size) if first_chunk_p
first_chunk_p = false

if infl.nil? && autodecode
case res.header['Content-Encoding'][0].to_s.downcase
when 'gzip'
Expand Down
15 changes: 15 additions & 0 deletions spec/td/client/job_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,21 @@
expect(api.job_result(12345)).to eq ['hello', 'world']
end

it 'has multiple chunks' do
client = double('client')
allow(api).to receive(:new_client).and_return([client, {}])
allow(client).to receive(:send_timeout=)
allow(client).to receive(:receive_timeout=)
res = HTTP::Message.new_response(nil, HTTP::Message::Headers.new)
sz = 3
chunk1 = packed[0, sz]
chunk2 = packed[sz, packed.bytesize-sz]
expect(client).to receive(:get).
and_yield(res, chunk1).
and_yield(res, chunk2).
and_return(res)
expect(api.job_result(12345)).to eq ['hello', 'world']
end
end

describe 'job_result_format' do
Expand Down

0 comments on commit beaea27

Please sign in to comment.