From edaa33dee2ff2f7ea3fac488d41558eb5f86d68c Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 20 Jan 2022 09:16:11 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-7-stable-ee --- spec/lib/gitlab/http_spec.rb | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'spec/lib/gitlab/http_spec.rb') diff --git a/spec/lib/gitlab/http_spec.rb b/spec/lib/gitlab/http_spec.rb index d0aae2ac475..7d459f2d88a 100644 --- a/spec/lib/gitlab/http_spec.rb +++ b/spec/lib/gitlab/http_spec.rb @@ -29,14 +29,42 @@ RSpec.describe Gitlab::HTTP do context 'when reading the response is too slow' do before do + # Override Net::HTTP to add a delay between sending each response chunk + mocked_http = Class.new(Net::HTTP) do + def request(*) + super do |response| + response.instance_eval do + def read_body(*) + @body.each do |fragment| + sleep 0.002.seconds + + yield fragment if block_given? + end + end + end + + yield response if block_given? + + response + end + end + end + + @original_net_http = Net.send(:remove_const, :HTTP) + Net.send(:const_set, :HTTP, mocked_http) + stub_const("#{described_class}::DEFAULT_READ_TOTAL_TIMEOUT", 0.001.seconds) WebMock.stub_request(:post, /.*/).to_return do |request| - sleep 0.002.seconds - { body: 'I\'m slow', status: 200 } + { body: %w(a b), status: 200 } end end + after do + Net.send(:remove_const, :HTTP) + Net.send(:const_set, :HTTP, @original_net_http) + end + let(:options) { {} } subject(:request_slow_responder) { described_class.post('http://example.org', **options) } @@ -51,7 +79,7 @@ RSpec.describe Gitlab::HTTP do end it 'still calls the block' do - expect { |b| described_class.post('http://example.org', **options, &b) }.to yield_with_args + expect { |b| described_class.post('http://example.org', **options, &b) }.to yield_successive_args('a', 'b') end end -- cgit v1.2.3