Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
- Add Logistics component with progress tracking - Add OrderDetail component for order information - Support data-driven steps and actions - Add blue color scale to widget SCSS - Fix node overflow and progress bar rendering issues - Add English translations for dashboard components Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
59 lines
2.3 KiB
Ruby
59 lines
2.3 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe MutexApplicationJob do
|
|
let(:lock_manager) { instance_double(Redis::LockManager) }
|
|
let(:lock_key) { 'test_key' }
|
|
|
|
before do
|
|
allow(Redis::LockManager).to receive(:new).and_return(lock_manager)
|
|
allow(lock_manager).to receive(:lock).and_return(true)
|
|
allow(lock_manager).to receive(:unlock).and_return(true)
|
|
end
|
|
|
|
describe '#with_lock' do
|
|
it 'acquires the lock and yields the block if lock is not acquired' do
|
|
expect(lock_manager).to receive(:lock).with(lock_key, Redis::LockManager::LOCK_TIMEOUT).and_return(true)
|
|
expect(lock_manager).to receive(:unlock).with(lock_key).and_return(true)
|
|
|
|
expect { |b| described_class.new.send(:with_lock, lock_key, &b) }.to yield_control
|
|
end
|
|
|
|
it 'acquires the lock with custom timeout' do
|
|
expect(lock_manager).to receive(:lock).with(lock_key, 5.seconds).and_return(true)
|
|
expect(lock_manager).to receive(:unlock).with(lock_key).and_return(true)
|
|
|
|
expect { |b| described_class.new.send(:with_lock, lock_key, 5.seconds, &b) }.to yield_control
|
|
end
|
|
|
|
it 'raises LockAcquisitionError if it cannot acquire the lock' do
|
|
allow(lock_manager).to receive(:lock).with(lock_key, Redis::LockManager::LOCK_TIMEOUT).and_return(false)
|
|
|
|
expect do
|
|
described_class.new.send(:with_lock, lock_key) do
|
|
# Do nothing
|
|
end
|
|
end.to raise_error(StandardError) { |error| expect(error.class.name).to eq('MutexApplicationJob::LockAcquisitionError') }
|
|
end
|
|
|
|
it 'raises StandardError if it execution raises it' do
|
|
allow(lock_manager).to receive(:lock).with(lock_key, Redis::LockManager::LOCK_TIMEOUT).and_return(false)
|
|
allow(lock_manager).to receive(:unlock).with(lock_key).and_return(true)
|
|
|
|
expect do
|
|
described_class.new.send(:with_lock, lock_key) do
|
|
raise StandardError
|
|
end
|
|
end.to raise_error(StandardError)
|
|
end
|
|
|
|
it 'ensures that the lock is released even if there is an error during block execution' do
|
|
expect(lock_manager).to receive(:lock).with(lock_key, Redis::LockManager::LOCK_TIMEOUT).and_return(true)
|
|
expect(lock_manager).to receive(:unlock).with(lock_key).and_return(true)
|
|
|
|
expect do
|
|
described_class.new.send(:with_lock, lock_key) { raise StandardError }
|
|
end.to raise_error(StandardError)
|
|
end
|
|
end
|
|
end
|