Module: ActiveJob::Continuation::TestHelper
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Instance Chain:
|
|
| Defined in: | activejob/lib/active_job/continuation/test_helper.rb |
Overview
Test helper for ::ActiveJob::Continuable jobs.
Constant Summary
::ActiveSupport::Testing::Assertions - Included
Instance Attribute Summary
Instance Method Summary
-
#interrupt_job_after_step(job_class, step, reason: true, &block)
Interrupta job after a step. -
#interrupt_job_during_step(job_class, step, cursor: nil, reason: true, &block)
Interrupta job during a step. - #after_step?(job, step) ⇒ Boolean private
- #continuation_for(job) private
- #during_step?(job, step, cursor: nil) ⇒ Boolean private
::ActiveJob::TestHelper - Included
| #assert_enqueued_jobs | Asserts that the number of enqueued jobs matches the given number. |
| #assert_enqueued_with | Asserts that the job has been enqueued with the given arguments. |
| #assert_no_enqueued_jobs | Asserts that no jobs have been enqueued. |
| #assert_no_performed_jobs | Asserts that no jobs have been performed. |
| #assert_performed_jobs | Asserts that the number of performed jobs matches the given number. |
| #assert_performed_with | Asserts that the job has been performed with the given arguments. |
| #perform_enqueued_jobs | Performs all enqueued jobs. |
| #queue_adapter | Accesses the queue_adapter set by |
| #queue_adapter_for_test | Returns a queue adapter instance to use with all Active Job test helpers. |
| #clear_enqueued_jobs, #clear_performed_jobs, #deserialize_args_for_assertion, #enqueued_jobs_with, #filter_as_proc, #flush_enqueued_jobs, #instantiate_job, #jobs_with, #performed_jobs_with, #prepare_args_for_assertion, #require_active_job_test_adapter!, #validate_option, #after_teardown, #before_setup | |
::ActiveSupport::Testing::Assertions - Included
| #assert_changes | Assertion that the result of evaluating an expression is changed before and after invoking the passed in block. |
| #assert_difference | Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. |
| #assert_no_changes | Assertion that the result of evaluating an expression is not changed before and after invoking the passed in block. |
| #assert_no_difference | Assertion that the numeric result of evaluating an expression is not changed before and after invoking the passed in block. |
| #assert_not | Asserts that an expression is not truthy. |
| #assert_nothing_raised | Assertion that the block should not raise an exception. |
| #assert_raise | |
| #assert_raises | Asserts that a block raises one of |
| #_assert_nothing_raised_or_warn, #_callable_to_source_string, #_expression_to_callable | |
Instance Method Details
#after_step?(job, step) ⇒ Boolean (private)
# File 'activejob/lib/active_job/continuation/test_helper.rb', line 87
def after_step?(job, step) if (continuation = continuation_for(job)) continuation["completed"].last == step.to_s && continuation["current"].nil? end end
#continuation_for(job) (private)
[ GitHub ]
#during_step?(job, step, cursor: nil) ⇒ Boolean (private)
# File 'activejob/lib/active_job/continuation/test_helper.rb', line 81
def during_step?(job, step, cursor: nil) if (continuation = continuation_for(job)) continuation["current"] == [ step.to_s, cursor ] end end
#interrupt_job_after_step(job_class, step, reason: true, &block)
Interrupt a job after a step.
Note that there's no checkpoint after the final step so it won't be interrupted.
class MyJob < ApplicationJob include ActiveJob::Continuable
cattr_accessor :items, default: []
def perform
step :step_one { items << 1 }
step :step_two { items << 2 }
step :step_three { items << 3 }
step :step_four { items << 4 }
end
end
test "interrupt job after step" do MyJob.perform_later interrupt_job_after_step(MyJob, :step_two) { perform_enqueued_jobs } assert_equal [1, 2], MyJob.items perform_enqueued_jobs assert_equal [1, 2, 3, 4], MyJob.items end
A custom interrupt reason can be provided with the reason argument.
# File 'activejob/lib/active_job/continuation/test_helper.rb', line 70
def interrupt_job_after_step(job_class, step, reason: true, &block) require_active_job_test_adapter!("interrupt_job_after_step") stopping = ->(job) { reason if job.is_a?(job_class) && after_step?(job, step) } queue_adapter.with(stopping: stopping, &block) end
#interrupt_job_during_step(job_class, step, cursor: nil, reason: true, &block)
Interrupt a job during a step.
class MyJob < ApplicationJob include ActiveJob::Continuable
cattr_accessor :items, default: []
def perform
step :my_step, start: 1 do |step|
(step.cursor..10).each do |i|
items << i
step.advance!
end
end
end
end
test "interrupt job during step" do MyJob.perform_later interrupt_job_during_step(MyJob, :my_step, cursor: 6) { perform_enqueued_jobs } assert_equal [1, 2, 3, 4, 5], MyJob.items perform_enqueued_jobs assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], MyJob.items end
A custom interrupt reason can be provided with the reason argument.
# File 'activejob/lib/active_job/continuation/test_helper.rb', line 38
def interrupt_job_during_step(job_class, step, cursor: nil, reason: true, &block) require_active_job_test_adapter!("interrupt_job_during_step") stopping = ->(job) { reason if job.is_a?(job_class) && during_step?(job, step, cursor: cursor) } queue_adapter.with(stopping: stopping, &block) end