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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
4934f607
Commit
4934f607
authored
Oct 31, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
specs for workers.
parent
d6744d98
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
55 deletions
+33
-55
app/workers/cluster_provision_worker.rb
app/workers/cluster_provision_worker.rb
+2
-2
app/workers/wait_for_cluster_creation_worker.rb
app/workers/wait_for_cluster_creation_worker.rb
+2
-2
spec/workers/cluster_provision_worker_spec.rb
spec/workers/cluster_provision_worker_spec.rb
+15
-4
spec/workers/wait_for_cluster_creation_worker_spec.rb
spec/workers/wait_for_cluster_creation_worker_spec.rb
+14
-47
No files found.
app/workers/cluster_provision_worker.rb
View file @
4934f607
...
...
@@ -4,8 +4,8 @@ class ClusterProvisionWorker
def
perform
(
cluster_id
)
Clusters
::
Cluster
.
find_by_id
(
cluster_id
).
try
do
|
cluster
|
cluster
.
provider
_gcp
.
try
do
|
provider
|
Clusters
::
Gcp
::
ProvisionService
.
new
.
execute
(
provider
)
cluster
.
provider
.
try
do
|
provider
|
Clusters
::
Gcp
::
ProvisionService
.
new
.
execute
(
provider
)
if
cluster
.
gcp?
end
end
end
...
...
app/workers/wait_for_cluster_creation_worker.rb
View file @
4934f607
...
...
@@ -4,8 +4,8 @@ class WaitForClusterCreationWorker
def
perform
(
cluster_id
)
Clusters
::
Cluster
.
find_by_id
(
cluster_id
).
try
do
|
cluster
|
cluster
.
provider
_gcp
.
try
do
|
provider
|
Clusters
::
Gcp
::
VerifyProvisionStatusService
.
new
.
execute
(
provider
)
cluster
.
provider
.
try
do
|
provider
|
Clusters
::
Gcp
::
VerifyProvisionStatusService
.
new
.
execute
(
provider
)
if
cluster
.
gcp?
end
end
end
...
...
spec/workers/cluster_provision_worker_spec.rb
View file @
4934f607
...
...
@@ -2,11 +2,22 @@ require 'spec_helper'
describe
ClusterProvisionWorker
do
describe
'#perform'
do
context
'when cluster exists'
do
let
(
:cluster
)
{
create
(
:gcp_cluster
)
}
context
'when provider type is gcp'
do
let
(
:cluster
)
{
create
(
:cluster
,
provider_type: :gcp
,
provider_gcp:
provider
)
}
let
(
:provider
)
{
create
(
:provider_gcp
,
:scheduled
)
}
it
'provision a cluster'
do
expect_any_instance_of
(
Ci
::
ProvisionClusterService
).
to
receive
(
:execute
)
expect_any_instance_of
(
Clusters
::
Gcp
::
ProvisionService
).
to
receive
(
:execute
)
described_class
.
new
.
perform
(
cluster
.
id
)
end
end
context
'when provider type is user'
do
let
(
:cluster
)
{
create
(
:cluster
,
provider_type: :user
)
}
it
'does not provision a cluster'
do
expect_any_instance_of
(
Clusters
::
Gcp
::
ProvisionService
).
not_to
receive
(
:execute
)
described_class
.
new
.
perform
(
cluster
.
id
)
end
...
...
@@ -14,7 +25,7 @@ describe ClusterProvisionWorker do
context
'when cluster does not exist'
do
it
'does not provision a cluster'
do
expect_any_instance_of
(
C
i
::
ProvisionCluster
Service
).
not_to
receive
(
:execute
)
expect_any_instance_of
(
C
lusters
::
Gcp
::
Provision
Service
).
not_to
receive
(
:execute
)
described_class
.
new
.
perform
(
123
)
end
...
...
spec/workers/wait_for_cluster_creation_worker_spec.rb
View file @
4934f607
...
...
@@ -2,65 +2,32 @@ require 'spec_helper'
describe
WaitForClusterCreationWorker
do
describe
'#perform'
do
context
'when
cluster exists
'
do
let
(
:cluster
)
{
create
(
:
gcp_clust
er
)
}
let
(
:
operation
)
{
double
}
context
'when
provider type is gcp
'
do
let
(
:cluster
)
{
create
(
:
cluster
,
provider_type: :gcp
,
provider_gcp:
provid
er
)
}
let
(
:
provider
)
{
create
(
:provider_gcp
,
:creating
)
}
before
do
allow
(
operation
).
to
receive
(
:status
).
and_return
(
status
)
allow
(
operation
).
to
receive
(
:start_time
).
and_return
(
1
.
minute
.
ago
)
allow
(
operation
).
to
receive
(
:status_message
).
and_return
(
'error'
)
allow_any_instance_of
(
Ci
::
FetchGcpOperationService
).
to
receive
(
:execute
).
and_yield
(
operation
)
end
context
'when operation status is RUNNING'
do
let
(
:status
)
{
'RUNNING'
}
it
'reschedules worker'
do
expect
(
described_class
).
to
receive
(
:perform_in
)
described_class
.
new
.
perform
(
cluster
.
id
)
end
context
'when operation timeout'
do
before
do
allow
(
operation
).
to
receive
(
:start_time
).
and_return
(
30
.
minutes
.
ago
.
utc
)
end
it
'sets an error message on cluster'
do
described_class
.
new
.
perform
(
cluster
.
id
)
it
'provision a cluster'
do
expect_any_instance_of
(
Clusters
::
Gcp
::
VerifyProvisionStatusService
).
to
receive
(
:execute
)
expect
(
cluster
.
reload
).
to
be_errored
end
end
end
context
'when operation status is DONE'
do
let
(
:status
)
{
'DONE'
}
it
'finalizes cluster creation'
do
expect_any_instance_of
(
Ci
::
FinalizeClusterCreationService
).
to
receive
(
:execute
)
described_class
.
new
.
perform
(
cluster
.
id
)
end
described_class
.
new
.
perform
(
cluster
.
id
)
end
end
context
'when operation status is others
'
do
let
(
:status
)
{
'others'
}
context
'when provider type is user
'
do
let
(
:cluster
)
{
create
(
:cluster
,
provider_type: :user
)
}
it
'sets an error message on
cluster'
do
described_class
.
new
.
perform
(
cluster
.
id
)
it
'does not provision a
cluster'
do
expect_any_instance_of
(
Clusters
::
Gcp
::
VerifyProvisionStatusService
).
not_to
receive
(
:execute
)
expect
(
cluster
.
reload
).
to
be_errored
end
described_class
.
new
.
perform
(
cluster
.
id
)
end
end
context
'when cluster does not exist'
do
it
'does not provision a cluster'
do
expect_any_instance_of
(
C
i
::
FetchGcpOperation
Service
).
not_to
receive
(
:execute
)
expect_any_instance_of
(
C
lusters
::
Gcp
::
VerifyProvisionStatus
Service
).
not_to
receive
(
:execute
)
described_class
.
new
.
perform
(
123
4
)
described_class
.
new
.
perform
(
123
)
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