diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
commit | 9297025d0b7ddf095eb618dfaaab2ff8f2018d8b (patch) | |
tree | 865198c01d1824a9b098127baa3ab980c9cd2c06 /spec/lib/gitlab/http_spec.rb | |
parent | 6372471f43ee03c05a7c1f8b0c6ac6b8a7431dbe (diff) |
Add latest changes from gitlab-org/gitlab@16-7-stable-eev16.7.0-rc42
Diffstat (limited to 'spec/lib/gitlab/http_spec.rb')
-rw-r--r-- | spec/lib/gitlab/http_spec.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/lib/gitlab/http_spec.rb b/spec/lib/gitlab/http_spec.rb index a9e0c6a3b92..3fc486a8984 100644 --- a/spec/lib/gitlab/http_spec.rb +++ b/spec/lib/gitlab/http_spec.rb @@ -32,6 +32,45 @@ RSpec.describe Gitlab::HTTP, feature_category: :shared do described_class.get('/path', allow_object_storage: true) end end + + context 'when passing async:true' do + it 'calls Gitlab::HTTP_V2.get with default options and async:true' do + expect(Gitlab::HTTP_V2).to receive(:get) + .with('/path', default_options.merge(async: true)) + + described_class.get('/path', async: true) + end + + it 'returns a Gitlab::HTTP_V2::LazyResponse object' do + stub_request(:get, 'http://example.org').to_return(status: 200, body: 'hello world') + result = described_class.get('http://example.org', async: true) + + expect(result).to be_a(Gitlab::HTTP_V2::LazyResponse) + + result.execute + result.wait + + expect(result.value).to be_a(HTTParty::Response) + expect(result.value.body).to eq('hello world') + end + + context 'when there is a DB call in the concurrent thread' do + it 'raises Gitlab::Utils::ConcurrentRubyThreadIsUsedError error', + quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/432145' do + stub_request(:get, 'http://example.org').to_return(status: 200, body: 'hello world') + + result = described_class.get('http://example.org', async: true) do |_fragment| + User.first + end + + result.execute + result.wait + + expect { result.value }.to raise_error(Gitlab::Utils::ConcurrentRubyThreadIsUsedError, + "Cannot run 'db' if running from `Concurrent::Promise`.") + end + end + end end describe '.try_get' do |