Skip to content

Commit

Permalink
Merge pull request #14723 from gtanzillo/fix-perf-capture_queue-tests
Browse files Browse the repository at this point in the history
Additional tests for queueing of collection of historical metrics
(cherry picked from commit 6db53a9)
  • Loading branch information
Fryguy authored and simaishi committed Apr 13, 2017
1 parent 9283c5a commit ed6d227
Showing 1 changed file with 55 additions and 2 deletions.
57 changes: 55 additions & 2 deletions spec/models/metric/ci_mixin/capture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def verify_perf_capture_queue(last_perf_capture_on, total_queue_items)
Timecop.freeze do
Timecop.travel(Time.now.end_of_day - 6.hours)
verify_perf_capture_queue(nil, 1)
Timecop.travel(Time.now + 20.minutes)
verify_perf_capture_queue(nil, 1)
end
end

Expand All @@ -110,15 +112,66 @@ def verify_perf_capture_queue(last_perf_capture_on, total_queue_items)
Timecop.freeze do
# set a specific time of day to avoid sporadic test failures that fall on the exact right time to bump the
# queue items to 12 instead of 11
Timecop.travel(Time.now.end_of_day - 6.hours)
current_time = Time.now.end_of_day - 6.hours
Timecop.travel(current_time)
last_perf_capture_on = (10.days + 5.hours + 23.minutes).ago
verify_perf_capture_queue(last_perf_capture_on, 11)
Timecop.travel(Time.now + 20.minutes)
Timecop.travel(current_time + 20.minutes)
verify_perf_capture_queue(last_perf_capture_on, 11)
end
end
end

context "historical with capture days > 0 and multiple attempts" do
def verify_perf_capture_queue_historical(last_perf_capture_on, total_queue_items)
@vm.last_perf_capture_on = last_perf_capture_on
@vm.perf_capture_queue("historical")
expect(MiqQueue.count).to eq total_queue_items
end

it "when last_perf_capture_on is nil(first time)" do
MiqQueue.delete_all
Timecop.freeze do
allow(Metric::Capture).to receive(:historical_days).and_return(7)
current_time = Time.now.end_of_day - 6.hours
Timecop.travel(current_time)
verify_perf_capture_queue_historical(nil, 8)
Timecop.travel(current_time + 20.minutes)
verify_perf_capture_queue_historical(nil, 8)
end
end

it "when last_perf_capture_on is very old" do
MiqQueue.delete_all
Timecop.freeze do
# set a specific time of day to avoid sporadic test failures that fall on the exact right time to bump the
# queue items to 12 instead of 11
allow(Metric::Capture).to receive(:historical_days).and_return(7)
current_time = Time.now.end_of_day - 6.hours
last_capture_on = (10.days + 5.hours + 23.minutes).ago
Timecop.travel(current_time)
verify_perf_capture_queue_historical(last_capture_on, 8)
Timecop.travel(current_time + 20.minutes)
verify_perf_capture_queue_historical(last_capture_on, 8)
end
end

it "when last_perf_capture_on is fairly recent" do
MiqQueue.delete_all
Timecop.freeze do
# set a specific time of day to avoid sporadic test failures that fall on the exact right time to bump the
# queue items to 12 instead of 11
allow(Metric::Capture).to receive(:historical_days).and_return(7)
current_time = Time.now.end_of_day - 6.hours
last_capture_on = (10.days + 5.hours + 23.minutes).ago
Timecop.travel(current_time)
verify_perf_capture_queue_historical(last_capture_on, 8)
Timecop.travel(current_time + 20.minutes)
verify_perf_capture_queue_historical(last_capture_on, 8)
end
end
end

context "2 collection periods total, end of 1. period has incomplete stat" do
###################################################################################################################
# DESCRIPTION FOR: net_usage_rate_average
Expand Down

0 comments on commit ed6d227

Please sign in to comment.