From abb8c669378af8f3551418330751aaad80b2d6c2 Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Tue, 9 Nov 2010 10:02:09 -0800 Subject: (#5242) Fix schedule specs that fail near daylight savings I fixed a few of these in a previous patch, but Hudson found more. I replaced the pattern of using Time.now and then doing date math to calculate intervals with the pattern of hard setting the intervals using utc times for the test. Reviewed-by: Paul Berry --- spec/unit/type/schedule_spec.rb | 58 +++++++++++------------------------------ 1 file changed, 15 insertions(+), 43 deletions(-) (limited to 'spec') diff --git a/spec/unit/type/schedule_spec.rb b/spec/unit/type/schedule_spec.rb index 86b3cdd35..387370fca 100755 --- a/spec/unit/type/schedule_spec.rb +++ b/spec/unit/type/schedule_spec.rb @@ -13,14 +13,6 @@ module ScheduleTesting Time.at(diff) end - def month(method, count) - diff(:hour, 3600 * 24 * 30, method, count) - end - - def week(method, count) - diff(:hour, 3600 * 24 * 7, method, count) - end - def day(method, count) diff(:hour, 3600 * 24, method, count) end @@ -33,10 +25,6 @@ module ScheduleTesting diff(:min, 60, method, count) end - def sec(method, count) - diff(:sec, 1, method, count) - end - end describe Puppet::Type.type(:schedule) do @@ -194,26 +182,18 @@ describe Puppet::Type.type(:schedule) do end it "should match if the times are one minute apart and the current minute is 0" do - current = Time.now + current = Time.utc(2008, 1, 1, 0, 0, 0) + previous = Time.utc(2007, 12, 31, 23, 59, 0) - # Subtract an hour, reset the minute to zero, then add 59 minutes, so we're the previous hour plus 59 minutes. - previous = (current - 3600 - (current.min * 60) + (59 * 60)) - - # Now set the "current" time to the zero minute of the current hour. - now = (current - (current.min * 60)) - Time.stubs(:now).returns(now) + Time.stubs(:now).returns(current) @schedule.match?(previous).should be_true end - it "should not match if the times are 58 minutes apart and the current minute is 59" do - current = Time.now - - # reset the minute to zero - previous = current - (current.min * 60) + it "should not match if the times are 59 minutes apart and the current minute is 59" do + current = Time.utc(2009, 2, 1, 12, 59, 0) + previous = Time.utc(2009, 2, 1, 12, 0, 0) - # Now set the "current" time to the 59th minute of the current hour. - now = (current - (current.min * 60) + (59 * 60)) - Time.stubs(:now).returns(now) + Time.stubs(:now).returns(current) @schedule.match?(previous).should be_false end end @@ -258,19 +238,15 @@ describe Puppet::Type.type(:schedule) do end it "should match if the previous time is prior to the most recent Sunday" do - now = Time.now - - # Subtract the number days we've progressed into the week, plus one because we're zero-indexed. - previous = now - (3600 * 24 * (now.wday + 1)) + now = Time.utc(2010, "nov", 11, 0, 0, 0) # Thursday + previous = Time.utc(2010, "nov", 6, 23, 59, 59) # Sat @schedule.match?(previous).should be_true end it "should not match if the previous time is after the most recent Saturday" do - now = Time.now - - # Subtract the number days we've progressed into the week - previous = now - (3600 * 24 * now.wday) + now = Time.utc(2010, "nov", 11, 0, 0, 0) # Thursday + previous = Time.utc(2010, "nov", 7, 0, 0, 0) # Sunday @schedule.match?(previous).should be_false end @@ -285,19 +261,15 @@ describe Puppet::Type.type(:schedule) do end it "should match when the previous time is prior to the first day of this month" do - now = Time.now - - # Subtract the number days we've progressed into the month - previous = now - (3600 * 24 * now.day) + now = Time.utc(2010, "nov", 8, 00, 59, 59) + previous = Time.utc(2010, "oct", 31, 23, 59, 59) @schedule.match?(previous).should be_true end it "should not match when the previous time is after the last day of last month" do - now = Time.now - - # Subtract the number days we've progressed into the month, minus one - previous = now - (3600 * 24 * (now.day - 1)) + now = Time.utc(2010, "nov", 8, 00, 59, 59) + previous = Time.utc(2010, "nov", 1, 0, 0, 0) @schedule.match?(previous).should be_false end -- cgit