UINotificationsHostsBuildCompletedTest failures with MySQL on Rails 5.0
|Assigned To:||Dominic Cleal|
|Found in release:||Pull request:||https://github.com/theforeman/foreman/pull/4424|
|Velocity based estimate||-|
The notifications host built test fails most of the time with a MySQL database under Rails 5.0:
Failure: UINotificationsHostsBuildCompletedTest#test_0002_multiple build events should update current build notification [test/unit/ui_notifications/hosts/build_completed_test.rb:12]: "Notification.where(:subject => host).count" didn't change by 1. Expected: 1 Actual: 0
The cause is similar to #19085, where the precision of timestamp fields is being relied upon for the test, and the default one-second precision of a timestamp field under MySQL is affecting it. The timestamp field getters in Rails 5.0 now return the same precision as the underlying field, causing the failure.
The test first marks an already-built host as built, puts it back into build mode and then marks it built, checking that a notification is generated on the second built event.
previous_changes['installed_at'] (i.e. a change in the installed_at timestamp) to test if the host has been provisioned. When the granularity of the timestamp is to the second, this test usually fails as it runs within one second.
This would technically be an issue in the live application as well as the test, but sub-second rebuilds are unlikely to occur in practice.
fixes #19087 - create host built notification from Host#built
Comparing the host's installed_at timestamp is unreliable on MySQL
databases, as the timestamp field has a limited granularity. Under Rails
5 in a sub-second test, this field will not be changed.
Instead, extend Host#built to create notifications as the original
method is also used to send e-mail notifications and update the