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

have_enqueued_job supports time object #2157

Merged
merged 1 commit into from
Sep 9, 2019

Conversation

alpaca-tc
Copy link
Contributor

Rails6 can pass Time as arguments to ActiveJob but have_enqueued_job#with doesn't support time object.
Deserialized time has 0 usec value, it will fail when compared with original time.

time = Time.now
expect { job.perform_later(time) }.to have_enqueued_job.with(time) #=> failed

This PR fixes it by to serialize/deserialize arguments before comparing.

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.

Thank a lot for your PR @alpaca-tc

Just a small comment but this is not a blocker.

@@ -172,6 +173,13 @@ def set_expected_number(relativity, count)
end
end

def serialize_and_deserialize_arguments(args)
serialized = ::ActiveJob::Arguments.serialize(args)
Copy link
Member

@benoittgt benoittgt Aug 19, 2019

Choose a reason for hiding this comment

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

I am surprise we have to serialize then deserialize. I am wondering if it can be simpler?

https://github.com/rails/rails/blob/6-0-stable/activejob/lib/active_job/serializers/time_serializer.rb

Also maybe we can avoid using exception to validate the correct behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed to use simple time rounder instead of serializer/deserializer.
It is copied from ActiveJob::TestHelper.

https://github.com/rails/rails/blob/c986369095ad89fd68fd84d21aa39006ea77904d/activejob/lib/active_job/test_helper.rb#L638

Copy link
Member

Choose a reason for hiding this comment

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

I prefer the original implementation, it's simpler as it replicates what Rails does without special casing, the new implementation may not catch other edgecases and we're just reinventing what Rails is doing.

Copy link
Member

Choose a reason for hiding this comment

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

I'd also like to see a green build, which is why I started #2158

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also like the original implementation, so I reverted. And, I deleted ActiveJob::DeserializationError because it never occurred.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the change and sorry for the back and forth.

@alpaca-tc alpaca-tc force-pushed the have_enqueued_job_time branch 2 times, most recently from 493fbb9 to 8a7317a Compare August 20, 2019 13:55
@benoittgt benoittgt self-requested a review August 21, 2019 05:21
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.

LGTM but waiting for a green CI.

@benoittgt benoittgt self-requested a review August 21, 2019 05:40
@JonRowe
Copy link
Member

JonRowe commented Aug 23, 2019

Can you cherry-pick 4eeb9ac into this to see if you get a green build?

@JonRowe
Copy link
Member

JonRowe commented Aug 25, 2019

I'm happy to merge this if you are @benoittgt I think the failures are the same as 4-0-dev normally right?

@benoittgt
Copy link
Member

Yes and yes Jon. I will try tonight to fix the build on 4-0-dev.

@benoittgt
Copy link
Member

Sorry last call. Can you rebase from 4-0-dev?

Thanks a lot

@alpaca-tc
Copy link
Contributor Author

@benoittgt All green now 💚 🎉

@JonRowe JonRowe merged commit 0fe7631 into rspec:4-0-dev Sep 9, 2019
@JonRowe
Copy link
Member

JonRowe commented Sep 9, 2019

Thanks! 💚

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.

3 participants