Skip to content

Commit

Permalink
Ensure that Sinatra loads the SidekiqAlive.config.port (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcantin authored and arturictus committed Jan 3, 2020
1 parent d6d8649 commit 618f13c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/sidekiq_alive/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module SidekiqAlive
class Server < Sinatra::Base
set :bind, '0.0.0.0'
set :port, SidekiqAlive.config.port
set :port, -> { SidekiqAlive.config.port }

get '/' do
if SidekiqAlive.alive?
Expand Down
16 changes: 16 additions & 0 deletions spec/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,20 @@
expect(last_response.body).to eq("Can't find the alive key")
end
end

describe 'SidekiqAlive setup' do
before do
ENV['SIDEKIQ_ALIVE_PORT'] = '4567'
SidekiqAlive.config.set_defaults
end

after do
ENV['SIDEKIQ_ALIVE_PORT'] = nil
end

it 'respects the SIDEKIQ_ALIVE_PORT environment variable' do
expect( described_class.port ).to eq '4567'
end
end

end
18 changes: 18 additions & 0 deletions spec/sidekiq_alive_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@
expect(SidekiqAlive::VERSION).not_to be nil
end

it 'configures the port from the #setup' do
described_class.setup do |config|
config.port = 4567
end

expect( described_class.config.port ).to eq 4567
end

it 'configures the port from the SIDEKIQ_ALIVE_PORT ENV var' do
ENV['SIDEKIQ_ALIVE_PORT'] = '4567'

SidekiqAlive.config.set_defaults

expect( described_class.config.port ).to eq '4567'

ENV['SIDEKIQ_ALIVE_PORT'] = nil
end

it 'configurations behave as expected' do
k = described_class.config
expect(k.port).to eq 7433
Expand Down
4 changes: 3 additions & 1 deletion spec/worker_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RSpec.describe SidekiqAlive::Worker do
context 'When beeing executed in the same instance' do
context 'When being executed in the same instance' do
subject do
described_class.new.perform
end
Expand All @@ -19,9 +19,11 @@
subject do
described_class.new
end

it 'when instance is not registered' do
expect(subject.hostname_registered?('any-name')).to be false
end

it 'when instance is registered' do
allow(SidekiqAlive).to receive(:registered_instances).and_return(['SIDEKIQ_KEY:any-name'])
expect(subject.hostname_registered?('any-name')).to be true
Expand Down

0 comments on commit 618f13c

Please sign in to comment.