diff options
author | Andreas Brandl <abrandl@gitlab.com> | 2019-07-09 12:22:18 +0000 |
---|---|---|
committer | Andreas Brandl <abrandl@gitlab.com> | 2019-07-09 12:22:18 +0000 |
commit | 630a8e80501aff46526086e8f2c72bb846780390 (patch) | |
tree | 98fcd5cbd84a16cc8d0071d2ba1b76b4842f8963 | |
parent | 0f7b5de4195cb3bc82cc9f3d3b08f99fc984e2d7 (diff) | |
parent | 9d2747a6a18561c3186567908323db1ea2d43ff7 (diff) | |
download | gitlab-ce-630a8e80501aff46526086e8f2c72bb846780390.tar.gz |
Merge branch 'fix-median-counting-for-cycle-analytics' into 'master'
Add additional condition to count median properly
See merge request gitlab-org/gitlab-ce!30229
-rw-r--r-- | changelogs/unreleased/fix-median-counting-for-cycle-analytics.yml | 5 | ||||
-rw-r--r-- | lib/gitlab/database/median.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/cycle_analytics/test_stage_spec.rb | 34 |
3 files changed, 40 insertions, 1 deletions
diff --git a/changelogs/unreleased/fix-median-counting-for-cycle-analytics.yml b/changelogs/unreleased/fix-median-counting-for-cycle-analytics.yml new file mode 100644 index 00000000000..6ae6db08ba1 --- /dev/null +++ b/changelogs/unreleased/fix-median-counting-for-cycle-analytics.yml @@ -0,0 +1,5 @@ +--- +title: Fix median counting for cycle analytics +merge_request: 30229 +author: +type: fixed diff --git a/lib/gitlab/database/median.rb b/lib/gitlab/database/median.rb index 1455e410d4b..b8d895dee7d 100644 --- a/lib/gitlab/database/median.rb +++ b/lib/gitlab/database/median.rb @@ -158,7 +158,7 @@ module Gitlab Arel::Nodes::Window.new.order(arel_table[column_sym]) ).as('row_id') - count = arel_table.project("COUNT(1)").as('ct') + count = arel_table.where(arel_table[column_sym].gteq(zero_interval)).project("COUNT(1)").as('ct') [column_row, row_id, count] end diff --git a/spec/lib/gitlab/cycle_analytics/test_stage_spec.rb b/spec/lib/gitlab/cycle_analytics/test_stage_spec.rb index eacde22cd56..8633a63849f 100644 --- a/spec/lib/gitlab/cycle_analytics/test_stage_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/test_stage_spec.rb @@ -3,6 +3,40 @@ require 'lib/gitlab/cycle_analytics/shared_stage_spec' describe Gitlab::CycleAnalytics::TestStage do let(:stage_name) { :test } + let(:project) { create(:project) } + let(:stage) { described_class.new(project: project, options: { from: 2.days.ago, current_user: project.creator }) } it_behaves_like 'base stage' + + describe '#median' do + 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_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) + + create(:merge_requests_closing_issues, merge_request: mr_1, issue: issue_1) + create(:merge_requests_closing_issues, merge_request: mr_2, issue: issue_2) + create(:merge_requests_closing_issues, merge_request: mr_3, issue: issue_3) + create(:merge_requests_closing_issues, merge_request: mr_4, issue: issue_3) + create(:merge_requests_closing_issues, merge_request: mr_5, issue: issue_3) + end + + around do |example| + Timecop.freeze { example.run } + end + + it 'counts median from issues with metrics' do + expect(stage.median).to eq(ISSUES_MEDIAN) + end + end end |