aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #33992 from kirs/enqueue-return-falseRafael França2018-12-052-0/+38
|\ | | | | Make AJ::Base#enqueue return false if the job wasn't enqueued
| * Make AJ::Base#enqueue return false if the job wasn't enqueuedKir Shatrov2018-10-282-0/+38
| |
* | Do not deserialize GlobalID objects that were not generated by Active JobRafael Mendonça França2018-11-271-0/+4
| | | | | | | | | | | | | | Trusting any GlobaID object when deserializing jobs can allow attackers to access information that should not be accessible to them. Fix CVE-2018-16476.
* | Merge pull request #34376 from composerinteralia/default_queue_nameRafael França2018-11-231-1/+28
|\ \ | | | | | | Allow using queue prefix with a default queue name
| * | Allow using queue prefix with a default queue nameDaniel Colson2018-11-031-1/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #34366 Currently setting queue_name_prefix will not combine a prefix with the default_queue_name; it will only affect queue names set with `queue_as`. With this PR the prefix will affect the default_queue_name as well. Closes #19831 Currently setting default_queue_name doesn't actually affect the queue_name default (although default_queue_name does get used if you pass a falsey `part_name` to `queue_as`). This PR would get default_queue_name working as expected as well. Because the queue_name default is now a lambda wrapping the default_queue_name, rather than the default_queue_name itself, I had to update one test to use the instance method `#queue_name` (which `instance_exec`s the value) instead of the class method. I think this change is OK, since only the instance method is documented. There was a question about whether we want a `default_queue_name` configuration. If we want to get rid of it, I would also be happy to open a PR for that instead. It has been around for a while now, but it also hasn't really worked for a while now. r? @matthewd since you had an opinion about this before
* | | Keep executions for each specific exception (#34352)Alberto Almagro2018-11-232-0/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Keep executions for each specific declaration Fixes #34337 ActiveJob used the global executions counter to control the number of times a job should be retried. The problem with this approach was that in case a job raised different exceptions during its executions they weren't retried the number of times defined by their `attemps` number. **Example:** Having the following job: ```ruby class BuggyJob < ActiveJob::Base retry_on CustomException, attemps: 3 retry_on OtherException, attempts: 3 end ``` If the job raised `CustomException` in the first two executions and then it raised `OtherException`, the job wasn't retried anymore because the global executions counter was already indicating 3 attempts. With this patch each `retry_on` declaration has its specific counter so that the first two executions that raise `CustomException` don't affect the retries count that future exceptions may have. * Revert "clarifies documentation around the attempts arugment to retry_on" This reverts commit 86aa8f8c5631f77ed9a208e5107003c01512133e.
* | | Allow all ActiveJob assertion helper to accept Proc in their `only` kw:Edouard CHIN2018-11-211-0/+56
| | | | | | | | | | | | | | | | | | | | | | | | - That feature is useful to enqueue or assert that jobs got enqueued or performed based on dynamic conditions. We will be able to leverage that feature to fix all ActionMailer assertion helper issue when a Mailer define a custom delivery job (see next commit).
* | | Permit ActionController::Parameters for serializable HashBernie Chiu2018-11-192-0/+25
|/ /
* | Restore HWIA support to AJ::Arguments.deserializeGannon McGibbon2018-10-301-0/+5
| | | | | | | | | | Restore HashWithIndifferentAccess support to ActiveJob::Arguments.deserialize.
* | Merge pull request #33972 from bogdanvlviv/follow-up-33897Rafael França2018-10-301-5/+5
|\ \ | |/ |/| Improve `enqueue_retry.active_job` message
| * Improve `enqueue_retry.active_job` messagebogdanvlviv2018-09-251-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since #33751 was added `enqueue_retry.active_job` instrumentation to the `retry_on` method, then #33897 moved the instrumentation to `retry_job` method in order to ensure that this method publish `enqueue_retry.active_job` notification too. See related discussion https://github.com/rails/rails/pull/33751#discussion_r214140008 Since `enqueue_retry.active_job` moved to `retry_job`, there is no guarantee that payload of `enqueue_retry.active_job` would have `:error`. See test `LoggingTest#test_enqueue_retry_logging_on_retry_job` as example of that case. Related to https://github.com/rails/rails/pull/33897#discussion_r219707024 I think we can improve notification of `enqueue_retry.active_job`: - If there is no `event.payload[:error]`, then publish like "Retrying RescueJob in 3 seconds." only. - If `event.payload[:wait]` is `nil`, then publish "Retrying RescueJob in 0 seconds." instead of "Retrying RescueJob in nil seconds." - If there is `event.payload[:error]`, then publish "Retrying RescueJob in 3 seconds, due to a DefaultsError.". - Change the type of the message from `error` to `info.` Also, this commit removes part of messages - "The original exception was #{ex.cause.inspect}." of `enqueue_retry.active_job`, `retry_stopped.active_job`, and `discard.active_job` since I haven't found it useful. Please let me know whether you agree with that?
* | Merge pull request #34204 from XrXr/aj-test-helper-argsRafael França2018-10-241-12/+12
|\ \ | | | | | | Include deserialized arguments in jobs returned by AJ test helpers
| * | Include deserialized arguments in jobs returned by AJ test helpersAlan Wu2018-10-121-12/+12
| | | | | | | | | | | | | | | | | | | | | | | | `assert_enqueued_with` and `assert_performed_with` return a instantiated instance of the matching job for further assertion (#21010). Before this commit the `arguments` method on the returned instance returns a serialized version of the arguments.
* | | Remove an extra `@mutex.synchronize`yuuji.yaginuma2018-10-191-12/+1
| | | | | | | | | | | | | | | | | | | | | | | | Since `@mutex.synchronize` is enforced in the `ensure_connection!` method, there is no need to do so on the caller side. https://github.com/jondot/sneakers/blob/c1b47f9c5d5a95da728bbe1700795790e4efbb12/lib/sneakers/publisher.rb#L22-L26 Due to this, `ThreadError(deadlock; recursive locking)` has occurred.
* | | Return a non zero code when can not connect to backend on CIyuuji.yaginuma2018-10-194-4/+8
|/ /
* | Add a way to check for subset of arguments when performing jobs:Edouard CHIN2018-09-261-0/+46
| | | | | | | | | | | | | | | | | | | | | | | | - When calling `assert_performed_with`/`assert_enqueued_with`, the +args+ needs to match exactly what the job get passed. Some jobs can have lot of arguments, or even a simple hash argument has many key. This is not convenient to test as most tests doesn't need to check if the arguments matches perfectly. This PR make it possible to only check if a subset of arguments were passed to the job.
* | Change the empty block style to have space inside of the blockRafael Mendonça França2018-09-251-1/+1
|/
* Merge pull request #33906 from dark-panda/ignore-psqlrc-when-using-psqlRafael França2018-09-202-4/+4
|\ | | | | Ignore psqlrc files when executing psql commands
| * Ignore psqlrc files when executing psql commandsJ Smith2018-09-172-4/+4
| | | | | | | | | | | | psqlrc files can affect the execution of commands in ways that can hold up execution by blocking or otherwise cause unexpected side effects and should best be ignored when using psql programmatically.
* | Make `assert_<enqueued|performed>_with()` compare hashes ignoring order of keysSharang Dashputre2018-09-212-0/+22
| | | | | | | | The test helpers now treat `{ a: 1, b: 2 }` and `{ b: 2, a: 1 }` as equals
* | Merge pull request #33897 from bogdanvlviv/follow-up-33751Rafael França2018-09-181-0/+5
|\ \ | |/ |/| Follow up #33751
| * `retry_job` should publish `enqueue_retry.active_job` notificationbogdanvlviv2018-09-161-0/+5
| | | | | | | | | | | | | | | | | | | | Also this commit removes `:wait` from payload of `retry_stopped.active_job`. Related to https://github.com/rails/rails/pull/33751#discussion_r214140008 Follow up #33751 /cc @kaspth, @rafaelfranca
* | Print correct rake command on running AJ integration testsbogdanvlviv2018-09-171-1/+1
|/ | | | | | | | | | | | | | | | | | | | | | | | | Currently when executing `bundle exec rake test:integration` under `activejob/` derectory, it prints helpful info like: ``` (snip) *** rake aj:integration:async *** (snip) *** rake aj:integration:delayed_job *** (snip) ``` but there is no defined `:aj` scope in `activejob/Rakefile`, so I think output should be like: ``` (snip) *** rake test:integration:async *** (snip) *** rake test:integration:delayed_job *** (snip) ``` By the way `rake test:integration` doesn't work if execute it without prepending `bundle exec` to that command. It is probably what we should fix too.
* Update test_helper_test.rbSharang Dashputre2018-09-121-1/+1
| | | Fix typo `wiht` -> `with`
* Merge pull request #33823 from stoodfarback/aj_backburner_fix_priorityRafael França2018-09-101-0/+12
|\ | | | | ActiveJob Backburner adapter: fix priority
| * ActiveJob Backburner adapter: fix prioritystoodfarback2018-09-071-0/+12
| | | | | | | | | | | | | | The priority wasn't being passed from ActiveJob to Backburner, despite priority being supported. This also brings it inline with the docs, which mark Backburner as supporting priorities in the "Backend Features" table: https://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html
* | Add missing `perform_enqueued_jobs` to error logging testyuuji.yaginuma2018-09-091-1/+1
|/ | | | Without `perform_enqueued_jobs`, job are not executed and assertion is not done.
* Merge pull request #33751 from steves/add_retry_notifications_to_ajRafael França2018-08-301-27/+72
|\ | | | | Add hooks to ActiveJob around retries and discards
| * Move ActiveJob retry and discard logging into log subscriberSteve S2018-08-301-27/+72
| |
* | Add test to make sure the custom object key can't be serializedRafael Mendonça França2018-08-281-2/+4
|/
* Remove duplicate testutilum2018-08-221-2/+2
| | | | | | This patch corrects a duplicate method name introduced in #33635. Also fixes typo in method names.
* Allow `assert_performed_with` to be called without a block.bogdanvlviv2018-08-201-7/+91
| | | | | | | | | | | | | | | Example: ``` def test_assert_performed_with MyJob.perform_later(1,2,3) perform_enqueued_jobs assert_performed_with(job: MyJob, args: [1,2,3], queue: 'high') end ``` Follow up #33626.
* Fix `assert_performed_jobs` and `assert_no_performed_jobs`bogdanvlviv2018-08-201-10/+256
| | | | | Execution of `assert_performed_jobs`, and `assert_no_performed_jobs` without a block should respect passed `:except`, `:only`, and `:queue` options.
* Allow `:queue` option to `assert_no_performed_jobs`.bogdanvlviv2018-08-201-0/+54
| | | | | | | | | | | | | | If the `:queue` option is specified, then only the job(s) enqueued to a specific queue will not be performed. Example: ``` def test_assert_no_performed_jobs_with_queue_option assert_no_performed_jobs queue: :some_queue do HelloJob.set(queue: :other_queue).perform_later("jeremy") end end ```
* Allow `:queue` option to `assert_performed_jobs`.bogdanvlviv2018-08-201-0/+58
| | | | | | | | | | | | | | | If the `:queue` option is specified, then only the job(s) enqueued to a specific queue will be performed. Example: ``` def test_assert_performed_jobs_with_queue_option assert_performed_jobs 1, queue: :some_queue do HelloJob.set(queue: :some_queue).perform_later("jeremy") HelloJob.set(queue: :other_queue).perform_later("bogdan") end end ```
* Allow `:queue` option to `perform_enqueued_jobs`.bogdanvlviv2018-08-201-5/+139
| | | | | | | | | | | | | | | | | | | | If the `:queue` option is specified, then only the job(s) enqueued to a specific queue will be performed. Example: ``` def test_perform_enqueued_jobs_with_queue perform_enqueued_jobs queue: :some_queue do MyJob.set(queue: :some_queue).perform_later(1, 2, 3) # will be performed HelloJob.set(queue: :other_queue).perform_later(1, 2, 3) # will not be performed end assert_performed_jobs 1 end ``` Follow up #33265 [bogdanvlviv & Jeremy Daer]
* Increment execution count before deserialize argumentsyuuji.yaginuma2018-08-182-0/+9
| | | | | | | | Currently, the execution count increments after deserializes arguments. Therefore, if an error occurs with deserialize, it retries indefinitely. In order to prevent this, the count is moved before deserialize. Fixes #33344.
* Allow `perform_enqueued_jobs` to be called without a block.Kevin Deisz2018-08-151-2/+18
| | | | Performs all of the jobs that have been enqueued up to this point in the test.
* Wrap ActiveJob::Enqueue in evented ActiveSupport::Notificationzvkemp2018-07-171-3/+20
|
* Allow `queue` option to `assert_no_enqueued_jobs`bogdanvlviv2018-06-301-0/+73
| | | | | | | | | | | It can be asserted that no jobs are enqueued to a specific queue: ```ruby def test_no_logging assert_no_enqueued_jobs queue: 'default' do LoggingJob.set(queue: :some_queue).perform_later end end ```
* Merge pull request #33257 from utilum/ruby-warningsRyuta Kamizono2018-06-302-4/+6
|\ | | | | Fix Ruby warnings tickled by the test suite
| * Fix Ruby warnings tickled by the test suiteutilum2018-06-302-4/+6
| |
* | Clarify activejob/lib/active_job/test_helper.rbbogdanvlviv2018-06-291-2/+8
|/ | | | | | | | | | | Rename `in_block_job` to `enqueued_job` since this variable can refer not only to jobs that were created in the block. See #33258. Return back accidentally removed test to activejob/test/cases/test_helper_test.rb See #33258. Fix name of tests.
* Allow call `assert_enqueued_with` and `assert_enqueued_email_with` with no blockbogdanvlviv2018-06-291-9/+74
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Example of `assert_enqueued_with` with no block ```ruby def test_assert_enqueued_with MyJob.perform_later(1,2,3) assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low') MyJob.set(wait_until: Date.tomorrow.noon).perform_later assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon) end ``` Example of `assert_enqueued_email_with` with no block: ```ruby def test_email ContactMailer.welcome.deliver_later assert_enqueued_email_with ContactMailer, :welcome end def test_email_with_arguments ContactMailer.welcome("Hello", "Goodbye").deliver_later assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"] end ``` Related to #33243
* Allow passing multiple exceptions to retry_on/discard_onGeorge Claghorn2018-06-252-0/+25
|
* Rename exception variable to error.Kasper Timm Hansen2018-05-211-2/+2
| | | | Follows the change from 6fac9bd, so the naming is consistent.
* Pass the error instance as the second parameter of block executed by ↵yuuji.yaginuma2018-05-122-2/+2
| | | | | | | | | | | `discard_on` I'm not sure what originally wanted to pass to the argument. However, as long as see the document added along with the commit, it seems just to be mistaken that trying to pass the error instance. https://github.com/rails/rails/pull/30622/files#diff-59beb0189c8c6bc862edf7fdb84ff5a7R64 Fixes #32853
* Make sure that when serialing an just deserialized job arguments are thereRafael Mendonça França2018-05-011-6/+6
| | | | | | | | | | | | | When a job was just deserialized `arguments` is `nil` and the serialized arguments are in the `@serialized_arguments` variable. If we try to serialize this job again the arguments are going to be `nil` instead of what was serialized. The test we had was not checking this case because it was deserializing the job in the same object that had the arguments. To fix this, when the `@serialized_arguments` are present we return it instead of the result of the `arguments` serialized.
* Remove support for Qu gem.Alberto Almagro2018-03-193-46/+1
| | | | | | Reasons are that the Qu gem wasn't compatible since Rails 5.1, gem development was stopped in 2014 and maintainers have confirmed its demise. See issue #32273
* Add support for timezones to Active JobAndrew White2018-02-226-0/+74
| | | | | | Record what was the current timezone in effect when the job was enqueued and then restore when the job is executed in same way that the current locale is recorded and restored.