Skip to content

Commit

Permalink
More testing for perf_capture_queue
Browse files Browse the repository at this point in the history
Ensure that perf_capture_queue works on long intervals and single days.
  • Loading branch information
blomquisg committed Mar 20, 2017
1 parent 1b539ce commit 8b24751
Showing 1 changed file with 36 additions and 23 deletions.
59 changes: 36 additions & 23 deletions spec/models/metric/ci_mixin/capture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,44 @@ def expected_stats_period_end
end

context "#perf_capture_queue" do
it "splits up long perf_capture durations for old last_perf_capture_on" do
# there should be 10 days + a partial day, or 11 queue items
Timecop.freeze
original_queue_count = MiqQueue.count
start_time = 10.days.ago - 5.hours - 23.minutes
@vm.last_perf_capture_on = start_time
@vm.perf_capture_queue("realtime")
expect(MiqQueue.count - original_queue_count).to eq 11

# make sure the queue items are in the correct order
queue_items = MiqQueue.peek(:conditions => {:zone => @vm.my_zone,
:queue_name => @vm.queue_name_for_metrics_collection,
:role => "ems_metrics_collector"},
:limit => 3)
start_time = (start_time + 10.days).utc
end_time = (start_time + 5.hours + 23.minutes).utc
queue_items.each do |q_item|
q_start_time, q_end_time = q_item.args
expect(q_start_time).to eq start_time
expect(q_end_time).to eq end_time
end_time = start_time
start_time = start_time - 1.day
def test_perf_capture_queue(time_since_last_perf_capture, total_queue_items, verify_queue_items_count)
# There are usually some lingering queue items from creating the provider above. Notably `stop_event_monitor`
MiqQueue.delete_all
Timecop.freeze do
start_time = (Time.now.utc - time_since_last_perf_capture)
@vm.last_perf_capture_on = start_time
@vm.perf_capture_queue("realtime")
expect(MiqQueue.count).to eq total_queue_items

# make sure the queue items are in the correct order
queue_items = MiqQueue.order(:id).limit(verify_queue_items_count)
days_ago = (time_since_last_perf_capture.to_i / 1.day.to_i).days
partial_days = time_since_last_perf_capture - days_ago
interval_start_time = (start_time + days_ago).utc
interval_end_time = (interval_start_time + partial_days).utc
queue_items.each do |q_item|
q_start_time, q_end_time = q_item.args
expect(q_start_time).to be_same_time_as interval_start_time
expect(q_end_time).to be_same_time_as interval_end_time
interval_end_time = interval_start_time
# if the collection threshold is ever parameterized, then this 1.day will have to change
interval_start_time = interval_start_time - 1.day
end
end
end

it "splits up long perf_capture durations for old last_perf_capture_on" do
# test when last perf capture was many days ago
# total queue items == 11
# verify last 3 queue items
test_perf_capture_queue(10.days + 5.hours + 23.minutes, 11, 3)
end

Timecop.return
it "does not get confused when dealing with a single day" do
# test when perf capture is just a few hours ago
# total queue items == 1
# verify last 1 queue item
test_perf_capture_queue(0.days + 2.hours + 5.minutes, 1, 1)
end
end

Expand Down

0 comments on commit 8b24751

Please sign in to comment.