-
-
Notifications
You must be signed in to change notification settings - Fork 1k
ActiveJob Matcher .at() fails with comparison of ActiveSupport::TimeWithZone and Time #2333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
👋 This is likely a precision issue:
So the times are not identical, it should be nothing to do with timezone, was your original test introduced in an earlier 4.0.0 beta? As the change you reference was actually a bug fix restoring this rounding behaviour which is the same as what is supposed to happen in rails internally. |
There's a lengthy discussion about time precision, jobs, testing, Rails' excessive trust for Ruby stability, lack of Ruby core specs etc here rails/rails#38831 Wondering if you would consider replacing Timecop.freeze with a more flexible expectation: it 'is scheduled in 5 seconds' do
expect { SayHiJob.perform_in_five }
.to have_enqueued_job(SayHiJob).at(a_value_within(5.seconds).of(Time.current))
end |
Hello @hughkelsey This is an old trick. But in your repo. --- a/spec/jobs/say_hi_job_spec.rb
+++ b/spec/jobs/say_hi_job_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
RSpec.describe SayHiJob, type: :job do
- let(:time) { Time.current }
+ let(:time) { Time.current.change(nsec: 0) } And it's green. I think the issue could be closed. |
Thanks everyone for the comments and suggestions, they all work. These specs have been green for a long time and the change between 4.0.0.beta3 and 4.0.0 caused me to open the issue. |
Having played with this some more to add a regression check, theres something funny going on with your time, using |
I've dug into this some more and this is a genuine precision error in the input value. The core issue here is that Rails, allows microsecond ( However when Rails schedules a job in the future using
Will work, and we are looking at adding a warning when we detect this scenario is possible. |
|
What Ruby, Rails and RSpec versions are you using?
Ruby version: ruby 2.6.3p62
Rails version: Rails 6.0.2.2
RSpec version: RSpec 3.9
Observed behaviour
I'm using timecop to freeze time and run a job that is delayed 5 seconds.
Expected behaviour
The spec should pass as these are the same times.
This failure happened after upgrading from 4.0.0.beta3 and is likely related to this commit:
f345e82
Can you provide an example app?
https://github.com/hughkelsey/ActiveJobMatcherAt
The relevant code is:
The text was updated successfully, but these errors were encountered: