Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
3f5191de
Commit
3f5191de
authored
Mar 03, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for notifications
parent
2b27a98d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
1 deletion
+55
-1
lib/gitlab/workhorse.rb
lib/gitlab/workhorse.rb
+1
-1
spec/lib/gitlab/workhorse_spec.rb
spec/lib/gitlab/workhorse_spec.rb
+54
-0
No files found.
lib/gitlab/workhorse.rb
View file @
3f5191de
...
...
@@ -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
)
...
...
spec/lib/gitlab/workhorse_spec.rb
View file @
3f5191de
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment