Skip to content

Add test case to demonstrate that recurring tasks don't report exceptions to the error reporter #219

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add test case to demonstrate that recurring tasks don't report except…
…ions to the error reporter
  • Loading branch information
fractaledmind committed May 3, 2024
commit db847aadde396597db783d99bccfec3f79353b80
4 changes: 4 additions & 0 deletions test/dummy/config/solid_queue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ default: &default
class: StoreResultJob
args: [ 42, { status: "custom_status" } ]
schedule: every second
periodic_raise_exception:
class: StoreResultJob
args: [ 42, { exception: RuntimeError } ]
schedule: every second

development:
<<: *default
Expand Down
50 changes: 42 additions & 8 deletions test/integration/recurring_tasks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,56 @@ class RecurringTasksTest < ActiveSupport::TestCase
terminate_process(@pid)

skip_active_record_query_cache do
assert SolidQueue::Job.count >= 2
SolidQueue::Job.all.each do |job|
assert_equal "periodic_store_result", job.recurring_execution.task_key
assert_equal "StoreResultJob", job.class_name
matching_jobs = SolidQueue::Job.all.select do |job|
"periodic_store_result" == job.recurring_execution.task_key &&
"StoreResultJob" == job.class_name
end
assert matching_jobs.count >= 2

assert_equal 2, JobResult.count
JobResult.all.each do |result|
assert_equal "custom_status", result.status
assert_equal "42", result.value
matching_results = JobResult.all.select do |result|
"custom_status" == result.status &&
"42" == result.value
end
assert matching_results.count >= 2
end
end

test "job failures are reported via Rails error subscriber" do
subscriber = ErrorBuffer.new
with_error_subscriber(subscriber) do
wait_for_jobs_to_be_enqueued(2, timeout: 2.seconds)
wait_for_jobs_to_finish_for(2.seconds)

terminate_process(@pid)

skip_active_record_query_cache do
matching_jobs = SolidQueue::Job.all.select do |job|
"periodic_raise_exception" == job.recurring_execution.task_key &&
"StoreResultJob" == job.class_name
end
assert matching_jobs.count >= 2

matching_results = JobResult.all.select do |result|
"started" == result.status &&
"42" == result.value
end
assert matching_results.count >= 2
end
end

assert subscriber.errors.count >= 2
assert_equal "RuntimeError", subscriber.messages.first
end

private
def wait_for_jobs_to_be_enqueued(count, timeout: 1.second)
wait_while_with_timeout(timeout) { SolidQueue::Job.count < count }
end

def with_error_subscriber(subscriber)
Rails.error.subscribe(subscriber)
yield
ensure
Rails.error.unsubscribe(subscriber) if Rails.error.respond_to?(:unsubscribe)
end
end
Loading