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
682b94d1
Commit
682b94d1
authored
Apr 21, 2020
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert request specs to unit for EE::PostReceiveService
parent
eca8d9af
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
61 deletions
+103
-61
ee/spec/requests/api/internal/base_spec.rb
ee/spec/requests/api/internal/base_spec.rb
+0
-61
ee/spec/services/ee/post_receive_service_spec.rb
ee/spec/services/ee/post_receive_service_spec.rb
+103
-0
No files found.
ee/spec/requests/api/internal/base_spec.rb
View file @
682b94d1
...
@@ -52,53 +52,6 @@ describe API::Internal::Base do
...
@@ -52,53 +52,6 @@ describe API::Internal::Base do
expect
(
git_push_http
).
to
receive
(
:fetch_referrer_node
).
and_return
(
secondary_node
)
expect
(
git_push_http
).
to
receive
(
:fetch_referrer_node
).
and_return
(
secondary_node
)
end
end
context
'when the secondary has a GeoNodeStatus'
do
context
'when the GeoNodeStatus db_replication_lag_seconds is greater than 0'
do
let!
(
:status
)
{
create
(
:geo_node_status
,
geo_node:
secondary_node
,
db_replication_lag_seconds:
17
)
}
it
'includes current Geo secondary lag in the output'
do
post
api
(
'/internal/post_receive'
),
params:
valid_params
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'messages'
]).
to
include
({
'type'
=>
'basic'
,
'message'
=>
"Current replication lag: 17 seconds"
})
end
end
context
'when the GeoNodeStatus db_replication_lag_seconds is 0'
do
let!
(
:status
)
{
create
(
:geo_node_status
,
geo_node:
secondary_node
,
db_replication_lag_seconds:
0
)
}
it
'does not include current Geo secondary lag in the output'
do
post
api
(
'/internal/post_receive'
),
params:
valid_params
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'messages'
]).
not_to
include
({
'message'
=>
a_string_matching
(
'replication lag'
),
'type'
=>
anything
})
end
end
context
'when the GeoNodeStatus db_replication_lag_seconds is nil'
do
let!
(
:status
)
{
create
(
:geo_node_status
,
geo_node:
secondary_node
,
db_replication_lag_seconds:
nil
)
}
it
'does not include current Geo secondary lag in the output'
do
post
api
(
'/internal/post_receive'
),
params:
valid_params
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'messages'
]).
not_to
include
({
'message'
=>
a_string_matching
(
'replication lag'
),
'type'
=>
anything
})
end
end
end
context
'when the secondary does not have a GeoNodeStatus'
do
it
'does not include current Geo secondary lag in the output'
do
post
api
(
'/internal/post_receive'
),
params:
valid_params
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'messages'
]).
not_to
include
({
'message'
=>
a_string_matching
(
'replication lag'
),
'type'
=>
anything
})
end
end
it
'includes a message advising a redirection occurred'
do
it
'includes a message advising a redirection occurred'
do
redirect_message
=
<<~
STR
redirect_message
=
<<~
STR
This request to a Geo secondary node will be forwarded to the
This request to a Geo secondary node will be forwarded to the
...
@@ -116,20 +69,6 @@ describe API::Internal::Base do
...
@@ -116,20 +69,6 @@ describe API::Internal::Base do
})
})
end
end
end
end
context
'when the push was not redirected from a Geo secondary to the primary'
do
before
do
expect
(
Gitlab
::
Geo
::
GitPushHttp
).
to
receive
(
:new
).
with
(
identifier
,
gl_repository
).
and_return
(
git_push_http
)
expect
(
git_push_http
).
to
receive
(
:fetch_referrer_node
).
and_return
(
nil
)
end
it
'does not include current Geo secondary lag in the output'
do
post
api
(
'/internal/post_receive'
),
params:
valid_params
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'messages'
]).
not_to
include
({
'message'
=>
a_string_matching
(
'replication lag'
),
'type'
=>
anything
})
end
end
end
end
describe
"POST /internal/allowed"
do
describe
"POST /internal/allowed"
do
...
...
ee/spec/services/ee/post_receive_service_spec.rb
0 → 100644
View file @
682b94d1
# frozen_string_literal: true
require
'spec_helper'
describe
PostReceiveService
,
:geo
do
include
EE
::
GeoHelpers
let_it_be
(
:primary_url
)
{
'http://primary.example.com'
}
let_it_be
(
:secondary_url
)
{
'http://secondary.example.com'
}
let_it_be
(
:primary_node
,
reload:
true
)
{
create
(
:geo_node
,
:primary
,
url:
primary_url
)
}
let_it_be
(
:secondary_node
,
reload:
true
)
{
create
(
:geo_node
,
url:
secondary_url
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:gl_repository
)
{
"project-
#{
project
.
id
}
"
}
let
(
:repository
)
{
project
.
repository
}
let
(
:identifier
)
{
'key-123'
}
let
(
:git_push_http
)
{
double
(
'GitPushHttp'
)
}
let
(
:params
)
do
{
gl_repository:
gl_repository
,
identifier:
identifier
,
changes:
[]
}
end
subject
do
service
=
described_class
.
new
(
user
,
repository
,
project
,
params
)
service
.
execute
.
messages
.
as_json
end
before
do
stub_current_geo_node
(
primary_node
)
allow
(
Gitlab
::
Geo
::
GitPushHttp
).
to
receive
(
:new
).
with
(
identifier
,
gl_repository
).
and_return
(
git_push_http
)
allow
(
git_push_http
).
to
receive
(
:fetch_referrer_node
).
and_return
(
node
)
end
context
'when the push was redirected from a Geo secondary to the primary'
do
let
(
:node
)
{
secondary_node
}
context
'when the secondary has a GeoNodeStatus'
do
let!
(
:status
)
{
create
(
:geo_node_status
,
geo_node:
secondary_node
,
db_replication_lag_seconds:
db_replication_lag_seconds
)
}
context
'when the GeoNodeStatus db_replication_lag_seconds is greater than 0'
do
let
(
:db_replication_lag_seconds
)
{
17
}
it
'includes current Geo secondary lag in the output'
do
expect
(
subject
).
to
include
({
'type'
=>
'basic'
,
'message'
=>
"Current replication lag: 17 seconds"
})
end
end
context
'when the GeoNodeStatus db_replication_lag_seconds is 0'
do
let
(
:db_replication_lag_seconds
)
{
0
}
it
'does not include current Geo secondary lag in the output'
do
expect
(
subject
).
not_to
include
({
'message'
=>
a_string_matching
(
'replication lag'
),
'type'
=>
anything
})
end
end
context
'when the GeoNodeStatus db_replication_lag_seconds is nil'
do
let
(
:db_replication_lag_seconds
)
{
nil
}
it
'does not include current Geo secondary lag in the output'
do
expect
(
subject
).
not_to
include
({
'message'
=>
a_string_matching
(
'replication lag'
),
'type'
=>
anything
})
end
end
end
context
'when the secondary does not have a GeoNodeStatus'
do
it
'does not include current Geo secondary lag in the output'
do
expect
(
subject
).
not_to
include
({
'message'
=>
a_string_matching
(
'replication lag'
),
'type'
=>
anything
})
end
end
it
'includes a message advising a redirection occurred'
do
redirect_message
=
<<~
STR
This request to a Geo secondary node will be forwarded to the
Geo primary node:
http://primary.example.com/
#{
project
.
full_path
}
.git
STR
expect
(
subject
).
to
include
({
'type'
=>
'basic'
,
'message'
=>
redirect_message
})
end
end
context
'when the push was not redirected from a Geo secondary to the primary'
do
let
(
:node
)
{
nil
}
it
'does not include current Geo secondary lag in the output'
do
expect
(
subject
).
not_to
include
({
'message'
=>
a_string_matching
(
'replication lag'
),
'type'
=>
anything
})
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