Skip to content

Commit

Permalink
Merge pull request #365 from mattkirby/pooler_156
Browse files Browse the repository at this point in the history
(POOLER-156) Detect redis connection failures
  • Loading branch information
highb authored Mar 17, 2020
2 parents 4cfa873 + 7597185 commit ad39b53
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ services:
- type: bind
source: ${PWD}/vmpooler.yaml
target: /etc/vmpooler/vmpooler.yaml
- type: bind
source: ${PWD}/providers.yaml
target: /etc/vmpooler/providers.yaml
ports:
- "4567:4567"
networks:
Expand All @@ -17,6 +20,9 @@ services:
- VMPOOLER_DEBUG=true # for use of dummy auth
- VMPOOLER_CONFIG_FILE=/etc/vmpooler/vmpooler.yaml
- REDIS_SERVER=redislocal
- EXTRA_CONFIG=/etc/vmpooler/providers.yaml
- LOGFILE=/dev/stdout
- LDAP_PORT=636
image: vmpooler-local
depends_on:
- redislocal
Expand Down
5 changes: 5 additions & 0 deletions lib/vmpooler/pool_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,8 @@ def check_pool(pool,
loop_count += 1
end
end
rescue Redis::CannotConnectError
raise
rescue StandardError => e
$logger.log('s', "[!] [#{pool['name']}] Error while checking the pool: #{e}")
raise
Expand Down Expand Up @@ -1310,6 +1312,9 @@ def execute!(maxloop = 0, loop_delay = 1)
loop_count += 1
end
end
rescue Redis::CannotConnectError => e
$logger.log('s', "Cannot connect to the redis server: #{e}")
raise
end
end
end
22 changes: 22 additions & 0 deletions spec/unit/pool_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2792,6 +2792,16 @@
subject.execute!(maxloop,0)
end
end

context 'when redis server connection is not available' do
let(:maxloop) { 2 }
it 'should log a failure and raise the error' do
expect(redis).to receive(:set).with('vmpooler__tasks__clone', 0).and_raise(Redis::CannotConnectError)
expect(logger).to receive(:log).with('s', 'Cannot connect to the redis server: Redis::CannotConnectError')

expect{subject.execute!(maxloop,0)}.to raise_error Redis::CannotConnectError
end
end
end

describe "#sleep_with_wakeup_events" do
Expand Down Expand Up @@ -2987,6 +2997,18 @@
end
end

context 'when redis connection fails' do
let(:maxloop) { 2 }
let(:loop_delay) { 1 }

it 'should raise the error' do
allow(subject).to receive(:_check_pool).and_raise(Redis::CannotConnectError)
expect(logger).to receive(:log).with('d', "[*] [#{pool}] starting worker thread")

expect{subject.check_pool(pool_object,maxloop,loop_delay,loop_delay)}.to raise_error Redis::CannotConnectError
end
end

context 'delays between loops configured in the pool configuration' do
let(:maxloop) { 2 }
let(:loop_delay) { 1 }
Expand Down

0 comments on commit ad39b53

Please sign in to comment.