Commit 2d750810 authored by Markus Koller's avatar Markus Koller

Merge branch 'pl-spec-lib-cycle-analytics-events-perf' into 'master'

Speed up cycle analytics events specs

See merge request gitlab-org/gitlab!43291
parents 26165d24 810ea12c
...@@ -942,7 +942,6 @@ Rails/SaveBang: ...@@ -942,7 +942,6 @@ Rails/SaveBang:
- 'spec/lib/gitlab/ci/ansi2json/style_spec.rb' - 'spec/lib/gitlab/ci/ansi2json/style_spec.rb'
- 'spec/lib/gitlab/ci/status/build/common_spec.rb' - 'spec/lib/gitlab/ci/status/build/common_spec.rb'
- 'spec/lib/gitlab/cycle_analytics/base_event_fetcher_spec.rb' - 'spec/lib/gitlab/cycle_analytics/base_event_fetcher_spec.rb'
- 'spec/lib/gitlab/cycle_analytics/events_spec.rb'
- 'spec/lib/gitlab/database/custom_structure_spec.rb' - 'spec/lib/gitlab/database/custom_structure_spec.rb'
- 'spec/lib/gitlab/database/partitioning_migration_helpers/table_management_helpers_spec.rb' - 'spec/lib/gitlab/database/partitioning_migration_helpers/table_management_helpers_spec.rb'
- 'spec/lib/gitlab/database_importers/self_monitoring/project/create_service_spec.rb' - 'spec/lib/gitlab/database_importers/self_monitoring/project/create_service_spec.rb'
......
...@@ -2,16 +2,20 @@ ...@@ -2,16 +2,20 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'cycle analytics events' do RSpec.describe 'cycle analytics events', :aggregate_failures do
let(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user, :admin) }
let(:from_date) { 10.days.ago } let(:from_date) { 10.days.ago }
let(:user) { create(:user, :admin) }
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) } let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
let(:events) do let(:events) do
CycleAnalytics::ProjectLevel.new(project, options: { from: from_date, current_user: user })[stage].events CycleAnalytics::ProjectLevel
.new(project, options: { from: from_date, current_user: user })[stage]
.events
end end
let(:event) { events.first }
before do before do
setup(context) setup(context)
end end
...@@ -19,36 +23,15 @@ RSpec.describe 'cycle analytics events' do ...@@ -19,36 +23,15 @@ RSpec.describe 'cycle analytics events' do
describe '#issue_events' do describe '#issue_events' do
let(:stage) { :issue } let(:stage) { :issue }
it 'has the total time' do it 'has correct attributes' do
expect(events.first[:total_time]).not_to be_empty expect(event[:total_time]).not_to be_empty
end expect(event[:title]).to eq(context.title)
expect(event[:url]).not_to be_nil
it 'has a title' do expect(event[:iid]).to eq(context.iid.to_s)
expect(events.first[:title]).to eq(context.title) expect(event[:created_at]).to end_with('ago')
end expect(event[:author][:web_url]).not_to be_nil
expect(event[:author][:avatar_url]).not_to be_nil
it 'has the URL' do expect(event[:author][:name]).to eq(context.author.name)
expect(events.first[:url]).not_to be_nil
end
it 'has an iid' do
expect(events.first[:iid]).to eq(context.iid.to_s)
end
it 'has a created_at timestamp' do
expect(events.first[:created_at]).to end_with('ago')
end
it "has the author's URL" do
expect(events.first[:author][:web_url]).not_to be_nil
end
it "has the author's avatar URL" do
expect(events.first[:author][:avatar_url]).not_to be_nil
end
it "has the author's name" do
expect(events.first[:author][:name]).to eq(context.author.name)
end end
end end
...@@ -59,36 +42,15 @@ RSpec.describe 'cycle analytics events' do ...@@ -59,36 +42,15 @@ RSpec.describe 'cycle analytics events' do
create_commit_referencing_issue(context) create_commit_referencing_issue(context)
end end
it 'has the total time' do it 'has correct attributes' do
expect(events.first[:total_time]).not_to be_empty expect(event[:total_time]).not_to be_empty
end expect(event[:title]).to eq(context.title)
expect(event[:url]).not_to be_nil
it 'has a title' do expect(event[:iid]).to eq(context.iid.to_s)
expect(events.first[:title]).to eq(context.title) expect(event[:created_at]).to end_with('ago')
end expect(event[:author][:web_url]).not_to be_nil
expect(event[:author][:avatar_url]).not_to be_nil
it 'has the URL' do expect(event[:author][:name]).to eq(context.author.name)
expect(events.first[:url]).not_to be_nil
end
it 'has an iid' do
expect(events.first[:iid]).to eq(context.iid.to_s)
end
it 'has a created_at timestamp' do
expect(events.first[:created_at]).to end_with('ago')
end
it "has the author's URL" do
expect(events.first[:author][:web_url]).not_to be_nil
end
it "has the author's avatar URL" do
expect(events.first[:author][:avatar_url]).not_to be_nil
end
it "has the author's name" do
expect(events.first[:author][:name]).to eq(context.author.name)
end end
end end
...@@ -100,32 +62,14 @@ RSpec.describe 'cycle analytics events' do ...@@ -100,32 +62,14 @@ RSpec.describe 'cycle analytics events' do
create_commit_referencing_issue(context) create_commit_referencing_issue(context)
end end
it 'has the total time' do it 'has correct attributes' do
expect(events.first[:total_time]).not_to be_empty expect(event[:total_time]).not_to be_empty
end expect(event[:title]).to eq('Awesome merge_request')
expect(event[:iid]).to eq(context.iid.to_s)
it 'has a title' do expect(event[:created_at]).to end_with('ago')
expect(events.first[:title]).to eq('Awesome merge_request') expect(event[:author][:web_url]).not_to be_nil
end expect(event[:author][:avatar_url]).not_to be_nil
expect(event[:author][:name]).to eq(MergeRequest.first.author.name)
it 'has an iid' do
expect(events.first[:iid]).to eq(context.iid.to_s)
end
it 'has a created_at timestamp' do
expect(events.first[:created_at]).to end_with('ago')
end
it "has the author's URL" do
expect(events.first[:author][:web_url]).not_to be_nil
end
it "has the author's avatar URL" do
expect(events.first[:author][:avatar_url]).not_to be_nil
end
it "has the author's name" do
expect(events.first[:author][:name]).to eq(MergeRequest.first.author.name)
end end
end end
...@@ -152,40 +96,16 @@ RSpec.describe 'cycle analytics events' do ...@@ -152,40 +96,16 @@ RSpec.describe 'cycle analytics events' do
merge_merge_requests_closing_issue(user, project, context) merge_merge_requests_closing_issue(user, project, context)
end end
it 'has the name' do it 'has correct attributes' do
expect(events.first[:name]).not_to be_nil expect(event[:name]).not_to be_nil
end expect(event[:id]).not_to be_nil
expect(event[:url]).not_to be_nil
it 'has the ID' do expect(event[:branch]).not_to be_nil
expect(events.first[:id]).not_to be_nil expect(event[:branch][:url]).not_to be_nil
end expect(event[:short_sha]).not_to be_nil
expect(event[:commit_url]).not_to be_nil
it 'has the URL' do expect(event[:date]).not_to be_nil
expect(events.first[:url]).not_to be_nil expect(event[:total_time]).not_to be_empty
end
it 'has the branch name' do
expect(events.first[:branch]).not_to be_nil
end
it 'has the branch URL' do
expect(events.first[:branch][:url]).not_to be_nil
end
it 'has the short SHA' do
expect(events.first[:short_sha]).not_to be_nil
end
it 'has the commit URL' do
expect(events.first[:commit_url]).not_to be_nil
end
it 'has the date' do
expect(events.first[:date]).not_to be_nil
end
it 'has the total time' do
expect(events.first[:total_time]).not_to be_empty
end end
end end
...@@ -197,40 +117,16 @@ RSpec.describe 'cycle analytics events' do ...@@ -197,40 +117,16 @@ RSpec.describe 'cycle analytics events' do
merge_merge_requests_closing_issue(user, project, context) merge_merge_requests_closing_issue(user, project, context)
end end
it 'has the total time' do it 'has correct attributes' do
expect(events.first[:total_time]).not_to be_empty expect(event[:total_time]).not_to be_empty
end expect(event[:title]).to eq('Awesome merge_request')
expect(event[:iid]).to eq(context.iid.to_s)
it 'has a title' do expect(event[:url]).not_to be_nil
expect(events.first[:title]).to eq('Awesome merge_request') expect(event[:state]).not_to be_nil
end expect(event[:created_at]).not_to be_nil
expect(event[:author][:web_url]).not_to be_nil
it 'has an iid' do expect(event[:author][:avatar_url]).not_to be_nil
expect(events.first[:iid]).to eq(context.iid.to_s) expect(event[:author][:name]).to eq(MergeRequest.first.author.name)
end
it 'has the URL' do
expect(events.first[:url]).not_to be_nil
end
it 'has a state' do
expect(events.first[:state]).not_to be_nil
end
it 'has a created_at timestamp' do
expect(events.first[:created_at]).not_to be_nil
end
it "has the author's URL" do
expect(events.first[:author][:web_url]).not_to be_nil
end
it "has the author's avatar URL" do
expect(events.first[:author][:avatar_url]).not_to be_nil
end
it "has the author's name" do
expect(events.first[:author][:name]).to eq(MergeRequest.first.author.name)
end end
end end
...@@ -257,58 +153,25 @@ RSpec.describe 'cycle analytics events' do ...@@ -257,58 +153,25 @@ RSpec.describe 'cycle analytics events' do
deploy_master(user, project) deploy_master(user, project)
end end
it 'has the name' do it 'has correct attributes' do
expect(events.first[:name]).not_to be_nil expect(event[:name]).not_to be_nil
end expect(event[:id]).not_to be_nil
expect(event[:url]).not_to be_nil
it 'has the ID' do expect(event[:branch]).not_to be_nil
expect(events.first[:id]).not_to be_nil expect(event[:branch][:url]).not_to be_nil
end expect(event[:short_sha]).not_to be_nil
expect(event[:commit_url]).not_to be_nil
it 'has the URL' do expect(event[:date]).not_to be_nil
expect(events.first[:url]).not_to be_nil expect(event[:total_time]).not_to be_empty
end expect(event[:author][:web_url]).not_to be_nil
expect(event[:author][:avatar_url]).not_to be_nil
it 'has the branch name' do expect(event[:author][:name]).to eq(MergeRequest.first.author.name)
expect(events.first[:branch]).not_to be_nil
end
it 'has the branch URL' do
expect(events.first[:branch][:url]).not_to be_nil
end
it 'has the short SHA' do
expect(events.first[:short_sha]).not_to be_nil
end
it 'has the commit URL' do
expect(events.first[:commit_url]).not_to be_nil
end
it 'has the date' do
expect(events.first[:date]).not_to be_nil
end
it 'has the total time' do
expect(events.first[:total_time]).not_to be_empty
end
it "has the author's URL" do
expect(events.first[:author][:web_url]).not_to be_nil
end
it "has the author's avatar URL" do
expect(events.first[:author][:avatar_url]).not_to be_nil
end
it "has the author's name" do
expect(events.first[:author][:name]).to eq(MergeRequest.first.author.name)
end end
end end
def setup(context) def setup(context)
milestone = create(:milestone, project: project) milestone = create(:milestone, project: project)
context.update(milestone: milestone) context.update!(milestone: milestone)
mr = create_merge_request_closing_issue(user, project, context, commit_message: "References #{context.to_reference}") mr = create_merge_request_closing_issue(user, project, context, commit_message: "References #{context.to_reference}")
ProcessCommitWorker.new.perform(project.id, user.id, mr.commits.last.to_hash) ProcessCommitWorker.new.perform(project.id, user.id, mr.commits.last.to_hash)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment