Skip to content

Commit

Permalink
Fix sidekiq-cron job patch return (#2176)
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py authored Nov 23, 2023
1 parent 62989c1 commit 78fb37a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 2 additions & 0 deletions sentry-sidekiq/lib/sentry/sidekiq/cron/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def save
slug: name,
monitor_config: Sentry::Cron::MonitorConfig.from_crontab(cron))
end

true
end
end
end
Expand Down
27 changes: 20 additions & 7 deletions sentry-sidekiq/spec/sentry/sidekiq/cron/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,30 @@
Sidekiq::Cron::Job.load_from_hash!(schedule)
end

before do
stub_const('Job', Class.new { def perform; end })
end

it 'patches class' do
expect(Sidekiq::Cron::Job.ancestors).to include(described_class)
end

it 'preserves return value' do
job = Sidekiq::Cron::Job.new(name: 'test', cron: '* * * * *', class: 'Job')
expect(job.save).to eq(true)
end

it 'preserves return value in invalid case' do
job = Sidekiq::Cron::Job.new(name: 'test', cron: 'not a crontab', class: 'Job')
expect(job.save).to eq(false)
end

it 'does not raise error on invalid class' do
expect do
Sidekiq::Cron::Job.create(name: 'invalid_class', cron: '* * * * *', class: 'UndefinedClass')
end.not_to raise_error
end

it 'patches HappyWorker' do
expect(HappyWorkerDup.ancestors).to include(Sentry::Cron::MonitorCheckIns)
expect(HappyWorkerDup.sentry_monitor_slug).to eq('happy')
Expand All @@ -39,11 +59,4 @@
it 'does not patch ReportingWorker because of invalid schedule' do
expect(ReportingWorker.ancestors).not_to include(Sentry::Cron::MonitorSchedule)
end

it 'does not raise error on invalid class' do
expect do
Sidekiq::Cron::Job.create(name: 'invalid_class', cron: '* * * * *', class: 'UndefinedClass')
end.not_to raise_error
end

end

0 comments on commit 78fb37a

Please sign in to comment.