|
19 | 19 | expect(performances).to eq [true, nil, nil] |
20 | 20 | expect(Delayed::Job).to have_received(:reserve) |
21 | 21 | end |
| 22 | + |
| 23 | + describe 'connection pool config check' do |
| 24 | + let(:connection_pool) { instance_double(ActiveRecord::ConnectionAdapters::ConnectionPool, size: pool_size) } |
| 25 | + |
| 26 | + before do |
| 27 | + subject.send(:stop) # prevent start from running more than one loop |
| 28 | + allow(Delayed::Job).to receive(:reserve).and_return([]) |
| 29 | + allow(Delayed::Job).to receive(:connection_pool).and_return(connection_pool) |
| 30 | + allow(Delayed::Job).to receive(:clear_locks!) |
| 31 | + allow(subject).to receive(:say).and_call_original |
| 32 | + end |
| 33 | + |
| 34 | + around do |example| |
| 35 | + max_claims_was = described_class.max_claims |
| 36 | + described_class.max_claims = max_claims |
| 37 | + example.run |
| 38 | + ensure |
| 39 | + described_class.max_claims = max_claims_was |
| 40 | + end |
| 41 | + |
| 42 | + context 'when max_claims equals pool size' do |
| 43 | + let(:max_claims) { 5 } |
| 44 | + let(:pool_size) { 5 } |
| 45 | + |
| 46 | + it 'logs a warning at startup' do |
| 47 | + subject.start |
| 48 | + expect(subject).to have_received(:say).with(/WARNING.*max_claims.*5.*>=.*pool size.*5/i, 'warn') |
| 49 | + end |
| 50 | + end |
| 51 | + |
| 52 | + context 'when max_claims exceeds pool size' do |
| 53 | + let(:max_claims) { 6 } |
| 54 | + let(:pool_size) { 5 } |
| 55 | + |
| 56 | + it 'logs a warning at startup' do |
| 57 | + subject.start |
| 58 | + expect(subject).to have_received(:say).with(/WARNING.*max_claims.*6.*>=.*pool size.*5/i, 'warn') |
| 59 | + end |
| 60 | + end |
| 61 | + |
| 62 | + context 'when max_claims is less than pool size' do |
| 63 | + let(:max_claims) { 4 } |
| 64 | + let(:pool_size) { 5 } |
| 65 | + |
| 66 | + it 'does not log a warning' do |
| 67 | + subject.start |
| 68 | + expect(subject).not_to have_received(:say).with(/WARNING/i, 'warn') |
| 69 | + end |
| 70 | + end |
| 71 | + |
| 72 | + context 'when connection_pool introspection raises' do |
| 73 | + let(:max_claims) { 5 } |
| 74 | + let(:pool_size) { 5 } |
| 75 | + |
| 76 | + before do |
| 77 | + allow(Delayed::Job).to receive(:connection_pool).and_raise(StandardError, 'unavailable') |
| 78 | + end |
| 79 | + |
| 80 | + it 'starts without raising' do |
| 81 | + expect { subject.start }.not_to raise_error |
| 82 | + end |
| 83 | + end |
| 84 | + end |
22 | 85 | end |
23 | 86 |
|
24 | 87 | # rubocop:disable RSpec/SubjectStub |
|
0 commit comments