Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nduitz committed Jun 25, 2024
1 parent 1ebcf89 commit 19cbeb6
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions spec/support/shared_examples/enqueuing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,42 @@
end
end

context 'when locking fails due to RedisClient error' do
before do
job_class.unique strategy

allow_any_instance_of(ActiveJob::Uniqueness::LockManager).to receive(:lock).and_raise(RedisClient::ConnectionError)
end

shared_examples 'of no jobs enqueued' do
it 'does not enqueue the job' do
expect { suppress(RedisClient::ConnectionError) { subject } }.not_to change(enqueued_jobs, :count)
end

it 'does not remove the existing lock' do
expect { suppress(RedisClient::ConnectionError) { subject } }.not_to change(locks, :count)
end
end

context 'when no options given' do
include_examples 'of no jobs enqueued'

it 'raises a RedisClient::ConnectionError error' do
expect { subject }.to raise_error RedisClient::ConnectionError
end
end

context 'when on_redis_connection_error: Proc given' do
before { job_class.unique strategy, on_redis_connection_error: ->(job, **_kwargs) { job.logger.info('Oops') } }

include_examples 'of no jobs enqueued'

it 'calls the Proc' do
expect { subject }.to log(/Oops/)
end
end
end

context 'when the lock exists' do
before do
job_class.unique strategy
Expand Down

0 comments on commit 19cbeb6

Please sign in to comment.