Skip to content

Commit

Permalink
use Time#floor to match database precision
Browse files Browse the repository at this point in the history
Database timestamps now have precision 6, while `Time.now` still has precision. To be able to compare them, we truncate to microseconds using `Time#floor`.
  • Loading branch information
razumau committed Jun 26, 2023
1 parent 0846f68 commit 4e41edb
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions test/queue_audit_test.rb
Expand Up @@ -57,7 +57,7 @@ class QueueAuditTest < Minitest::Test
Timecop.freeze(Time.now) do
@audit.complete!

assert_equal Time.now, @audit.completed_at
assert_equal Time.now.floor(6), @audit.completed_at
assert_equal true, @audit.complete?
end
end
Expand Down Expand Up @@ -129,7 +129,7 @@ class QueueAuditTest < Minitest::Test
@audit.enqueued!
end

assert_equal an_hour_ago, @audit.enqueued_at
assert_equal an_hour_ago.floor(6), @audit.enqueued_at
end

end
Expand All @@ -141,7 +141,7 @@ class QueueAuditTest < Minitest::Test
@audit.enqueued!
end

assert_equal (an_hour_ago + 10.minutes), @audit.timeout_at
assert_equal (an_hour_ago + 10.minutes).floor(6), @audit.timeout_at
end

it 'allows configuration of the timeout' do
Expand Down Expand Up @@ -184,13 +184,13 @@ class QueueAuditTest < Minitest::Test
Timecop.freeze(ts) do
@audit.enqueued!
end
assert_equal ts + 10.minutes, @audit.timeout_at
assert_equal (ts + 10.minutes).floor(6), @audit.timeout_at

ts = 30.minutes.ago
Timecop.freeze(ts) do
@audit.heartbeat!
end
assert_equal ts + 10.minutes, @audit.timeout_at
assert_equal (ts + 10.minutes).floor(6), @audit.timeout_at
end
end

Expand Down

0 comments on commit 4e41edb

Please sign in to comment.