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
f3f1b010
Commit
f3f1b010
authored
Mar 23, 2020
by
Sean McGivern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use public project in UpdateAllMirrorsWorker specs
This public project allows us to test the next change effectively.
parent
4a09d7b3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
70 deletions
+76
-70
ee/spec/workers/update_all_mirrors_worker_spec.rb
ee/spec/workers/update_all_mirrors_worker_spec.rb
+76
-70
No files found.
ee/spec/workers/update_all_mirrors_worker_spec.rb
View file @
f3f1b010
...
@@ -126,7 +126,7 @@ describe UpdateAllMirrorsWorker do
...
@@ -126,7 +126,7 @@ describe UpdateAllMirrorsWorker do
projects
.
each
{
|
project
|
expect_import_status
(
project
,
'none'
)
}
projects
.
each
{
|
project
|
expect_import_status
(
project
,
'none'
)
}
end
end
context
'unlicensed'
do
context
'
when the instance is
unlicensed'
do
it
'does not schedule when project does not have repository mirrors available'
do
it
'does not schedule when project does not have repository mirrors available'
do
project
=
create
(
:project
,
:mirror
)
project
=
create
(
:project
,
:mirror
)
...
@@ -138,110 +138,116 @@ describe UpdateAllMirrorsWorker do
...
@@ -138,110 +138,116 @@ describe UpdateAllMirrorsWorker do
end
end
end
end
context
'licensed'
do
context
'on GitLab.com'
do
def
scheduled_mirror
(
at
:,
licensed
:)
def
scheduled_mirror
(
at
:,
licensed
:,
public:
false
,
subgroup:
nil
)
namespace
=
create
(
:group
,
:public
)
group_args
=
[
:group
,
:public
,
subgroup
&&
:nested
].
compact
namespace
=
create
(
*
group_args
)
project
=
create
(
:project
,
:public
,
:mirror
,
namespace:
namespace
)
project
=
create
(
:project
,
:public
,
:mirror
,
namespace:
namespace
)
create
(
:gitlab_subscription
,
(
licensed
?
:bronze
:
:free
),
namespace:
namespace
)
create
(
:gitlab_subscription
,
(
licensed
?
:bronze
:
:free
),
namespace:
namespace
.
root_ancestor
)
project
.
import_state
.
update!
(
next_execution_timestamp:
at
)
project
.
import_state
.
update!
(
next_execution_timestamp:
at
)
project
.
update!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
)
project
.
update!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
)
unless
public
project
project
end
end
before
do
before
do
stub_licensed_features
(
repository_mirrors:
true
)
stub_application_setting
(
check_namespace_plan:
true
)
stub_application_setting
(
check_namespace_plan:
true
)
allow
(
Gitlab
).
to
receive_messages
(
com?:
true
)
stub_const
(
'License::ANY_PLAN_FEATURES'
,
[])
end
end
let
!
(
:unlicensed_project1
)
{
scheduled_mirror
(
at:
8
.
weeks
.
ago
,
licensed:
false
)
}
let
_it_be
(
:unlicensed_project1
)
{
scheduled_mirror
(
at:
8
.
weeks
.
ago
,
licensed:
false
)
}
let
!
(
:unlicensed_project2
)
{
scheduled_mirror
(
at:
7
.
weeks
.
ago
,
licensed:
false
)
}
let
_it_be
(
:unlicensed_project2
)
{
scheduled_mirror
(
at:
7
.
weeks
.
ago
,
licensed:
false
)
}
let
!
(
:licensed_project1
)
{
scheduled_mirror
(
at:
6
.
weeks
.
ago
,
licensed
:
true
)
}
let
_it_be
(
:licensed_project1
)
{
scheduled_mirror
(
at:
6
.
weeks
.
ago
,
licensed:
true
,
subgroup
:
true
)
}
let
!
(
:unlicensed_project3
)
{
scheduled_mirror
(
at:
5
.
weeks
.
ago
,
licensed:
false
)
}
let
_it_be
(
:unlicensed_project3
)
{
scheduled_mirror
(
at:
5
.
weeks
.
ago
,
licensed:
false
)
}
let
!
(
:licensed_project2
)
{
scheduled_mirror
(
at:
4
.
weeks
.
ago
,
licensed:
true
)
}
let
_it_be
(
:licensed_project2
)
{
scheduled_mirror
(
at:
4
.
weeks
.
ago
,
licensed:
true
)
}
let
!
(
:unlicensed_project4
)
{
scheduled_mirror
(
at:
3
.
weeks
.
ago
,
licensed:
false
)
}
let
_it_be
(
:unlicensed_project4
)
{
scheduled_mirror
(
at:
3
.
weeks
.
ago
,
licensed:
false
)
}
let
!
(
:licensed_project3
)
{
scheduled_mirror
(
at:
1
.
week
.
ago
,
licensed
:
true
)
}
let
_it_be
(
:public_project
)
{
scheduled_mirror
(
at:
1
.
week
.
ago
,
licensed:
false
,
public
:
true
)
}
let
(
:unlicensed_projects
)
{
[
unlicensed_project1
,
unlicensed_project2
,
unlicensed_project3
,
unlicensed_project4
]
}
let
(
:unlicensed_projects
)
{
[
unlicensed_project1
,
unlicensed_project2
,
unlicensed_project3
,
unlicensed_project4
]
}
context
'when capacity is in excess'
do
context
'during the free period for pull mirroring'
do
it
"schedules all available mirrors"
do
before
do
schedule_mirrors!
(
capacity:
4
)
stub_const
(
'License::ANY_PLAN_FEATURES'
,
[])
expect_import_scheduled
(
licensed_project1
,
licensed_project2
,
licensed_project3
)
expect_import_not_scheduled
(
*
unlicensed_projects
)
end
end
it
'requests as many batches as necessary'
do
context
'when capacity is in excess'
do
# The first batch will only contain 3 licensed mirrors, but since we have
it
"schedules all available mirrors"
do
# fewer than 8 mirrors in total, there's no need to request another batch
schedule_mirrors!
(
capacity:
4
)
expect
(
subject
).
to
receive
(
:pull_mirrors_batch
).
with
(
hash_including
(
batch_size:
8
)).
and_call_original
schedule_mirrors!
(
capacity:
4
)
aggregate_failures
do
end
expect_import_scheduled
(
licensed_project1
,
licensed_project2
,
public_project
)
expect_import_not_scheduled
(
*
unlicensed_projects
)
end
end
it
"does not schedule a mirror of an archived project"
do
it
'requests as many batches as necessary'
do
licensed_project1
.
update!
(
archived:
true
)
# The first batch will only contain 3 licensed mirrors, but since we have
# fewer than 8 mirrors in total, there's no need to request another batch
expect
(
subject
).
to
receive
(
:pull_mirrors_batch
).
with
(
hash_including
(
batch_size:
8
)).
and_call_original
schedule_mirrors!
(
capacity:
4
)
schedule_mirrors!
(
capacity:
4
)
end
expect_import_scheduled
(
licensed_project2
,
licensed_project3
)
it
"does not schedule a mirror of an archived project"
do
expect_import_not_scheduled
(
licensed_project1
)
licensed_project1
.
update!
(
archived:
true
)
expect_import_not_scheduled
(
*
unlicensed_projects
)
end
end
context
'when capacity is exacly sufficient'
do
schedule_mirrors!
(
capacity:
4
)
it
"schedules all available mirrors"
do
schedule_mirrors!
(
capacity:
3
)
expect_import_scheduled
(
licensed_project1
,
licensed_project2
,
licensed_project3
)
expect_import_scheduled
(
licensed_project2
,
public_project
)
expect_import_not_scheduled
(
*
unlicensed_projects
)
expect_import_not_scheduled
(
licensed_project1
)
expect_import_not_scheduled
(
*
unlicensed_projects
)
end
end
end
it
'requests as many batches as necessary'
do
context
'when capacity is exacly sufficient'
do
# The first batch will only contain 2 licensed mirrors, so we need to request another batch
it
"schedules all available mirrors"
do
expect
(
subject
).
to
receive
(
:pull_mirrors_batch
).
with
(
hash_including
(
batch_size:
6
)).
ordered
.
and_call_original
schedule_mirrors!
(
capacity:
3
)
expect
(
subject
).
to
receive
(
:pull_mirrors_batch
).
with
(
hash_including
(
batch_size:
2
)).
ordered
.
and_call_original
schedule_mirrors!
(
capacity:
3
)
expect_import_scheduled
(
licensed_project1
,
licensed_project2
,
public_project
)
end
expect_import_not_scheduled
(
*
unlicensed_projects
)
end
end
context
'when capacity is insufficient'
do
it
'requests as many batches as necessary'
do
it
'schedules mirrors by next_execution_timestamp'
do
# The first batch will only contain 2 licensed mirrors, so we need to request another batch
schedule_mirrors!
(
capacity:
2
)
expect
(
subject
).
to
receive
(
:pull_mirrors_batch
).
with
(
hash_including
(
batch_size:
6
)).
ordered
.
and_call_original
expect
(
subject
).
to
receive
(
:pull_mirrors_batch
).
with
(
hash_including
(
batch_size:
2
)).
ordered
.
and_call_original
expect_import_scheduled
(
licensed_project1
,
licensed_project2
)
schedule_mirrors!
(
capacity:
3
)
e
xpect_import_not_scheduled
(
*
unlicensed_projects
,
licensed_project3
)
e
nd
end
end
it
'requests as many batches as necessary'
do
context
'when capacity is insufficient'
do
# The first batch will only contain 1 licensed mirror, so we need to request another batch
it
'schedules mirrors by next_execution_timestamp'
do
expect
(
subject
).
to
receive
(
:pull_mirrors_batch
).
with
(
hash_including
(
batch_size:
4
)).
ordered
.
and_call_original
schedule_mirrors!
(
capacity:
2
)
expect
(
subject
).
to
receive
(
:pull_mirrors_batch
).
with
(
hash_including
(
batch_size:
2
)).
ordered
.
and_call_original
schedule_mirrors!
(
capacity:
2
)
expect_import_scheduled
(
licensed_project1
,
licensed_project
2
)
end
expect_import_not_scheduled
(
*
unlicensed_projects
,
public_project
)
end
end
context
'when capacity is insufficient and the first batch is empty'
do
it
'requests as many batches as necessary'
do
it
'schedules mirrors by next_execution_timestamp'
do
# The first batch will only contain 1 licensed mirror, so we need to request another batch
schedule_mirrors!
(
capacity:
1
)
expect
(
subject
).
to
receive
(
:pull_mirrors_batch
).
with
(
hash_including
(
batch_size:
4
)).
ordered
.
and_call_original
expect
(
subject
).
to
receive
(
:pull_mirrors_batch
).
with
(
hash_including
(
batch_size:
2
)).
ordered
.
and_call_original
expect_import_scheduled
(
licensed_project1
)
schedule_mirrors!
(
capacity:
2
)
e
xpect_import_not_scheduled
(
*
unlicensed_projects
,
licensed_project2
,
licensed_project3
)
e
nd
end
end
it
'requests as many batches as necessary'
do
context
'when capacity is insufficient and the first batch is empty'
do
# The first batch will not contain any licensed mirrors, so we need to request another batch
it
'schedules mirrors by next_execution_timestamp'
do
expect
(
subject
).
to
receive
(
:pull_mirrors_batch
).
with
(
hash_including
(
batch_size:
2
)).
ordered
.
and_call_original
schedule_mirrors!
(
capacity:
1
)
expect
(
subject
).
to
receive
(
:pull_mirrors_batch
).
with
(
hash_including
(
batch_size:
2
)).
ordered
.
and_call_original
expect_import_scheduled
(
licensed_project1
)
expect_import_not_scheduled
(
*
unlicensed_projects
,
licensed_project2
,
public_project
)
end
it
'requests as many batches as necessary'
do
# The first batch will not contain any licensed mirrors, so we need to request another batch
expect
(
subject
).
to
receive
(
:pull_mirrors_batch
).
with
(
hash_including
(
batch_size:
2
)).
ordered
.
and_call_original
expect
(
subject
).
to
receive
(
:pull_mirrors_batch
).
with
(
hash_including
(
batch_size:
2
)).
ordered
.
and_call_original
schedule_mirrors!
(
capacity:
1
)
schedule_mirrors!
(
capacity:
1
)
end
end
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