From 71366209d56a62c90ef39fb00470305f7caa5a0f Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sat, 6 Feb 2016 20:01:00 +0900 Subject: [PATCH] Fix `assert_in_delta` test failure `assert_in_delta` in `timestamp_test.rb` causes an intermittent test failure. It looks like that caused by subseconds truncation in MySQL 5.5. Example: ``` 1) Failure: TimestampTest#test_touching_many_attributes_updates_them [/home/travis/build/rails/rails/activerecord/test/cases/timestamp_test.rb:125]: Expected |2016-02-06 09:22:10 +0000 - 2016-02-06 09:22:09 UTC| (1.000837185) to be <= 1. ``` --- activerecord/test/cases/timestamp_test.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/activerecord/test/cases/timestamp_test.rb b/activerecord/test/cases/timestamp_test.rb index 970f6bcf4a..937b84bccc 100644 --- a/activerecord/test/cases/timestamp_test.rb +++ b/activerecord/test/cases/timestamp_test.rb @@ -98,8 +98,11 @@ class TimestampTest < ActiveRecord::TestCase task = Task.first previous_value = task.ending task.touch(:ending) + + now = Time.now.change(usec: 0) + assert_not_equal previous_value, task.ending - assert_in_delta Time.now, task.ending, 1 + assert_in_delta now, task.ending, 1 end def test_touching_an_attribute_updates_timestamp_with_given_time @@ -120,10 +123,12 @@ class TimestampTest < ActiveRecord::TestCase previous_ending = task.ending task.touch(:starting, :ending) + now = Time.now.change(usec: 0) + assert_not_equal previous_starting, task.starting assert_not_equal previous_ending, task.ending - assert_in_delta Time.now, task.starting, 1 - assert_in_delta Time.now, task.ending, 1 + assert_in_delta now, task.starting, 1 + assert_in_delta now, task.ending, 1 end def test_touching_a_record_without_timestamps_is_unexceptional