diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-12 09:10:10 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-12 09:10:10 +0300 |
commit | b684feb6c8dc322efb73d1e0473bcd3f37e08d34 (patch) | |
tree | 2ddb117609e4bb246758acfad58fc02d9da06504 /spec | |
parent | e6de69cc2eae87536ed97df4dee36980583010f5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
5 files changed, 122 insertions, 13 deletions
diff --git a/spec/factories/work_item/work_item_types.rb b/spec/factories/work_item/work_item_types.rb index 9f507844d76..07d6d685c57 100644 --- a/spec/factories/work_item/work_item_types.rb +++ b/spec/factories/work_item/work_item_types.rb @@ -5,11 +5,26 @@ FactoryBot.define do namespace name { generate(:work_item_type_name) } - icon_name { 'issue' } - base_type { Issue.issue_types['issue'] } + base_type { WorkItem::Type.base_types[:issue] } + icon_name { 'issue-type-issue' } trait :default do namespace { nil } end + + trait :incident do + base_type { WorkItem::Type.base_types[:incident] } + icon_name { 'issue-type-incident' } + end + + trait :test_case do + base_type { WorkItem::Type.base_types[:test_case] } + icon_name { 'issue-type-test-case' } + end + + trait :requirement do + base_type { WorkItem::Type.base_types[:requirement] } + icon_name { 'issue-type-requirements' } + end end end diff --git a/spec/lib/gitlab/http_spec.rb b/spec/lib/gitlab/http_spec.rb index 71e80de9f89..d0aae2ac475 100644 --- a/spec/lib/gitlab/http_spec.rb +++ b/spec/lib/gitlab/http_spec.rb @@ -33,7 +33,7 @@ RSpec.describe Gitlab::HTTP do WebMock.stub_request(:post, /.*/).to_return do |request| sleep 0.002.seconds - { body: 'I\m slow', status: 200 } + { body: 'I\'m slow', status: 200 } end end @@ -41,25 +41,67 @@ RSpec.describe Gitlab::HTTP do subject(:request_slow_responder) { described_class.post('http://example.org', **options) } - specify do - expect { request_slow_responder }.not_to raise_error + shared_examples 'tracks the timeout but does not raise an error' do + specify :aggregate_failures do + expect(Gitlab::ErrorTracking).to receive(:track_exception).with( + an_instance_of(Gitlab::HTTP::ReadTotalTimeout) + ).once + + expect { request_slow_responder }.not_to raise_error + end + + it 'still calls the block' do + expect { |b| described_class.post('http://example.org', **options, &b) }.to yield_with_args + end end - context 'with use_read_total_timeout option' do + shared_examples 'does not track or raise timeout error' do + specify :aggregate_failures do + expect(Gitlab::ErrorTracking).not_to receive(:track_exception) + + expect { request_slow_responder }.not_to raise_error + end + end + + it_behaves_like 'tracks the timeout but does not raise an error' + + context 'and use_read_total_timeout option is truthy' do let(:options) { { use_read_total_timeout: true } } - it 'raises a timeout error' do + it 'raises an error' do expect { request_slow_responder }.to raise_error(Gitlab::HTTP::ReadTotalTimeout, /Request timed out after ?([0-9]*[.])?[0-9]+ seconds/) end + end - context 'and timeout option' do - let(:options) { { use_read_total_timeout: true, timeout: 10.seconds } } + context 'and timeout option is greater than DEFAULT_READ_TOTAL_TIMEOUT' do + let(:options) { { timeout: 10.seconds } } - it 'overrides the default timeout when timeout option is present' do - expect { request_slow_responder }.not_to raise_error - end + it_behaves_like 'does not track or raise timeout error' + end + + context 'and stream_body option is truthy' do + let(:options) { { stream_body: true } } + + it_behaves_like 'does not track or raise timeout error' + + context 'but skip_read_total_timeout option is falsey' do + let(:options) { { stream_body: true, skip_read_total_timeout: false } } + + it_behaves_like 'tracks the timeout but does not raise an error' end end + + context 'and skip_read_total_timeout option is truthy' do + let(:options) { { skip_read_total_timeout: true } } + + it_behaves_like 'does not track or raise timeout error' + end + + context 'and skip_read_total_timeout option is falsely' do + let(:options) { { skip_read_total_timeout: false } } + + it_behaves_like 'tracks the timeout but does not raise an error' + end end it 'calls a block' do diff --git a/spec/migrations/20210804150320_create_base_work_item_types_spec.rb b/spec/migrations/20210804150320_create_base_work_item_types_spec.rb new file mode 100644 index 00000000000..535472f5931 --- /dev/null +++ b/spec/migrations/20210804150320_create_base_work_item_types_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration!('create_base_work_item_types') + +RSpec.describe CreateBaseWorkItemTypes, :migration do + let!(:work_item_types) { table(:work_item_types) } + + it 'creates default data' do + reversible_migration do |migration| + migration.before -> { + # Depending on whether the migration has been run before, + # the size could be 4, or 0, so we don't set any expectations + } + + migration.after -> { + expect(work_item_types.count).to eq 4 + expect(work_item_types.all.pluck(:base_type)).to match_array WorkItem::Type.base_types.values + } + end + end +end diff --git a/spec/services/dependency_proxy/download_blob_service_spec.rb b/spec/services/dependency_proxy/download_blob_service_spec.rb index 4b5c6b5bd6a..2f293b8a46b 100644 --- a/spec/services/dependency_proxy/download_blob_service_spec.rb +++ b/spec/services/dependency_proxy/download_blob_service_spec.rb @@ -8,7 +8,7 @@ RSpec.describe DependencyProxy::DownloadBlobService do let(:token) { Digest::SHA256.hexdigest('123') } let(:blob_sha) { Digest::SHA256.hexdigest('ruby:2.7.0') } - subject { described_class.new(image, blob_sha, token).execute } + subject(:download_blob) { described_class.new(image, blob_sha, token).execute } context 'remote request is successful' do before do @@ -18,6 +18,21 @@ RSpec.describe DependencyProxy::DownloadBlobService do it { expect(subject[:status]).to eq(:success) } it { expect(subject[:file]).to be_a(Tempfile) } it { expect(subject[:file].size).to eq(6) } + + it 'streams the download' do + expected_options = { headers: anything, stream_body: true } + + expect(Gitlab::HTTP).to receive(:perform_request).with(Net::HTTP::Get, anything, expected_options) + + download_blob + end + + it 'skips read_total_timeout', :aggregate_failures do + stub_const('GitLab::HTTP::DEFAULT_READ_TOTAL_TIMEOUT', 0) + + expect(Gitlab::Metrics::System).not_to receive(:monotonic_time) + expect(download_blob).to include(status: :success) + end end context 'remote request is not found' do diff --git a/spec/services/projects/lfs_pointers/lfs_download_service_spec.rb b/spec/services/projects/lfs_pointers/lfs_download_service_spec.rb index f27ebb2e19e..f9ff959fa05 100644 --- a/spec/services/projects/lfs_pointers/lfs_download_service_spec.rb +++ b/spec/services/projects/lfs_pointers/lfs_download_service_spec.rb @@ -90,6 +90,21 @@ RSpec.describe Projects::LfsPointers::LfsDownloadService do expect(File.binread(LfsObject.first.file.file.file)).to eq lfs_content end + + it 'streams the download' do + expected_options = { headers: anything, stream_body: true } + + expect(Gitlab::HTTP).to receive(:perform_request).with(Net::HTTP::Get, anything, expected_options) + + subject.execute + end + + it 'skips read_total_timeout', :aggregate_failures do + stub_const('GitLab::HTTP::DEFAULT_READ_TOTAL_TIMEOUT', 0) + + expect(Gitlab::Metrics::System).not_to receive(:monotonic_time) + expect(subject.execute).to include(status: :success) + end end context 'when file download fails' do |