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
c1353c95
Commit
c1353c95
authored
May 13, 2021
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refact build queue service tests to improve readability
parent
9b9b6f05
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
45 deletions
+58
-45
spec/services/ci/update_build_queue_service_spec.rb
spec/services/ci/update_build_queue_service_spec.rb
+58
-45
No files found.
spec/services/ci/update_build_queue_service_spec.rb
View file @
c1353c95
...
...
@@ -8,76 +8,89 @@ RSpec.describe Ci::UpdateBuildQueueService do
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
describe
'#push'
do
it
'creates a new pending build in transaction'
do
transition
=
double
(
to:
'pending'
)
let
(
:transition
)
{
double
(
'transition'
)
}
before
do
allow
(
transition
).
to
receive
(
:to
).
and_return
(
'pending'
)
allow
(
transition
).
to
receive
(
:within_transaction
).
and_yield
end
queued
=
subject
.
push
(
build
,
transition
)
context
'when pending build can be created'
do
it
'creates a new pending build in transaction'
do
queued
=
subject
.
push
(
build
,
transition
)
expect
(
queued
.
build
).
to
eq
build
expect
(
queued
.
project
).
to
eq
project
end
expect
(
queued
.
build
).
to
eq
build
expect
(
queued
.
project
).
to
eq
project
end
it
'increments queue push metric'
do
metrics
=
spy
(
'metrics'
)
transition
=
double
(
to:
'pending'
)
allow
(
transition
).
to
receive
(
:within_transaction
).
and_yield
it
'increments queue push metric'
do
metrics
=
spy
(
'metrics'
)
described_class
.
new
(
metrics
).
push
(
build
,
transition
)
described_class
.
new
(
metrics
).
push
(
build
,
transition
)
expect
(
metrics
)
.
to
have_received
(
:increment_queue_operation
)
.
with
(
:build_queue_push
)
expect
(
metrics
)
.
to
have_received
(
:increment_queue_operation
)
.
with
(
:build_queue_push
)
end
end
it
'raises an error when invalid transition is detected'
do
transition
=
double
(
to:
'created'
)
context
'when invalid transition is detected'
do
it
'raises an error'
do
allow
(
transition
).
to
receive
(
:to
).
and_return
(
'created'
)
expect
{
subject
.
push
(
build
,
transition
)
}
.
to
raise_error
(
described_class
::
InvalidQueueTransition
)
expect
{
subject
.
push
(
build
,
transition
)
}
.
to
raise_error
(
described_class
::
InvalidQueueTransition
)
end
end
end
describe
'#pop'
do
it
'removes pending build in a transaction'
do
transition
=
double
(
from:
'pending'
)
let
(
:transition
)
{
double
(
'transition'
)
}
before
do
allow
(
transition
).
to
receive
(
:from
).
and_return
(
'pending'
)
allow
(
transition
).
to
receive
(
:within_transaction
).
and_yield
Ci
::
PendingBuild
.
create!
(
build:
build
,
project:
project
)
end
dequeued
=
subject
.
pop
(
build
,
transition
)
context
'when pending build exists'
do
before
do
Ci
::
PendingBuild
.
create!
(
build:
build
,
project:
project
)
end
expect
(
dequeued
.
build
).
to
eq
build
expect
(
dequeued
.
project
).
to
eq
project
expect
(
dequeued
).
to
be_destroyed
end
it
'removes pending build in a transaction'
do
dequeued
=
subject
.
pop
(
build
,
transition
)
it
'increments queue pop metric'
do
metrics
=
spy
(
'metrics'
)
transition
=
double
(
from:
'pending'
)
allow
(
transition
).
to
receive
(
:within_transaction
).
and_yield
Ci
::
PendingBuild
.
create!
(
build:
build
,
project:
project
)
expect
(
dequeued
.
build
).
to
eq
build
expect
(
dequeued
.
project
).
to
eq
project
expect
(
dequeued
).
to
be_destroyed
end
described_class
.
new
(
metrics
).
pop
(
build
,
transition
)
it
'increments queue pop metric'
do
metrics
=
spy
(
'metrics'
)
expect
(
metrics
)
.
to
have_received
(
:increment_queue_operation
)
.
with
(
:build_queue_pop
)
end
described_class
.
new
(
metrics
).
pop
(
build
,
transition
)
it
'does nothing if there is no pending build to remove'
do
transition
=
double
(
from:
'pending'
)
allow
(
transition
).
to
receive
(
:within_transaction
).
and_yield
expect
(
metrics
)
.
to
have_received
(
:increment_queue_operation
)
.
with
(
:build_queue_pop
)
end
end
dequeued
=
subject
.
pop
(
build
,
transition
)
context
'when pending build does not exist'
do
it
'does nothing if there is no pending build to remove'
do
dequeued
=
subject
.
pop
(
build
,
transition
)
expect
(
dequeued
).
to
be_nil
expect
(
dequeued
).
to
be_nil
end
end
it
'raises an error when invalid transition is detected'
do
transition
=
double
(
from:
'created'
)
context
'when invalid transition is detected'
do
it
'raises an error'
do
allow
(
transition
).
to
receive
(
:from
).
and_return
(
'created'
)
expect
{
subject
.
pop
(
build
,
transition
)
}
.
to
raise_error
(
described_class
::
InvalidQueueTransition
)
expect
{
subject
.
pop
(
build
,
transition
)
}
.
to
raise_error
(
described_class
::
InvalidQueueTransition
)
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