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

Fix sidekiq-cron job patch return #2176

Merged
merged 1 commit into from Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions sentry-sidekiq/lib/sentry/sidekiq/cron/job.rb
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
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