Commit 3f5191de authored by Kamil Trzcinski's avatar Kamil Trzcinski

Add specs for notifications

parent 2b27a98d
...@@ -160,7 +160,7 @@ module Gitlab ...@@ -160,7 +160,7 @@ module Gitlab
result = redis.set(key, value, ex: expire, nx: !overwrite) result = redis.set(key, value, ex: expire, nx: !overwrite)
if result if result
payload = "#{key}=#{value}" payload = "#{key}=#{value}"
redis.publish(RUNNER_NOTIFICATION_CHANNEL, payload) redis.publish(NOTIFICATION_CHANNEL, payload)
value value
else else
redis.get(key) redis.get(key)
......
...@@ -199,4 +199,58 @@ describe Gitlab::Workhorse, lib: true do ...@@ -199,4 +199,58 @@ describe Gitlab::Workhorse, lib: true do
end end
end end
end end
describe '.ensure_and_notify' do
let(:key) { 'test-key' }
let(:value) { 'test-value' }
subject { described_class.ensure_and_notify(key, value, overwrite: overwrite) }
shared_examples 'set and notify' do
it 'set and return the same value' do
is_expected.to eq(value)
end
it 'set and notify' do
expect_any_instance_of(Redis).to receive(:publish)
.with(described_class::NOTIFICATION_CHANNEL, "test-key=test-value")
subject
end
end
context 'when we set a new key' do
let(:overwrite) { true }
it_behaves_like 'set and notify'
end
context 'when we set an existing key' do
let(:old_value) { 'existing-key' }
before do
described_class.ensure_and_notify(key, old_value, overwrite: true)
end
context 'and overwrite' do
let(:overwrite) { true }
it_behaves_like 'set and notify'
end
context 'and do not overwrite' do
let(:overwrite) { false }
it 'try to set but return the previous value' do
is_expected.to eq(old_value)
end
it 'set and notify' do
expect_any_instance_of(Redis).not_to receive(:publish)
subject
end
end
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment