Skip to content

Commit

Permalink
metrics: combine time ranges for tests
Browse files Browse the repository at this point in the history
Instead of getting into the weeds about how granular our messages are,
we are just making sure all the time frames of interest are tested
  • Loading branch information
kbrock committed Jan 8, 2020
1 parent 953fcd8 commit b30db11
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions spec/support/metric_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,30 @@ def queue_timings(items = MiqQueue.where(:method_name => %w[perf_capture_hourly
messages[interval_name] ||= {}
(messages[interval_name][obj] ||= []) << q.args
end
messages["historical"]&.transform_values!(&:sort!)
messages["historical"]&.transform_values! { |v| combine_consecutive(v) }

messages
end

def combine_consecutive(array)
x = array.sort!.shift
array.each_with_object([]) do |i, ac|
if i.first == x.last
x[1] = i.last
else
ac << x
x = i
end
end << x
end

# sorry, stole from the code - not really testing
def arg_day_range(start_time, end_time, threshold = 1.day)
(start_time.utc..end_time.utc).step_value(threshold).each_cons(2).collect do |s_time, e_time|
[s_time, e_time]
end
combine_consecutive(
(start_time.utc..end_time.utc).step_value(threshold).each_cons(2).collect do |s_time, e_time|
[s_time, e_time]
end
)
end

def stub_performance_settings(hash)
Expand Down

0 comments on commit b30db11

Please sign in to comment.