debian-mirror-gitlab/spec/lib/gitlab/analytics/cycle_analytics/median_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.2 KiB
Ruby
Raw Permalink Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Analytics::CycleAnalytics::Median do
2020-05-24 23:13:21 +05:30
let_it_be(:project) { create(:project, :repository) }
2021-04-29 21:17:54 +05:30
2020-05-24 23:13:21 +05:30
let(:query) { Project.joins(merge_requests: :metrics) }
let(:stage) do
build(
2023-04-23 21:23:45 +05:30
:cycle_analytics_stage,
2020-05-24 23:13:21 +05:30
start_event_identifier: Gitlab::Analytics::CycleAnalytics::StageEvents::MergeRequestCreated.identifier,
end_event_identifier: Gitlab::Analytics::CycleAnalytics::StageEvents::MergeRequestMerged.identifier,
2023-04-23 21:23:45 +05:30
namespace: project.reload.project_namespace
2020-05-24 23:13:21 +05:30
)
end
subject { described_class.new(stage: stage, query: query).seconds }
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)
2023-03-04 22:38:38 +05:30
travel(5.minutes) do
2020-05-24 23:13:21 +05:30
merge_request1.metrics.update!(merged_at: Time.zone.now)
end
2023-03-04 22:38:38 +05:30
travel(10.minutes) do
2020-05-24 23:13:21 +05:30
merge_request2.metrics.update!(merged_at: Time.zone.now)
end
2023-01-13 00:05:48 +05:30
expect(subject).to be_within(5.seconds).of(7.5.minutes.seconds)
2020-05-24 23:13:21 +05:30
end
end