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
4982354c
Commit
4982354c
authored
Aug 21, 2020
by
Alex Kalderimis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for rebalancing service
parent
8c413af4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
52 deletions
+102
-52
app/services/issue_rebalancing_service.rb
app/services/issue_rebalancing_service.rb
+50
-52
spec/services/issue_rebalancing_service_spec.rb
spec/services/issue_rebalancing_service_spec.rb
+52
-0
No files found.
app/services/issue_rebalancing_service.rb
View file @
4982354c
# frozen_string_literal: true
# frozen_string_literal: true
module
Issue
class
IssueRebalancingService
<
Issues
::
BaseService
class
RebalancingService
<
Issues
::
BaseService
MAX_ISSUE_COUNT
=
100_000
MAX_ISSUE_COUNT
=
100_000
TooManyIssues
=
Class
.
new
(
StandardError
)
TooManyIssues
=
Class
.
new
(
StandardError
)
...
@@ -57,5 +56,4 @@ module Issue
...
@@ -57,5 +56,4 @@ module Issue
end
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
spec/services/issue_rebalancing_service_spec.rb
0 → 100644
View file @
4982354c
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
IssueRebalancingService
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:user
)
{
project
.
creator
}
let_it_be
(
:start
)
{
RelativePositioning
::
START_POSITION
}
let_it_be
(
:max_pos
)
{
RelativePositioning
::
MAX_POSITION
}
let_it_be
(
:min_pos
)
{
RelativePositioning
::
MIN_POSITION
}
let_it_be
(
:clump_size
)
{
300
}
let_it_be
(
:unclumped
)
do
(
0
..
clump_size
).
to_a
.
map
do
|
i
|
create
(
:issue
,
project:
project
,
author:
user
,
relative_position:
start
+
(
1024
*
i
))
end
end
let_it_be
(
:end_clump
)
do
(
0
..
clump_size
).
to_a
.
map
do
|
i
|
create
(
:issue
,
project:
project
,
author:
user
,
relative_position:
max_pos
-
i
)
end
end
let_it_be
(
:start_clump
)
do
(
0
..
clump_size
).
to_a
.
map
do
|
i
|
create
(
:issue
,
project:
project
,
author:
user
,
relative_position:
min_pos
+
i
)
end
end
def
issues_in_position_order
project
.
reload
.
issues
.
reorder
(
relative_position: :asc
).
to_a
end
it
'rebalances a set of issues with clumps at the end and start'
do
all_issues
=
start_clump
+
unclumped
+
end_clump
.
reverse
service
=
described_class
.
new
(
project
.
issues
.
first
)
expect
{
service
.
execute
}.
not_to
change
{
issues_in_position_order
.
map
(
&
:id
)
}
all_issues
.
each
(
&
:reset
)
gaps
=
all_issues
.
take
(
all_issues
.
count
-
1
).
zip
(
all_issues
.
drop
(
1
)).
map
do
|
a
,
b
|
b
.
relative_position
-
a
.
relative_position
end
expect
(
gaps
).
to
all
(
be
>
RelativePositioning
::
MIN_GAP
)
expect
(
all_issues
.
first
.
relative_position
).
to
be
>
RelativePositioning
::
MIN_POSITION
expect
(
all_issues
.
last
.
relative_position
).
to
be
<
RelativePositioning
::
MAX_POSITION
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