|
23 | 23 | describe 'connection pool config check' do |
24 | 24 | let(:connection_pool) { instance_double(ActiveRecord::ConnectionAdapters::ConnectionPool, size: pool_size) } |
25 | 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 | 26 | around do |example| |
35 | 27 | max_claims_was = described_class.max_claims |
36 | 28 | described_class.max_claims = max_claims |
|
39 | 31 | described_class.max_claims = max_claims_was |
40 | 32 | end |
41 | 33 |
|
| 34 | + before do |
| 35 | + allow(Delayed.logger).to receive(:warn) |
| 36 | + subject.send(:stop) # prevent start from running more than one loop |
| 37 | + allow(Delayed::Job).to receive(:reserve).and_return([]) |
| 38 | + allow(Delayed::Job).to receive(:connection_pool).and_return(connection_pool) |
| 39 | + allow(Delayed::Job).to receive(:clear_locks!) |
| 40 | + end |
| 41 | + |
42 | 42 | context 'when max_claims equals pool size' do |
43 | 43 | let(:max_claims) { 5 } |
44 | 44 | let(:pool_size) { 5 } |
45 | 45 |
|
46 | 46 | it 'logs a warning at startup' do |
47 | 47 | subject.start |
48 | | - expect(subject).to have_received(:say).with( |
49 | | - 'WARNING: max_claims (5) >= DB connection pool size (5). ' \ |
50 | | - 'The worker process needs at least 1 connection for its own housekeeping, so job threads may ' \ |
51 | | - 'starve waiting for a connection. Set Delayed::Worker.max_claims to at most 4.', |
52 | | - 'warn', |
| 48 | + expect(Delayed.logger).to have_received(:warn).with( |
| 49 | + include( |
| 50 | + 'WARNING: Delayed::Worker.max_claims (5) >= ActiveRecord connection pool size (5). ' \ |
| 51 | + 'The worker process itself also needs a connection for polling and locking, so at least one job thread ' \ |
| 52 | + 'will likely fail with ActiveRecord::ConnectionTimeoutError. ' \ |
| 53 | + 'Set Delayed::Worker.max_claims to 4 or less, or increase your connection pool size.', |
| 54 | + ), |
53 | 55 | ) |
54 | 56 | end |
55 | 57 | end |
|
60 | 62 |
|
61 | 63 | it 'logs a warning at startup' do |
62 | 64 | subject.start |
63 | | - expect(subject).to have_received(:say).with( |
64 | | - 'WARNING: max_claims (6) >= DB connection pool size (5). ' \ |
65 | | - 'The worker process needs at least 1 connection for its own housekeeping, so job threads may ' \ |
66 | | - 'starve waiting for a connection. Set Delayed::Worker.max_claims to at most 4.', |
67 | | - 'warn', |
| 65 | + expect(Delayed.logger).to have_received(:warn).with( |
| 66 | + include( |
| 67 | + 'WARNING: Delayed::Worker.max_claims (6) >= ActiveRecord connection pool size (5). ' \ |
| 68 | + 'The worker process itself also needs a connection for polling and locking, so at least one job thread ' \ |
| 69 | + 'will likely fail with ActiveRecord::ConnectionTimeoutError. ' \ |
| 70 | + 'Set Delayed::Worker.max_claims to 4 or less, or increase your connection pool size.', |
| 71 | + ), |
68 | 72 | ) |
69 | 73 | end |
70 | 74 | end |
|
75 | 79 |
|
76 | 80 | it 'does not log a warning' do |
77 | 81 | subject.start |
78 | | - expect(subject).not_to have_received(:say).with(/WARNING/i, 'warn') |
| 82 | + expect(Delayed.logger).not_to have_received(:warn).with(/WARNING/i) |
79 | 83 | end |
80 | 84 | end |
81 | 85 |
|
|
0 commit comments