debian-mirror-gitlab/spec/lib/gitlab/buffered_io_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.4 KiB
Ruby
Raw Normal View History

2022-07-01 11:34:44 +05:30
# frozen_string_literal: true
2022-04-04 11:22:00 +05:30
require 'spec_helper'
RSpec.describe Gitlab::BufferedIo do
describe '#readuntil' do
2022-07-01 11:34:44 +05:30
let(:mock_io) { StringIO.new('a') }
let(:start_time) { Process.clock_gettime(Process::CLOCK_MONOTONIC) }
2022-04-04 11:22:00 +05:30
2022-07-01 11:34:44 +05:30
before do
stub_const('Gitlab::BufferedIo::HEADER_READ_TIMEOUT', 0.1)
end
2022-04-04 11:22:00 +05:30
2022-07-01 11:34:44 +05:30
subject(:readuntil) do
Gitlab::BufferedIo.new(mock_io).readuntil('a', false, start_time)
end
2022-04-04 11:22:00 +05:30
2022-07-01 11:34:44 +05:30
it 'does not raise a timeout error' do
expect { readuntil }.not_to raise_error
end
2022-04-04 11:22:00 +05:30
2022-07-01 11:34:44 +05:30
context 'when the response contains infinitely long headers' do
before do
read_counter = 0
2022-04-04 11:22:00 +05:30
2022-07-01 11:34:44 +05:30
allow(mock_io).to receive(:read_nonblock) do |buffer_size, *_|
read_counter += 1
raise 'Test did not raise HeaderReadTimeout' if read_counter > 10
2022-04-04 11:22:00 +05:30
sleep 0.01
'H' * buffer_size
end
end
2022-07-01 11:34:44 +05:30
it 'raises a timeout error' do
expect { readuntil }.to raise_error(Gitlab::HTTP::HeaderReadTimeout, /Request timed out after reading headers for 0\.[0-9]+ seconds/)
end
2022-04-04 11:22:00 +05:30
2022-07-01 11:34:44 +05:30
context 'when not passing start_time' do
subject(:readuntil) do
Gitlab::BufferedIo.new(mock_io).readuntil('a', false)
end
2022-04-04 11:22:00 +05:30
2022-07-01 11:34:44 +05:30
it 'raises a timeout error' do
expect { readuntil }.to raise_error(Gitlab::HTTP::HeaderReadTimeout, /Request timed out after reading headers for 0\.[0-9]+ seconds/)
end
end
2022-04-04 11:22:00 +05:30
end
end
end