Use UTC instead of system timezone #2

Merged
merged 1 commit into from Nov 18, 2011

Projects

None yet

2 participants

@kencheeto

The 'failed' named_scope uses Time.now, which looks at the system timezone. Exposed this by changing a spec:

it 'provides audits enqueued for more than than the expected run duration' do
  Timecop.freeze(@audit.duration.from_now + 1.second) do

to

it 'provides audits enqueued for more than than the expected run duration' do
  Timecop.freeze(@audit.timeout_at + 1.second) do

which has the same behavior but will test against the @audit's time, not from_now which uses system time. An example named_scope that uses Time.now is below:

queue_audit.rb

named_scope :failed, lambda {
  { :conditions => [ 'completed_at is null AND timeout_at < ?', Time.now ], :order => 'timeout_at asc' }
}
  1) Failure:
test_0001_provides_audits_enqueued_for_more_than_than_the_expected_run_duration(Queue Audit::failed) [test/queue_audit_test.rb:73]:
--- expected
+++ actual
@@ -1 +1 @@
-[#<Resque::Durable::QueueAudit>]
+[]

After using Time.now.utc instead of Time.now, tests will pass and behavior will be correct in any system timezone.

@eac eac and 1 other commented on an outdated diff Nov 17, 2011
test/monitor_test.rb
@@ -1,4 +1,4 @@
-require 'test_helper'
+require File.join(File.dirname(__FILE__), 'test_helper')
@eac
eac Nov 17, 2011 owner

Awesome. Can you revert this line? Then I'll merge in. You can run tests via ruby -I "test"

@kencheeto
kencheeto Nov 17, 2011

Reverted- ready to merge :^)

@eac eac merged commit fad0c9e into eac:master Nov 18, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment