diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-03-03 13:51:49 +0100 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-03-03 13:51:49 +0100 |
commit | 3f5191de6db80872e3e712247b5582bdc4eec296 (patch) | |
tree | 48eef7cc5eaa40bd81f1f4972a1da8fba19ef59e | |
parent | 2b27a98db32d788796c4495f5405ba09436fd8ce (diff) | |
download | gitlab-ce-3f5191de6db80872e3e712247b5582bdc4eec296.tar.gz |
Add specs for notifications
-rw-r--r-- | lib/gitlab/workhorse.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/workhorse_spec.rb | 54 |
2 files changed, 55 insertions, 1 deletions
diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb index ca4eba48a8b..34fbb227f7b 100644 --- a/lib/gitlab/workhorse.rb +++ b/lib/gitlab/workhorse.rb @@ -160,7 +160,7 @@ module Gitlab result = redis.set(key, value, ex: expire, nx: !overwrite) if result payload = "#{key}=#{value}" - redis.publish(RUNNER_NOTIFICATION_CHANNEL, payload) + redis.publish(NOTIFICATION_CHANNEL, payload) value else redis.get(key) diff --git a/spec/lib/gitlab/workhorse_spec.rb b/spec/lib/gitlab/workhorse_spec.rb index a32c6131030..2f0db9616ed 100644 --- a/spec/lib/gitlab/workhorse_spec.rb +++ b/spec/lib/gitlab/workhorse_spec.rb @@ -199,4 +199,58 @@ describe Gitlab::Workhorse, lib: true do 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 |