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
d832d1f0
Commit
d832d1f0
authored
Sep 28, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve and add specs for CI/CD Quotas/Limits classes
parent
39a7103d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
208 additions
and
32 deletions
+208
-32
ee/lib/ee/gitlab/ci/pipeline/chain/limit/activity.rb
ee/lib/ee/gitlab/ci/pipeline/chain/limit/activity.rb
+30
-16
ee/lib/ee/gitlab/ci/pipeline/chain/limit/size.rb
ee/lib/ee/gitlab/ci/pipeline/chain/limit/size.rb
+20
-16
spec/ee/spec/lib/gitlab/ci/pipeline/chain/limit/activity_spec.rb
.../spec/lib/gitlab/ci/pipeline/chain/limit/activity_spec.rb
+69
-0
spec/ee/spec/lib/gitlab/ci/pipeline/chain/limit/size_spec.rb
spec/ee/spec/lib/gitlab/ci/pipeline/chain/limit/size_spec.rb
+89
-0
No files found.
ee/lib/ee/gitlab/ci/pipeline/chain/limit/activity.rb
View file @
d832d1f0
...
...
@@ -3,27 +3,41 @@ module EE
module
Ci
module
Pipeline
module
Chain
class
Activity
<
::
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Base
include
::
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Helpers
module
Limit
class
Activity
<
::
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Base
include
::
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Helpers
include
::
Gitlab
::
OptimisticLocking
def
initialize
(
*
)
super
def
initialize
(
*
)
super
@limit
=
Pipeline
::
Quota
::
Activity
.
new
(
project
.
namespace
,
pipeline
.
project
)
end
@limit
=
Pipeline
::
Quota
::
Activity
.
new
(
project
.
namespace
,
pipeline
.
project
)
end
def
perform!
return
unless
@limit
.
exceeded?
return
unless
@command
.
save_incompleted
def
perform!
return
unless
@limit
.
exceeded?
# TODO, add failure reason
# TODO, add validation error
@pipeline
.
drop
end
# TODO, add failure reason
# TODO, transaction?
@pipeline
.
cancel_running
retry_optimistic_lock
(
@pipeline
)
@pipeline
.
drop!
end
# TODO, should we invalidate the pipeline
# while it is already persisted?
#
# Should we show info in the UI or alert/warning?
#
error
(
@limit
.
message
)
end
def
break?
@limit
.
exceeded?
def
break?
@limit
.
exceeded?
end
end
end
end
...
...
ee/lib/ee/gitlab/ci/pipeline/chain/limit/size.rb
View file @
d832d1f0
...
...
@@ -3,27 +3,31 @@ module EE
module
Ci
module
Pipeline
module
Chain
class
Size
<
::
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Base
include
::
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Helpers
module
Limit
class
Size
<
::
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Base
include
::
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Helpers
def
initialize
(
*
)
super
def
initialize
(
*
)
super
@limit
=
Pipeline
::
Quota
::
Size
.
new
(
project
.
namespace
,
pipeline
)
end
@limit
=
Pipeline
::
Quota
::
Size
.
new
(
project
.
namespace
,
pipeline
)
end
def
perform!
return
unless
@limit
.
exceeded?
return
unless
@command
.
save_incompleted
def
perform!
return
unless
@limit
.
exceeded?
# TODO, add failure reason
# TODO, add validation error
@pipeline
.
drop
end
if
@command
.
save_incompleted
# TODO, add failure reason
@pipeline
.
drop
end
error
(
@limit
.
message
)
end
def
break?
@limit
.
exceeded?
def
break?
@limit
.
exceeded?
end
end
end
end
...
...
spec/ee/spec/lib/gitlab/ci/pipeline/chain/limit/activity_spec.rb
0 → 100644
View file @
d832d1f0
require
'spec_helper'
describe
EE
::
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Limit
::
Activity
do
set
(
:namespace
)
{
create
(
:namespace
,
plan:
Namespace
::
GOLD_PLAN
)
}
set
(
:project
)
{
create
(
:project
,
namespace:
namespace
)
}
set
(
:user
)
{
create
(
:user
)
}
let
(
:command
)
do
double
(
'command'
,
project:
project
,
current_user:
user
)
end
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
project:
project
)
end
before
do
create
(
:ci_build
,
pipeline:
pipeline
)
end
let
(
:step
)
{
described_class
.
new
(
pipeline
,
command
)
}
context
'when active pipelines limit is exceeded'
do
before
do
project
.
namespace
.
plan
.
update_column
(
:active_pipelines_limit
,
1
)
create
(
:ci_pipeline
,
project:
project
,
status:
'pending'
)
create
(
:ci_pipeline
,
project:
project
,
status:
'running'
)
step
.
perform!
end
it
'drops the pipeline'
do
expect
(
pipeline
.
reload
).
to
be_failed
end
it
'persists the pipeline'
do
expect
(
pipeline
).
to
be_persisted
end
it
'cancels all pipeline jobs'
do
expect
(
pipeline
.
statuses
).
not_to
be_empty
expect
(
pipeline
.
statuses
).
to
all
(
be_canceled
)
end
it
'breaks the chain'
do
expect
(
step
.
break?
).
to
be
true
end
it
'appends validation error'
do
expect
(
pipeline
.
errors
.
to_a
)
.
to
include
'Active pipelines limit exceeded by 2 pipelines!'
end
end
context
'when pipeline size limit is not exceeded'
do
before
do
step
.
perform!
end
it
'does not break the chain'
do
expect
(
step
.
break?
).
to
be
false
end
it
'does not invalidate the pipeline'
do
expect
(
pipeline
.
errors
).
to
be_empty
end
end
end
spec/ee/spec/lib/gitlab/ci/pipeline/chain/limit/size_spec.rb
0 → 100644
View file @
d832d1f0
require
'spec_helper'
describe
EE
::
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Limit
::
Size
do
set
(
:namespace
)
{
create
(
:namespace
,
plan:
Namespace
::
GOLD_PLAN
)
}
set
(
:project
)
{
create
(
:project
,
namespace:
namespace
)
}
set
(
:user
)
{
create
(
:user
)
}
let
(
:pipeline
)
do
build
(
:ci_pipeline_with_one_job
,
project:
project
,
ref:
'master'
)
end
let
(
:command
)
do
double
(
'command'
,
project:
project
,
current_user:
user
)
end
let
(
:step
)
{
described_class
.
new
(
pipeline
,
command
)
}
context
'when pipeline size limit is exceeded'
do
before
do
project
.
namespace
.
plan
.
update_column
(
:pipeline_size_limit
,
1
)
step
.
perform!
end
let
(
:pipeline
)
do
config
=
{
rspec:
{
script:
'rspec'
},
spinach:
{
script:
'spinach'
}
}
create
(
:ci_pipeline
,
project:
project
,
config:
config
)
end
context
'when saving incomplete pipelines'
do
let
(
:command
)
do
double
(
'command'
,
project:
project
,
current_user:
user
,
save_incompleted:
true
)
end
it
'drops the pipeline'
do
expect
(
pipeline
.
reload
).
to
be_failed
end
it
'persists the pipeline'
do
expect
(
pipeline
).
to
be_persisted
end
it
'breaks the chain'
do
expect
(
step
.
break?
).
to
be
true
end
it
'appends validation error'
do
expect
(
pipeline
.
errors
.
to_a
)
.
to
include
'Pipeline size limit exceeded by 1 job!'
end
end
context
'when not saving incomplete pipelines'
do
let
(
:command
)
do
double
(
'command'
,
project:
project
,
current_user:
user
,
save_incompleted:
false
)
end
it
'does not drop the pipeline'
do
expect
(
pipeline
).
not_to
be_failed
end
it
'breaks the chain'
do
expect
(
step
.
break?
).
to
be
true
end
end
end
context
'when pipeline size limit is not exceeded'
do
before
do
step
.
perform!
end
it
'does not break the chain'
do
expect
(
step
.
break?
).
to
be
false
end
it
'does not persist the pipeline'
do
expect
(
pipeline
).
not_to
be_persisted
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