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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
041e8877
Commit
041e8877
authored
Aug 11, 2020
by
alinamihaila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for Redis HLL add and count
parent
d03735af
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
10 deletions
+49
-10
spec/lib/gitlab/redis/hll_spec.rb
spec/lib/gitlab/redis/hll_spec.rb
+49
-10
No files found.
spec/lib/gitlab/redis/hll_spec.rb
View file @
041e8877
...
...
@@ -4,18 +4,57 @@ require 'spec_helper'
RSpec
.
describe
Gitlab
::
Redis
::
HLL
,
:clean_gitlab_redis_shared_state
do
describe
'.add'
do
it
'raise an error when using an invalid key format'
do
expect
{
described_class
.
add
(
key:
'test'
,
value:
1
,
expiry:
1
.
day
)
}.
to
raise_error
(
Gitlab
::
Redis
::
HLL
::
KeyFormatError
)
expect
{
described_class
.
add
(
key:
'test-{metric'
,
value:
1
,
expiry:
1
.
day
)
}.
to
raise_error
(
Gitlab
::
Redis
::
HLL
::
KeyFormatError
)
expect
{
described_class
.
add
(
key:
'test-{metric}}'
,
value:
1
,
expiry:
1
.
day
)
}.
to
raise_error
(
Gitlab
::
Redis
::
HLL
::
KeyFormatError
)
context
'when checking key format'
do
it
'raise an error when using an invalid key format'
do
expect
{
described_class
.
add
(
key:
'test'
,
value:
1
,
expiry:
1
.
day
)
}.
to
raise_error
(
Gitlab
::
Redis
::
HLL
::
KeyFormatError
)
expect
{
described_class
.
add
(
key:
'test-{metric'
,
value:
1
,
expiry:
1
.
day
)
}.
to
raise_error
(
Gitlab
::
Redis
::
HLL
::
KeyFormatError
)
expect
{
described_class
.
add
(
key:
'test-{metric}}'
,
value:
1
,
expiry:
1
.
day
)
}.
to
raise_error
(
Gitlab
::
Redis
::
HLL
::
KeyFormatError
)
end
it
"doesn't raise error when having correct format"
do
expect
{
described_class
.
add
(
key:
'test-{metric}'
,
value:
1
,
expiry:
1
.
day
)
}.
not_to
raise_error
expect
{
described_class
.
add
(
key:
'test-{metric}-1'
,
value:
1
,
expiry:
1
.
day
)
}.
not_to
raise_error
expect
{
described_class
.
add
(
key:
'test:{metric}-1'
,
value:
1
,
expiry:
1
.
day
)
}.
not_to
raise_error
expect
{
described_class
.
add
(
key:
'2020-216-{project_action}'
,
value:
1
,
expiry:
1
.
day
)
}.
not_to
raise_error
expect
{
described_class
.
add
(
key:
'i_{analytics}_dev_ops_score-2020-32'
,
value:
1
,
expiry:
1
.
day
)
}.
not_to
raise_error
end
end
end
describe
'counts correct data for expand_vulnerabilities event'
do
before
do
described_class
.
add
(
key:
'2020-32-{expand_vulnerabilities}'
,
value:
"user_id_1"
,
expiry:
1
.
day
)
described_class
.
add
(
key:
'2020-32-{expand_vulnerabilities}'
,
value:
"user_id_1"
,
expiry:
1
.
day
)
described_class
.
add
(
key:
'2020-32-{expand_vulnerabilities}'
,
value:
"user_id_2"
,
expiry:
1
.
day
)
described_class
.
add
(
key:
'2020-32-{expand_vulnerabilities}'
,
value:
"user_id_3"
,
expiry:
1
.
day
)
described_class
.
add
(
key:
'2020-33-{expand_vulnerabilities}'
,
value:
"user_id_3"
,
expiry:
1
.
day
)
described_class
.
add
(
key:
'2020-33-{expand_vulnerabilities}'
,
value:
"user_id_3"
,
expiry:
1
.
day
)
described_class
.
add
(
key:
'2020-34-{expand_vulnerabilities}'
,
value:
"user_id_3"
,
expiry:
1
.
day
)
described_class
.
add
(
key:
'2020-34-{expand_vulnerabilities}'
,
value:
"user_id_2"
,
expiry:
1
.
day
)
end
it
'has 3 distinct users for weeks 32, 33, 34'
do
expect
(
described_class
.
count
(
keys:
[
'2020-32-{expand_vulnerabilities}'
,
'2020-33-{expand_vulnerabilities}'
,
'2020-34-{expand_vulnerabilities}'
])).
to
eq
(
3
)
end
it
"doesn't raise error when having correct format"
do
expect
{
described_class
.
add
(
key:
'test-{metric}'
,
value:
1
,
expiry:
1
.
day
)
}.
not_to
raise_error
expect
{
described_class
.
add
(
key:
'test-{metric}-1'
,
value:
1
,
expiry:
1
.
day
)
}.
not_to
raise_error
expect
{
described_class
.
add
(
key:
'test:{metric}-1'
,
value:
1
,
expiry:
1
.
day
)
}.
not_to
raise_error
expect
{
described_class
.
add
(
key:
'2020-216-{project_action}'
,
value:
1
,
expiry:
1
.
day
)
}.
not_to
raise_error
expect
{
described_class
.
add
(
key:
'i_{analytics}_dev_ops_score-2020-32'
,
value:
1
,
expiry:
1
.
day
)
}.
not_to
raise_error
it
'has 3 distinct users for weeks 32, 33'
do
expect
(
described_class
.
count
(
keys:
[
'2020-32-{expand_vulnerabilities}'
,
'2020-33-{expand_vulnerabilities}'
])).
to
eq
(
3
)
end
it
'has 2 distinct users for weeks 33, 34'
do
expect
(
described_class
.
count
(
keys:
[
'2020-33-{expand_vulnerabilities}'
,
'2020-34-{expand_vulnerabilities}'
])).
to
eq
(
2
)
end
it
'has one distinct user for weel 33'
do
expect
(
described_class
.
count
(
keys:
[
'2020-33-{expand_vulnerabilities}'
])).
to
eq
(
1
)
end
it
'has 4 distinct users when one different user has an action on week 34'
do
described_class
.
add
(
key:
'2020-34-{expand_vulnerabilities}'
,
value:
"user_id_4"
,
expiry:
29
.
days
)
expect
(
described_class
.
count
(
keys:
[
'2020-32-{expand_vulnerabilities}'
,
'2020-33-{expand_vulnerabilities}'
,
'2020-34-{expand_vulnerabilities}'
])).
to
eq
(
4
)
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