diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-08 15:09:18 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-08 15:09:18 +0300 |
commit | cca8451493930537fcd14f50642599b94e13ce09 (patch) | |
tree | 3e7474f15cb67764a49becbc2dc0efe05c35c3b6 /spec | |
parent | 9ce920f62f1cb0471763bfe95874de421881e366 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/projects_spec.rb | 1 | ||||
-rw-r--r-- | spec/frontend/lib/utils/datetime_utility_spec.js | 56 | ||||
-rw-r--r-- | spec/frontend/performance_bar/components/detailed_metric_spec.js | 67 | ||||
-rw-r--r-- | spec/lib/gitlab/gitaly_client/call_spec.rb | 13 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/subscribers/external_http_spec.rb | 57 | ||||
-rw-r--r-- | spec/lib/peek/views/external_http_spec.rb | 33 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 23 | ||||
-rw-r--r-- | spec/spec_helper.rb | 5 |
8 files changed, 164 insertions, 91 deletions
diff --git a/spec/features/projects_spec.rb b/spec/features/projects_spec.rb index 34601cab24f..4730679feb8 100644 --- a/spec/features/projects_spec.rb +++ b/spec/features/projects_spec.rb @@ -290,7 +290,6 @@ RSpec.describe 'Project' do let(:project) { create(:forked_project_with_submodules) } before do - stub_feature_flags(refactor_blob_viewer: false) project.add_maintainer(user) sign_in user visit project_path(project) diff --git a/spec/frontend/lib/utils/datetime_utility_spec.js b/spec/frontend/lib/utils/datetime_utility_spec.js index 2df0cb00f9a..2a226ca8ade 100644 --- a/spec/frontend/lib/utils/datetime_utility_spec.js +++ b/spec/frontend/lib/utils/datetime_utility_spec.js @@ -966,62 +966,6 @@ describe('format24HourTimeStringFromInt', () => { }); }); -describe('getOverlapDateInPeriods', () => { - const start = new Date(2021, 0, 11); - const end = new Date(2021, 0, 13); - - describe('when date periods overlap', () => { - const givenPeriodLeft = new Date(2021, 0, 11); - const givenPeriodRight = new Date(2021, 0, 14); - - it('returns an overlap object that contains the amount of days overlapping, the amount of hours overlapping, start date of overlap and end date of overlap', () => { - expect( - datetimeUtility.getOverlapDateInPeriods( - { start, end }, - { start: givenPeriodLeft, end: givenPeriodRight }, - ), - ).toEqual({ - daysOverlap: 2, - hoursOverlap: 48, - overlapStartDate: givenPeriodLeft.getTime(), - overlapEndDate: end.getTime(), - }); - }); - }); - - describe('when date periods do not overlap', () => { - const givenPeriodLeft = new Date(2021, 0, 9); - const givenPeriodRight = new Date(2021, 0, 10); - - it('returns an overlap object that contains a 0 value for days overlapping', () => { - expect( - datetimeUtility.getOverlapDateInPeriods( - { start, end }, - { start: givenPeriodLeft, end: givenPeriodRight }, - ), - ).toEqual({ daysOverlap: 0 }); - }); - }); - - describe('when date periods contain an invalid Date', () => { - const startInvalid = new Date(NaN); - const endInvalid = new Date(NaN); - const error = __('Invalid period'); - - it('throws an exception when the left period contains an invalid date', () => { - expect(() => - datetimeUtility.getOverlapDateInPeriods({ start, end }, { start: startInvalid, end }), - ).toThrow(error); - }); - - it('throws an exception when the right period contains an invalid date', () => { - expect(() => - datetimeUtility.getOverlapDateInPeriods({ start, end }, { start, end: endInvalid }), - ).toThrow(error); - }); - }); -}); - describe('isToday', () => { const today = new Date(); it.each` diff --git a/spec/frontend/performance_bar/components/detailed_metric_spec.js b/spec/frontend/performance_bar/components/detailed_metric_spec.js index a58712f2fec..c35bd772c86 100644 --- a/spec/frontend/performance_bar/components/detailed_metric_spec.js +++ b/spec/frontend/performance_bar/components/detailed_metric_spec.js @@ -120,6 +120,73 @@ describe('detailedMetric', () => { }); }); + describe('when the details have summaryOptions option', () => { + const gitalyDetails = { + duration: '123ms', + calls: 456, + details: requestDetails, + warnings: ['gitaly calls: 456 over 30'], + }; + + describe('when the details have summaryOptions > hideTotal option', () => { + beforeEach(() => { + createComponent({ + currentRequest: { + details: { + gitaly: { ...gitalyDetails, summaryOptions: { hideTotal: true } }, + }, + }, + }); + }); + + it('displays a summary section', () => { + expect(findAllSummaryItems()).toEqual(['Total duration 123ms']); + }); + }); + + describe('when the details have summaryOptions > hideDuration option', () => { + beforeEach(() => { + createComponent({ + currentRequest: { + details: { + gitaly: { ...gitalyDetails, summaryOptions: { hideDuration: true } }, + }, + }, + }); + }); + + it('displays a summary section', () => { + expect(findAllSummaryItems()).toEqual(['Total 456']); + }); + }); + + describe('when the details have both summary and summaryOptions field', () => { + beforeEach(() => { + createComponent({ + currentRequest: { + details: { + gitaly: { + ...gitalyDetails, + summary: { + 'In controllers': 100, + 'In middlewares': 20, + }, + summaryOptions: { + hideDuration: true, + hideTotal: true, + }, + }, + }, + }, + }); + }); + + it('displays a summary section', () => { + expect(findAllSummaryItems()).toEqual(['In controllers 100', 'In middlewares 20']); + }); + }); + }); + describe("when the details don't have a start field", () => { beforeEach(() => { createComponent({ diff --git a/spec/lib/gitlab/gitaly_client/call_spec.rb b/spec/lib/gitlab/gitaly_client/call_spec.rb index 5c33ac40460..099307fc4e1 100644 --- a/spec/lib/gitlab/gitaly_client/call_spec.rb +++ b/spec/lib/gitlab/gitaly_client/call_spec.rb @@ -24,11 +24,14 @@ RSpec.describe Gitlab::GitalyClient::Call do def expect_call_details_to_match(duration_higher_than: 0) expect(client.list_call_details.size).to eq(1) expect(client.list_call_details.first) - .to match a_hash_including(feature: "#{service}##{rpc}", - duration: a_value > duration_higher_than, - request: an_instance_of(Hash), - rpc: rpc, - backtrace: an_instance_of(Array)) + .to match a_hash_including( + start: a_value > 0, + feature: "#{service}##{rpc}", + duration: a_value > duration_higher_than, + request: an_instance_of(Hash), + rpc: rpc, + backtrace: an_instance_of(Array) + ) end context 'when the response is not an enumerator' do diff --git a/spec/lib/gitlab/metrics/subscribers/external_http_spec.rb b/spec/lib/gitlab/metrics/subscribers/external_http_spec.rb index 5bcaf8fbc47..adbc05cb711 100644 --- a/spec/lib/gitlab/metrics/subscribers/external_http_spec.rb +++ b/spec/lib/gitlab/metrics/subscribers/external_http_spec.rb @@ -6,29 +6,45 @@ RSpec.describe Gitlab::Metrics::Subscribers::ExternalHttp, :request_store do let(:transaction) { Gitlab::Metrics::Transaction.new } let(:subscriber) { described_class.new } + around do |example| + freeze_time { example.run } + end + let(:event_1) do - double(:event, payload: { - method: 'POST', code: "200", duration: 0.321, - scheme: 'https', host: 'gitlab.com', port: 80, path: '/api/v4/projects', - query: 'current=true' - }) + double( + :event, + payload: { + method: 'POST', code: "200", duration: 0.321, + scheme: 'https', host: 'gitlab.com', port: 80, path: '/api/v4/projects', + query: 'current=true' + }, + time: Time.current + ) end let(:event_2) do - double(:event, payload: { - method: 'GET', code: "301", duration: 0.12, - scheme: 'http', host: 'gitlab.com', port: 80, path: '/api/v4/projects/2', - query: 'current=true' - }) + double( + :event, + payload: { + method: 'GET', code: "301", duration: 0.12, + scheme: 'http', host: 'gitlab.com', port: 80, path: '/api/v4/projects/2', + query: 'current=true' + }, + time: Time.current + ) end let(:event_3) do - double(:event, payload: { - method: 'POST', duration: 5.3, - scheme: 'http', host: 'gitlab.com', port: 80, path: '/api/v4/projects/2/issues', - query: 'current=true', - exception_object: Net::ReadTimeout.new - }) + double( + :event, + payload: { + method: 'POST', duration: 5.3, + scheme: 'http', host: 'gitlab.com', port: 80, path: '/api/v4/projects/2/issues', + query: 'current=true', + exception_object: Net::ReadTimeout.new + }, + time: Time.current + ) end describe '.detail_store' do @@ -134,19 +150,22 @@ RSpec.describe Gitlab::Metrics::Subscribers::ExternalHttp, :request_store do subscriber.request(event_3) expect(Gitlab::SafeRequestStore[:external_http_detail_store].length).to eq(3) - expect(Gitlab::SafeRequestStore[:external_http_detail_store][0]).to include( + expect(Gitlab::SafeRequestStore[:external_http_detail_store][0]).to match a_hash_including( + start: be_like_time(Time.current), method: 'POST', code: "200", duration: 0.321, scheme: 'https', host: 'gitlab.com', port: 80, path: '/api/v4/projects', query: 'current=true', exception_object: nil, backtrace: be_a(Array) ) - expect(Gitlab::SafeRequestStore[:external_http_detail_store][1]).to include( + expect(Gitlab::SafeRequestStore[:external_http_detail_store][1]).to match a_hash_including( + start: be_like_time(Time.current), method: 'GET', code: "301", duration: 0.12, scheme: 'http', host: 'gitlab.com', port: 80, path: '/api/v4/projects/2', query: 'current=true', exception_object: nil, backtrace: be_a(Array) ) - expect(Gitlab::SafeRequestStore[:external_http_detail_store][2]).to include( + expect(Gitlab::SafeRequestStore[:external_http_detail_store][2]).to match a_hash_including( + start: be_like_time(Time.current), method: 'POST', duration: 5.3, scheme: 'http', host: 'gitlab.com', port: 80, path: '/api/v4/projects/2/issues', query: 'current=true', diff --git a/spec/lib/peek/views/external_http_spec.rb b/spec/lib/peek/views/external_http_spec.rb index 98c4f771f33..18ae1326493 100644 --- a/spec/lib/peek/views/external_http_spec.rb +++ b/spec/lib/peek/views/external_http_spec.rb @@ -11,6 +11,10 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do allow(Gitlab::PerformanceBar).to receive(:enabled_for_request?).and_return(true) end + around do |example| + freeze_time { example.run } + end + let(:event_1) do { method: 'POST', code: "200", duration: 0.03, @@ -44,9 +48,9 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do end it 'returns aggregated results' do - subscriber.request(double(:event, payload: event_1)) - subscriber.request(double(:event, payload: event_2)) - subscriber.request(double(:event, payload: event_3)) + subscriber.request(double(:event, payload: event_1, time: Time.current)) + subscriber.request(double(:event, payload: event_2, time: Time.current)) + subscriber.request(double(:event, payload: event_3, time: Time.current)) results = subject.results expect(results[:calls]).to eq(3) @@ -55,6 +59,7 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do expected = [ { + start: be_like_time(Time.current), duration: 30.0, label: "POST https://gitlab.com:80/api/v4/projects?current=true", code: "Response status: 200", @@ -63,6 +68,7 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do warnings: [] }, { + start: be_like_time(Time.current), duration: 1300, label: "POST http://gitlab.com:80/api/v4/projects/2/issues?current=true", code: nil, @@ -71,6 +77,7 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do warnings: ["1300.0 over 100"] }, { + start: be_like_time(Time.current), duration: 5.0, label: "GET http://gitlab.com:80/api/v4/projects/2?current=true", code: "Response status: 301", @@ -81,7 +88,7 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do ] expect( - results[:details].map { |data| data.slice(:duration, :label, :code, :proxy, :error, :warnings) } + results[:details].map { |data| data.slice(:start, :duration, :label, :code, :proxy, :error, :warnings) } ).to match_array(expected) end @@ -91,10 +98,11 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do end it 'displays IPv4 in the label' do - subscriber.request(double(:event, payload: event_1)) + subscriber.request(double(:event, payload: event_1, time: Time.current)) expect(subject.results[:details]).to contain_exactly( a_hash_including( + start: be_like_time(Time.current), duration: 30.0, label: "POST https://1.2.3.4:80/api/v4/projects?current=true", code: "Response status: 200", @@ -112,10 +120,11 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do end it 'displays IPv6 in the label' do - subscriber.request(double(:event, payload: event_1)) + subscriber.request(double(:event, payload: event_1, time: Time.current)) expect(subject.results[:details]).to contain_exactly( a_hash_including( + start: be_like_time(Time.current), duration: 30.0, label: "POST https://[2606:4700:90:0:f22e:fbec:5bed:a9b9]:80/api/v4/projects?current=true", code: "Response status: 200", @@ -133,10 +142,11 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do end it 'converts query hash into a query string' do - subscriber.request(double(:event, payload: event_1)) + subscriber.request(double(:event, payload: event_1, time: Time.current)) expect(subject.results[:details]).to contain_exactly( a_hash_including( + start: be_like_time(Time.current), duration: 30.0, label: "POST https://gitlab.com:80/api/v4/projects?current=true&item1=string&item2%5B%5D=1&item2%5B%5D=2", code: "Response status: 200", @@ -154,10 +164,11 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do end it 'displays unknown in the label' do - subscriber.request(double(:event, payload: event_1)) + subscriber.request(double(:event, payload: event_1, time: Time.current)) expect(subject.results[:details]).to contain_exactly( a_hash_including( + start: be_like_time(Time.current), duration: 30.0, label: "POST unknown", code: "Response status: 200", @@ -176,10 +187,11 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do end it 'displays unknown in the label' do - subscriber.request(double(:event, payload: event_1)) + subscriber.request(double(:event, payload: event_1, time: Time.current)) expect(subject.results[:details]).to contain_exactly( a_hash_including( + start: be_like_time(Time.current), duration: 30.0, label: "POST unknown", code: "Response status: 200", @@ -198,10 +210,11 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do end it 'displays unknown in the label' do - subscriber.request(double(:event, payload: event_1)) + subscriber.request(double(:event, payload: event_1, time: Time.current)) expect(subject.results[:details]).to contain_exactly( a_hash_including( + start: be_like_time(Time.current), duration: 30.0, label: "POST unknown", code: "Response status: 200", diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 1850363bb72..0a63f1d7fa0 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -835,6 +835,29 @@ RSpec.describe API::Projects do end.not_to exceed_query_limit(control.count) end end + + context 'when service desk is enabled', :use_clean_rails_memory_store_caching do + let_it_be(:admin) { create(:admin) } + + it 'avoids N+1 queries' do + allow(Gitlab::ServiceDeskEmail).to receive(:enabled?).and_return(true) + allow(Gitlab::IncomingEmail).to receive(:enabled?).and_return(true) + + get api('/projects', admin) + + create(:project, :public, :service_desk_enabled, namespace: admin.namespace) + + control = ActiveRecord::QueryRecorder.new do + get api('/projects', admin) + end + + create_list(:project, 2, :public, :service_desk_enabled, namespace: admin.namespace) + + expect do + get api('/projects', admin) + end.not_to exceed_query_limit(control.count) + end + end end describe 'POST /projects' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a3925a0c0fb..1550e2f9b3b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -277,6 +277,11 @@ RSpec.configure do |config| # Vue issues page has feature parity with the current Haml page stub_feature_flags(vue_issues_list: false) + # Disable `refactor_blob_viewer` as we refactor + # the blob viewer. See the follwing epic for more: + # https://gitlab.com/groups/gitlab-org/-/epics/5531 + stub_feature_flags(refactor_blob_viewer: false) + allow(Gitlab::GitalyClient).to receive(:can_use_disk?).and_return(enable_rugged) else unstub_all_feature_flags |