Commit 85b196b4 authored by Stan Hu's avatar Stan Hu

Merge branch '202143-fix-not-enough-data-in-vsa' into 'master'

Fix not enough data in VSA

Closes #202143

See merge request gitlab-org/gitlab!31315
parents f6eed567 7611afe5
---
title: Fix 'not enough data' in Value Stream Analytics when low median values are
returned
merge_request: 31315
author:
type: fixed
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
@query = @query.select(median_duration_in_seconds.as('median')) @query = @query.select(median_duration_in_seconds.as('median'))
result = execute_query(@query).first || {} result = execute_query(@query).first || {}
result['median'] ? result['median'].to_i : nil result['median'] || nil
end end
def days def days
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Analytics::CycleAnalytics::Median do
let_it_be(:project) { create(:project, :repository) }
let(:query) { Project.joins(merge_requests: :metrics) }
let(:stage) do
build(
:cycle_analytics_project_stage,
start_event_identifier: Gitlab::Analytics::CycleAnalytics::StageEvents::MergeRequestCreated.identifier,
end_event_identifier: Gitlab::Analytics::CycleAnalytics::StageEvents::MergeRequestMerged.identifier,
project: project
)
end
subject { described_class.new(stage: stage, query: query).seconds }
around do |example|
Timecop.freeze { example.run }
end
it 'retruns nil when no results' do
expect(subject).to eq(nil)
end
it 'returns median duration seconds as float' do
merge_request1 = create(:merge_request, source_branch: '1', target_project: project, source_project: project)
merge_request2 = create(:merge_request, source_branch: '2', target_project: project, source_project: project)
Timecop.travel(5.minutes.from_now) do
merge_request1.metrics.update!(merged_at: Time.zone.now)
end
Timecop.travel(10.minutes.from_now) do
merge_request2.metrics.update!(merged_at: Time.zone.now)
end
expect(subject).to be_within(0.5).of(7.5.minutes.seconds)
end
end
...@@ -63,7 +63,7 @@ shared_examples 'Gitlab::Analytics::CycleAnalytics::DataCollector backend exampl ...@@ -63,7 +63,7 @@ shared_examples 'Gitlab::Analytics::CycleAnalytics::DataCollector backend exampl
context 'provides the same results as the old implementation' do context 'provides the same results as the old implementation' do
it 'for the median' do it 'for the median' do
expect(data_collector.median.seconds).to eq(ISSUES_MEDIAN) expect(data_collector.median.seconds).to be_within(0.5).of(ISSUES_MEDIAN)
end end
it 'for the list of event records' do it 'for the list of event records' do
......
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