diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-11 00:06:01 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-11 00:06:01 +0300 |
commit | f607152a0802a68067343ad73f989033cb8e9a06 (patch) | |
tree | bbc16fd5f827ea5e30527d455a01dd6b1249a19c /spec/lib/gitlab/cycle_analytics | |
parent | 7c862041c66833ebf49d9964f1797d93b1829690 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/cycle_analytics')
5 files changed, 57 insertions, 7 deletions
diff --git a/spec/lib/gitlab/cycle_analytics/code_stage_spec.rb b/spec/lib/gitlab/cycle_analytics/code_stage_spec.rb index 6959778661b..aa12bc21d22 100644 --- a/spec/lib/gitlab/cycle_analytics/code_stage_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/code_stage_spec.rb @@ -26,6 +26,13 @@ describe Gitlab::CycleAnalytics::CodeStage do it_behaves_like 'base stage' + context 'when using the new query backend' do + include_examples 'Gitlab::Analytics::CycleAnalytics::DataCollector backend examples' do + let(:expected_record_count) { 2 } + let(:expected_ordered_attribute_values) { [mr_2.title, mr_1.title] } + end + end + describe '#project_median' do around do |example| Timecop.freeze { example.run } diff --git a/spec/lib/gitlab/cycle_analytics/issue_stage_spec.rb b/spec/lib/gitlab/cycle_analytics/issue_stage_spec.rb index b99debf8cac..497db88d850 100644 --- a/spec/lib/gitlab/cycle_analytics/issue_stage_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/issue_stage_spec.rb @@ -21,6 +21,13 @@ describe Gitlab::CycleAnalytics::IssueStage do it_behaves_like 'base stage' + context 'when using the new query backend' do + include_examples 'Gitlab::Analytics::CycleAnalytics::DataCollector backend examples' do + let(:expected_record_count) { 3 } + let(:expected_ordered_attribute_values) { [issue_3.title, issue_2.title, issue_1.title] } + end + end + describe '#median' do around do |example| Timecop.freeze { example.run } diff --git a/spec/lib/gitlab/cycle_analytics/plan_stage_spec.rb b/spec/lib/gitlab/cycle_analytics/plan_stage_spec.rb index 60d180015c4..01a46f5ba65 100644 --- a/spec/lib/gitlab/cycle_analytics/plan_stage_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/plan_stage_spec.rb @@ -21,6 +21,13 @@ describe Gitlab::CycleAnalytics::PlanStage do it_behaves_like 'base stage' + context 'when using the new query backend' do + include_examples 'Gitlab::Analytics::CycleAnalytics::DataCollector backend examples' do + let(:expected_record_count) { 2 } + let(:expected_ordered_attribute_values) { [issue_1.title, issue_2.title] } + end + end + describe '#project_median' do around do |example| Timecop.freeze { example.run } diff --git a/spec/lib/gitlab/cycle_analytics/shared_stage_spec.rb b/spec/lib/gitlab/cycle_analytics/shared_stage_spec.rb index b3a6c2c4239..c5b17aafdd2 100644 --- a/spec/lib/gitlab/cycle_analytics/shared_stage_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/shared_stage_spec.rb @@ -52,3 +52,21 @@ shared_examples 'calculate #median with date range' do it { expect(stage.project_median).to eq(nil) } end end + +shared_examples 'Gitlab::Analytics::CycleAnalytics::DataCollector backend examples' do + let(:stage_params) { Gitlab::Analytics::CycleAnalytics::DefaultStages.send("params_for_#{stage_name}_stage").merge(project: project) } + let(:stage) { Analytics::CycleAnalytics::ProjectStage.new(stage_params) } + let(:data_collector) { Gitlab::Analytics::CycleAnalytics::DataCollector.new(stage: stage, params: { from: stage_options[:from], current_user: project.creator }) } + let(:attribute_to_verify) { :title } + + context 'provides the same results as the old implementation' do + it 'for the median' do + expect(data_collector.median.seconds).to eq(ISSUES_MEDIAN) + end + + it 'for the list of event records' do + records = data_collector.records_fetcher.serialized_records + expect(records.map { |event| event[attribute_to_verify] }).to eq(expected_ordered_attribute_values) + end + end +end diff --git a/spec/lib/gitlab/cycle_analytics/test_stage_spec.rb b/spec/lib/gitlab/cycle_analytics/test_stage_spec.rb index bbb53cefae7..e347f36dfce 100644 --- a/spec/lib/gitlab/cycle_analytics/test_stage_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/test_stage_spec.rb @@ -12,17 +12,20 @@ describe Gitlab::CycleAnalytics::TestStage do it_behaves_like 'base stage' describe '#median' do + let(:mr_1) { create(:merge_request, :closed, source_project: project, created_at: 60.minutes.ago) } + let(:mr_2) { create(:merge_request, :closed, source_project: project, created_at: 40.minutes.ago, source_branch: 'A') } + let(:mr_3) { create(:merge_request, source_project: project, created_at: 10.minutes.ago, source_branch: 'B') } + let(:mr_4) { create(:merge_request, source_project: project, created_at: 10.minutes.ago, source_branch: 'C') } + let(:mr_5) { create(:merge_request, source_project: project, created_at: 10.minutes.ago, source_branch: 'D') } + let(:ci_build1) { create(:ci_build, project: project) } + let(:ci_build2) { create(:ci_build, project: project) } + before do issue_1 = create(:issue, project: project, created_at: 90.minutes.ago) issue_2 = create(:issue, project: project, created_at: 60.minutes.ago) issue_3 = create(:issue, project: project, created_at: 60.minutes.ago) - mr_1 = create(:merge_request, :closed, source_project: project, created_at: 60.minutes.ago) - mr_2 = create(:merge_request, :closed, source_project: project, created_at: 40.minutes.ago, source_branch: 'A') - mr_3 = create(:merge_request, source_project: project, created_at: 10.minutes.ago, source_branch: 'B') - mr_4 = create(:merge_request, source_project: project, created_at: 10.minutes.ago, source_branch: 'C') - mr_5 = create(:merge_request, source_project: project, created_at: 10.minutes.ago, source_branch: 'D') - mr_1.metrics.update!(latest_build_started_at: 32.minutes.ago, latest_build_finished_at: 2.minutes.ago) - mr_2.metrics.update!(latest_build_started_at: 62.minutes.ago, latest_build_finished_at: 32.minutes.ago) + mr_1.metrics.update!(latest_build_started_at: 32.minutes.ago, latest_build_finished_at: 2.minutes.ago, pipeline_id: ci_build1.commit_id) + mr_2.metrics.update!(latest_build_started_at: 62.minutes.ago, latest_build_finished_at: 32.minutes.ago, pipeline_id: ci_build2.commit_id) mr_3.metrics.update!(latest_build_started_at: nil, latest_build_finished_at: nil) mr_4.metrics.update!(latest_build_started_at: nil, latest_build_finished_at: nil) mr_5.metrics.update!(latest_build_started_at: nil, latest_build_finished_at: nil) @@ -43,5 +46,13 @@ describe Gitlab::CycleAnalytics::TestStage do end include_examples 'calculate #median with date range' + + context 'when using the new query backend' do + include_examples 'Gitlab::Analytics::CycleAnalytics::DataCollector backend examples' do + let(:expected_record_count) { 2 } + let(:attribute_to_verify) { :id } + let(:expected_ordered_attribute_values) { [mr_1.metrics.pipeline.builds.first.id, mr_2.metrics.pipeline.builds.first.id] } + end + end end end |