diff --git a/spec/support/metric_helper.rb b/spec/support/metric_helper.rb index 337b616afea1..ea7534c77a9b 100644 --- a/spec/support/metric_helper.rb +++ b/spec/support/metric_helper.rb @@ -31,15 +31,29 @@ 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] + 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 end