Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve enqueued_job at specs and warn about precision. #2350

Merged
merged 2 commits into from
May 28, 2020

Conversation

JonRowe
Copy link
Member

@JonRowe JonRowe commented May 28, 2020

There is an issue with our time matching for enqueued_job, Rails allows microsecond (usec) precision in job queue values, and uses .to_f for exact time scheduling, which we replicated in #2157, without this to_f you cannot check exact time scheduled jobs.

However when Rails schedules a job in the future using wait: n it is doing n.seconds.from_now which does not get passed through to_f, there is no way for us to detect which is correct so we'll stick with out existing handling, but warn about this precision issue, adding change(usec: 0) or switching to n.seconds.from_now...

Ironically I found this by trying to remove freeze_time from our own specs, it appears that travel_to specific time, keeps usec precision, but not freeze_time?

@JonRowe JonRowe requested a review from pirj May 28, 2020 09:40
@JonRowe JonRowe force-pushed the improve-enqueued-job-at branch from 2fc5707 to a815b2e Compare May 28, 2020 09:46
Copy link
Member

@benoittgt benoittgt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot. I hit this issue many times before. This warning will help lot's people to understand spec failure in this case. 🙏

lib/rspec/rails/matchers/active_job.rb Outdated Show resolved Hide resolved
lib/rspec/rails/matchers/active_job.rb Show resolved Hide resolved
@JonRowe JonRowe force-pushed the improve-enqueued-job-at branch from a815b2e to f9c3bc1 Compare May 28, 2020 11:14
@JonRowe JonRowe merged commit 631a226 into master May 28, 2020
@JonRowe JonRowe deleted the improve-enqueued-job-at branch May 28, 2020 17:34
JonRowe added a commit that referenced this pull request May 29, 2020
JonRowe added a commit that referenced this pull request Jun 10, 2020
JonRowe added a commit that referenced this pull request Jun 10, 2020
JonRowe added a commit that referenced this pull request Jun 10, 2020
pirj pushed a commit that referenced this pull request Aug 2, 2020
pirj pushed a commit that referenced this pull request Aug 2, 2020
This was referenced Mar 15, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants