Skip to content
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

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
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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants