summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/buffered_io_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/buffered_io_spec.rb')
-rw-r--r--spec/lib/gitlab/buffered_io_spec.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/lib/gitlab/buffered_io_spec.rb b/spec/lib/gitlab/buffered_io_spec.rb
new file mode 100644
index 00000000000..f8896abd46e
--- /dev/null
+++ b/spec/lib/gitlab/buffered_io_spec.rb
@@ -0,0 +1,54 @@
+# rubocop:disable Style/FrozenStringLiteralComment
+require 'spec_helper'
+
+RSpec.describe Gitlab::BufferedIo do
+ describe '#readuntil' do
+ let(:never_ending_tcp_socket) do
+ Class.new do
+ def initialize(*_)
+ @read_counter = 0
+ end
+
+ def setsockopt(*_); end
+
+ def closed?
+ false
+ end
+
+ def close
+ true
+ end
+
+ def to_io
+ StringIO.new('Hello World!')
+ end
+
+ def write_nonblock(data, *_)
+ data.size
+ end
+
+ def read_nonblock(buffer_size, *_)
+ sleep 0.01
+ @read_counter += 1
+
+ raise 'Test did not raise HeaderReadTimeout' if @read_counter > 10
+
+ 'H' * buffer_size
+ end
+ end
+ end
+
+ before do
+ stub_const('Gitlab::BufferedIo::HEADER_READ_TIMEOUT', 0.1)
+ end
+
+ subject(:readuntil) do
+ Gitlab::BufferedIo.new(never_ending_tcp_socket.new).readuntil('a')
+ end
+
+ 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
+end
+# rubocop:enable Style/FrozenStringLiteralComment