Commit 3f681f4c authored by James Lopez's avatar James Lopez

fix specs, refactor missing bits from events stuff

parent b214be49
......@@ -3,7 +3,7 @@ module Gitlab
class BaseEventFetcher
include MetricsTables
attr_reader :projections, :query, :stage
attr_reader :projections, :query, :stage, :order
def initialize(fetcher:, options:, stage:)
@fetcher = fetcher
......@@ -22,10 +22,6 @@ module Gitlab
def custom_query(_base_query); end
def order
@order || @start_time_attrs
end
private
def update_author!
......@@ -35,7 +31,7 @@ module Gitlab
end
def event_result
@event_result ||= @fetcher.events(self).to_a
@event_result ||= @fetcher.events.to_a
end
def serialize(_event)
......
module Gitlab
module CycleAnalytics
class BaseStage
include MetricsTables
attr_accessor :start_time_attrs, :end_time_attrs
def initialize(project:, options:)
......@@ -13,7 +15,7 @@ module Gitlab
end
def event
@event ||= Gitlab::CycleAnalytics::Event[stage].new(fetcher: @fetcher, options: @options)
@event ||= Gitlab::CycleAnalytics::Event[stage].new(fetcher: @fetcher, options: @options, stage: stage)
end
def events
......
......@@ -2,7 +2,7 @@ module Gitlab
module CycleAnalytics
module Event
def self.[](stage_name)
CycleAnalytics.const_get("#{stage_name.to_s.camelize}Event")
CycleAnalytics.const_get("#{stage_name.to_s.camelize}EventFetcher")
end
end
end
......
......@@ -38,13 +38,16 @@ module Gitlab
def events_query
base_query = base_query_for(@stage.stage)
event = @stage.event
diff_fn = subtract_datetimes_diff(base_query, @stage.start_time_attrs, @stage.end_time_attrs)
event_instance.custom_query(base_query)
@stage.event.custom_query(base_query)
base_query.project(extract_diff_epoch(diff_fn).as('total_time'), *event.projections).order(event.order.desc)
base_query.project(extract_diff_epoch(diff_fn).as('total_time'), *@stage.event.projections).order(order.desc)
end
def order
@stage.event.order || @stage.start_time_attrs.is_a?(Array) ? @stage.start_time_attrs.first : @stage.start_time_attrs
end
# Join table with a row for every <issue,merge_request> pair (where the merge request
......
......@@ -5,8 +5,8 @@ describe Gitlab::CycleAnalytics::CodeEventFetcher do
let(:stage_name) { :code }
it_behaves_like 'default query config' do
it 'does not have the default order' do
expect(event.order).not_to eq(event.start_time_attrs)
it 'has a default order' do
expect(event.order).not_to be_nil
end
end
end
......@@ -4,9 +4,5 @@ require 'lib/gitlab/cycle_analytics/shared_event_spec'
describe Gitlab::CycleAnalytics::IssueEventFetcher do
let(:stage_name) { :issue }
it_behaves_like 'default query config' do
it 'has the default order' do
expect(event.order).to eq(event.start_time_attrs)
end
end
it_behaves_like 'default query config'
end
......@@ -5,10 +5,6 @@ describe Gitlab::CycleAnalytics::PlanEventFetcher do
let(:stage_name) { :plan }
it_behaves_like 'default query config' do
it 'has the default order' do
expect(event.order).to eq(event.start_time_attrs)
end
context 'no commits' do
it 'does not blow up if there are no commits' do
allow_any_instance_of(Gitlab::CycleAnalytics::MetricsFetcher).to receive(:events).and_return([{}])
......
......@@ -4,9 +4,5 @@ require 'lib/gitlab/cycle_analytics/shared_event_spec'
describe Gitlab::CycleAnalytics::ProductionEventFetcher do
let(:stage_name) { :production }
it_behaves_like 'default query config' do
it 'has the default order' do
expect(event.order).to eq(event.start_time_attrs)
end
end
it_behaves_like 'default query config'
end
......@@ -4,9 +4,5 @@ require 'lib/gitlab/cycle_analytics/shared_event_spec'
describe Gitlab::CycleAnalytics::ReviewEventFetcher do
let(:stage_name) { :review }
it_behaves_like 'default query config' do
it 'has the default order' do
expect(event.order).to eq(event.start_time_attrs)
end
end
it_behaves_like 'default query config'
end
......@@ -10,18 +10,10 @@ shared_examples 'default query config' do
let(:event) { described_class.new(fetcher: fetcher, options: {}, stage: stage_name) }
it 'has the start attributes' do
expect(event.start_time_attrs).not_to be_nil
end
it 'has the stage attribute' do
expect(event.stage).not_to be_nil
end
it 'has the end attributes' do
expect(event.end_time_attrs).not_to be_nil
end
it 'has the projection attributes' do
expect(event.projections).not_to be_nil
end
......
......@@ -8,6 +8,14 @@ shared_examples 'base stage' do
allow_any_instance_of(Gitlab::CycleAnalytics::BaseEventFetcher).to receive(:event_result).and_return({})
end
it 'has the start attributes' do
expect(stage.start_time_attrs).not_to be_nil
end
it 'has the end attributes' do
expect(stage.end_time_attrs).not_to be_nil
end
it 'has the median data value' do
expect(stage.median_data[:value]).not_to be_nil
end
......
......@@ -5,8 +5,8 @@ describe Gitlab::CycleAnalytics::StagingEventFetcher do
let(:stage_name) { :staging }
it_behaves_like 'default query config' do
it 'does not have the default order' do
expect(event.order).not_to eq(event.start_time_attrs)
it 'has a default order' do
expect(event.order).not_to be_nil
end
end
end
......@@ -5,8 +5,8 @@ describe Gitlab::CycleAnalytics::TestEventFetcher do
let(:stage_name) { :test }
it_behaves_like 'default query config' do
it 'does not have the default order' do
expect(event.order).not_to eq(event.start_time_attrs)
it 'has a default order' do
expect(event.order).not_to be_nil
end
end
end
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