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

Add Active Job's assertions to ActiveSupport::TestCase #17475

Closed
wants to merge 2 commits into from
Closed

Add Active Job's assertions to ActiveSupport::TestCase #17475

wants to merge 2 commits into from

Conversation

robin850
Copy link
Member

@robin850 robin850 commented Nov 1, 2014

Hello,

Since we should test job queuing/execution inside other components of the application like models and controllers, we should make the custom assertions provided by ActiveJob::TestHelper available directly from ActiveSupport::TestCase.

Thus, we don't need the ActiveJob::TestCase class anymore so we can remove it and avoid relying on it when we generate a job's test.

This has originally been requested here but it turns out that this hasn't been addressed.

Have a nice day.

@robin850 robin850 added this to the 4.2.0 milestone Nov 1, 2014
@seuros
Copy link
Member

seuros commented Nov 1, 2014

👍

@seuros
Copy link
Member

seuros commented Nov 1, 2014

Wait! That will break if AJ is not part of the bundle. eq(A project without AJ or AM)

@robin850
Copy link
Member Author

robin850 commented Nov 1, 2014

Wait! That will break if AJ is not part of the bundle

Yup, this is not ideal and this is why I didn't put it directly under ActiveSupport::TestCase but well, there's no --skip-active-job option so if you don't want to use Active Job you will have to change things manually anyway. What do you think ?

@seuros
Copy link
Member

seuros commented Nov 1, 2014

Do we have --skip-action-mailer ? That the only gem that depend on AJ for now. Could we use it ?

@robin850
Copy link
Member Author

robin850 commented Nov 1, 2014

Do we have --skip-action-mailer ?

Nope we don't plus we are adding config.action_mailer statements in the environments files so I'm not sure whether there's a real problem here but let's wait for some feedback, what do you think ? :-)

@chancancode
Copy link
Member

That will break if AJ is not part of the bundle

This is not a concern, it has been decided that AJ will always be present in Rails apps. In a way, it's kind of like Rails.cache or Rails.logger so that (eventually – when people drop support for 4.2 and below) library authors etc can depend on the same API being present (there's no point turning it "off" – that's basically the default inline adapter).

@@ -8,5 +8,8 @@ class ActiveSupport::TestCase
fixtures :all

<% end -%>
# Make Active Job's custom assertions available inside all tests
include ActiveJob::TestHelper
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this is the right place to add this. As mentioned in my comments above, this is not something that we expect people to turn off, so I don't think it makes sense to include it in a template. Seems like we can just do this automatically somewhere inside Active Job?

Since we should test job queuing/execution inside other components of
the application like models and controllers, we should make the custom
assertions provided by `ActiveJob::TestHelper` available directly from
`ActiveSupport::TestCase`.

Thus, we don't need the `ActiveJob::TestCase` class anymore so we can
remove it and avoid relying on it when we generate a job's test.
Let's add tests to ensure that this generator get the works done when we
are calling it along the lines of the other ones.
@robin850
Copy link
Member Author

robin850 commented Nov 9, 2014

Ok, so I moved this directly to Active Job and addressed the discussion that we had on the Campfire room regarding the removal of AcitveJob::TestCase. The only problem is that Active Job's integration tests are now failing.

The problem is that ActiveJob::TestHelper overrides the queue_adapter in the before_setup hook while the integration tests are on a per adapter basis. A simple fix could be to override the adapter in the setup hook of the integration test like setup { ActiveJob::Base.queue_adapter = ENV["AJADAPTER"] } but then we are overriding the adapter three different times (in the job manager of the adapter that we are testing against, inside TestHelper and finally bring it back inside the test).

The real question is do we expect people to be able to use another queue adapter than :test when testing ?

If yes, then we would certainly need a kind of AbstractAdapter like there is in Active Record that'd define common methods needed for testing (e.g. enqueued_jobs) so assertions can work for different adapters. The problem with that approach is that we would add enqueued and performed jobs to their respective arrays while it's pretty useless outside the scope of testing.

If no, then there's no big deal, this won't work anyway outside of the framework but apart from the aforementioned solution with setup, I don't know how we could handle it in our internal test suite. 😕

Feel free to ask questions if something isn't clear in my explanations !

@robin850 robin850 changed the title Add Active Job's custom assertions to test_helper Add Active Job's assertions to ActiveSupport::TestCase Nov 9, 2014
@jeremy jeremy modified the milestones: 5.0.0, 4.2.0 Nov 24, 2014
@jeremy
Copy link
Member

jeremy commented Nov 24, 2014

We can ship with apps mixing in ActiveJob::TestHelper. Cleaning up the AJ test interaction with queue adapters needs work first.

@rafaelfranca
Copy link
Member

@robin850 want to take back on this? If not we should close.

@robin850
Copy link
Member Author

robin850 commented Jan 5, 2016

@rafaelfranca : I'm closing this one ; maybe I will work on it later but I don't have much time to spend on it ATM, sorry ! :/

@robin850 robin850 closed this Jan 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants