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
72347448
Commit
72347448
authored
Oct 28, 2018
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More specs for fallback testing.
parent
01c7cb90
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
0 deletions
+36
-0
lib/gitlab/database/count.rb
lib/gitlab/database/count.rb
+3
-0
spec/lib/gitlab/database/count_spec.rb
spec/lib/gitlab/database/count_spec.rb
+33
-0
No files found.
lib/gitlab/database/count.rb
View file @
72347448
...
...
@@ -29,6 +29,9 @@ module Gitlab
strategies
.
each_with_object
({})
do
|
strategy
,
counts_by_model
|
if
strategy
.
enabled?
models_with_missing_counts
=
models
-
counts_by_model
.
keys
return
counts_by_model
if
models_with_missing_counts
.
empty?
counts
=
strategy
.
new
(
models_with_missing_counts
).
count
counts
.
each
do
|
model
,
count
|
...
...
spec/lib/gitlab/database/count_spec.rb
View file @
72347448
...
...
@@ -27,6 +27,39 @@ describe Gitlab::Database::Count do
end
context
'fallbacks'
do
subject
{
described_class
.
approximate_counts
(
models
,
strategies:
strategies
)
}
let
(
:strategies
)
do
[
double
(
's1'
,
:enabled?
=>
true
,
new:
first_strategy
),
double
(
's2'
,
:enabled?
=>
true
,
new:
second_strategy
)
]
end
let
(
:first_strategy
)
{
double
(
'first strategy'
,
count:
{})
}
let
(
:second_strategy
)
{
double
(
'second strategy'
,
count:
{})
}
it
'gets results from first strategy'
do
expect
(
strategies
[
0
]).
to
receive
(
:new
).
with
(
models
).
and_return
(
first_strategy
)
expect
(
first_strategy
).
to
receive
(
:count
)
subject
end
it
'gets more results from second strategy if some counts are missing'
do
expect
(
first_strategy
).
to
receive
(
:count
).
and_return
({
Project
=>
3
})
expect
(
strategies
[
1
]).
to
receive
(
:new
).
with
([
Identity
]).
and_return
(
second_strategy
)
expect
(
second_strategy
).
to
receive
(
:count
).
and_return
({
Identity
=>
1
})
expect
(
subject
).
to
eq
({
Project
=>
3
,
Identity
=>
1
})
end
it
'does not get more results as soon as all counts are present'
do
expect
(
first_strategy
).
to
receive
(
:count
).
and_return
({
Project
=>
3
,
Identity
=>
1
})
expect
(
strategies
[
1
]).
not_to
receive
(
:new
)
subject
end
end
context
'with PostgreSQL'
,
:postgresql
do
...
...
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