Defect #33941

Test fails depending on time zone setting

Added by Yuichi HARADA about 1 month ago. Updated about 1 month ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-
Target version:-
Resolution: Affected version:

Description

If you set the timezone in config/additional_environment.rb and test it, any tests may fail.

config.time_zone = 'International Date Line West'   # UTC-12:00

The test will always fail if the date of today on UTC and the date of today on config.time_zone are different.

$ RAILS_ENV=test bundle exec rake db:migrate:reset

$ RAILS_ENV=test bundle exec rake test
Run options: --seed 21968

# Running:

....................F

Failure:
MailerTest#test_reminders [./test/unit/mailer_test.rb:694]:
"Bug #3: Error 281 when updating a recipe (5 days late)" not found in "1 issue(s) that are assigned to you are due in the next 42 days::

* eCookbook - Bug #3: Error 281 when updating a recipe (6 days late)

View all issues (2 open)
http://localhost:3000/issues?assigned_to_id=me&set_filter=1&sort=due_date%3Aasc

--
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://hostname/my/account
" 

bin/rails test test/unit/mailer_test.rb:687

................F

Failure:
MailerTest#test_reminders_should_sort_issues_by_due_date [./test/unit/mailer_test.rb:823]:
<(?-mix:foo \(1 day late\))> expected but was
<eCookbook - Bug #18: foo (2 days late)>..
Expected 0 to be >= 1.

bin/rails test test/unit/mailer_test.rb:811

........F

Failure:
MailerTest#test_reminders_language_auto [./test/unit/mailer_test.rb:717]:
"Bug #3: Error 281 when updating a recipe (En retard de 5 jours)" not found in "1 demande(s) qui vous sont assignées arrivent à échéance dans les 42 prochains jours ::

* eCookbook - Bug #3: Error 281 when updating a recipe (En retard de 6 jours)

Voir toutes les demandes (2 ouvertes)
http://localhost:3000/issues?assigned_to_id=me&set_filter=1&sort=due_date%3Aasc

--
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://hostname/my/account
" 

bin/rails test test/unit/mailer_test.rb:708

....F

Failure:
MailerTest#test_reminder_should_include_issues_assigned_to_groups [./test/unit/mailer_test.rb:773]:
"Assigned to group (Due in 5 days)" not found in "1 issue(s) that are assigned to you are due in the next 7 days::

* eCookbook - Bug #15: Assigned to group (Due in 4 days)

View all issues (2 open)
http://localhost:3000/issues?assigned_to_id=me&set_filter=1&sort=due_date%3Aasc

--
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://hostname/my/account
" 

bin/rails test test/unit/mailer_test.rb:749

.......F

Failure:
MailerTest#test_reminders_for_users [./test/unit/mailer_test.rb:746]:
"Bug #3: Error 281 when updating a recipe (5 days late)" not found in "1 issue(s) that are assigned to you are due in the next 42 days::

* eCookbook - Bug #3: Error 281 when updating a recipe (6 days late)

View all issues (2 open)
http://localhost:3000/issues?assigned_to_id=me&set_filter=1&sort=due_date%3Aasc

--
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://hostname/my/account
" 

bin/rails test test/unit/mailer_test.rb:738

...........

Finished in 411.745744s, 12.2090 runs/s, 56.3649 assertions/s.
5027 runs, 23208 assertions, 5 failures, 0 errors, 7 skips

You have skipped tests. Run with --verbose for details.
$

fixed-33941.patch Magnifier (38.3 KB) Yuichi HARADA, 2020-09-01 08:08

History

#1 Updated by Yuichi HARADA about 1 month ago

There are two possible causes for the test to fail.

  • When using Date.today, Time.now, DateTime.now, the timezone in config.time_zone is ignored. You should use Date.current, Time.current, DateTime.current.
  • Times of the day are not stored in table columns of type of date. However, in Query#date_clause(source:/trunk/app/models/query.rb#L1465), because the where condition considering the time difference is created for this Date type table column, the SQL execution result is strange.

#2 Updated by Yuichi HARADA about 1 month ago

Yuichi HARADA wrote:

There are two possible causes for the test to fail.

  • When using Date.today, Time.now, DateTime.now, the timezone in config.time_zone is ignored. You should use Date.current, Time.current, DateTime.current.
  • Times of the day are not stored in table columns of type of date. However, in Query#date_clause(source:/trunk/app/models/query.rb#L1465), because the where condition considering the time difference is created for this Date type table column, the SQL execution result is strange.

I will attach a patch to resolve these.

I've tested in the following time zones to make sure the tests don't fail.

config.time_zone = 'UTC'   # UTC+-00:00

config.time_zone = 'Tokyo'  # UTC+09:00
config.time_zone = 'Samoa' # UTC+13:00

config.time_zone = 'Alaska'  # UTC-09:00
config.time_zone = 'International Date Line West'   # UTC-12:00

Also available in: Atom PDF