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
Léo-Paul Géneau
gitlab-ce
Commits
7421604b
Commit
7421604b
authored
Mar 06, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce FailedToExtractError. Fix spec. Add DNS test mock.
parent
031794f5
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
10 deletions
+22
-10
app/services/projects/update_pages_service.rb
app/services/projects/update_pages_service.rb
+8
-7
spec/features/projects/jobs/user_browses_job_spec.rb
spec/features/projects/jobs/user_browses_job_spec.rb
+0
-2
spec/features/projects/pages_spec.rb
spec/features/projects/pages_spec.rb
+1
-1
spec/services/projects/update_pages_service_spec.rb
spec/services/projects/update_pages_service_spec.rb
+13
-0
No files found.
app/services/projects/update_pages_service.rb
View file @
7421604b
module
Projects
module
Projects
class
UpdatePagesService
<
BaseService
class
UpdatePagesService
<
BaseService
InvaildStateError
=
Class
.
new
(
StandardError
)
InvaildStateError
=
Class
.
new
(
StandardError
)
FailedToExtractError
=
Class
.
new
(
StandardError
)
BLOCK_SIZE
=
32
.
kilobytes
BLOCK_SIZE
=
32
.
kilobytes
MAX_SIZE
=
1
.
terabyte
MAX_SIZE
=
1
.
terabyte
...
@@ -30,13 +31,13 @@ module Projects
...
@@ -30,13 +31,13 @@ module Projects
# Check if we did extract public directory
# Check if we did extract public directory
archive_public_path
=
File
.
join
(
archive_path
,
'public'
)
archive_public_path
=
File
.
join
(
archive_path
,
'public'
)
raise
InvaildState
Error
,
'pages miss the public folder'
unless
Dir
.
exist?
(
archive_public_path
)
raise
FailedToExtract
Error
,
'pages miss the public folder'
unless
Dir
.
exist?
(
archive_public_path
)
raise
InvaildStateError
,
'pages are outdated'
unless
latest?
raise
InvaildStateError
,
'pages are outdated'
unless
latest?
deploy_page!
(
archive_public_path
)
deploy_page!
(
archive_public_path
)
success
success
end
end
rescue
InvaildStateError
=>
e
rescue
InvaildStateError
,
FailedToExtractError
=>
e
register_failure
register_failure
error
(
e
.
message
)
error
(
e
.
message
)
end
end
...
@@ -75,7 +76,7 @@ module Projects
...
@@ -75,7 +76,7 @@ module Projects
elsif
artifacts
.
ends_with?
(
'.zip'
)
elsif
artifacts
.
ends_with?
(
'.zip'
)
extract_zip_archive!
(
temp_path
)
extract_zip_archive!
(
temp_path
)
else
else
raise
'unsupported artifacts format'
raise
FailedToExtractError
,
'unsupported artifacts format'
end
end
end
end
...
@@ -84,17 +85,17 @@ module Projects
...
@@ -84,17 +85,17 @@ module Projects
%W(dd bs=
#{
BLOCK_SIZE
}
count=
#{
blocks
}
)
,
%W(dd bs=
#{
BLOCK_SIZE
}
count=
#{
blocks
}
)
,
%W(tar -x -C
#{
temp_path
}
#{
SITE_PATH
}
)
,
%W(tar -x -C
#{
temp_path
}
#{
SITE_PATH
}
)
,
err:
'/dev/null'
)
err:
'/dev/null'
)
raise
'pages failed to extract'
unless
results
.
compact
.
all?
(
&
:success?
)
raise
FailedToExtractError
,
'pages failed to extract'
unless
results
.
compact
.
all?
(
&
:success?
)
end
end
def
extract_zip_archive!
(
temp_path
)
def
extract_zip_archive!
(
temp_path
)
raise
'missing artifacts metadata'
unless
build
.
artifacts_metadata?
raise
FailedToExtractError
,
'missing artifacts metadata'
unless
build
.
artifacts_metadata?
# Calculate page size after extract
# Calculate page size after extract
public_entry
=
build
.
artifacts_metadata_entry
(
SITE_PATH
,
recursive:
true
)
public_entry
=
build
.
artifacts_metadata_entry
(
SITE_PATH
,
recursive:
true
)
if
public_entry
.
total_size
>
max_size
if
public_entry
.
total_size
>
max_size
raise
"artifacts for pages are too large:
#{
public_entry
.
total_size
}
"
raise
FailedToExtractError
,
"artifacts for pages are too large:
#{
public_entry
.
total_size
}
"
end
end
# Requires UnZip at least 6.00 Info-ZIP.
# Requires UnZip at least 6.00 Info-ZIP.
...
@@ -103,7 +104,7 @@ module Projects
...
@@ -103,7 +104,7 @@ module Projects
# We add * to end of SITE_PATH, because we want to extract SITE_PATH and all subdirectories
# We add * to end of SITE_PATH, because we want to extract SITE_PATH and all subdirectories
site_path
=
File
.
join
(
SITE_PATH
,
'*'
)
site_path
=
File
.
join
(
SITE_PATH
,
'*'
)
unless
system
(
*
%W(unzip -qq -n
#{
artifacts
}
#{
site_path
}
-d
#{
temp_path
}
)
)
unless
system
(
*
%W(unzip -qq -n
#{
artifacts
}
#{
site_path
}
-d
#{
temp_path
}
)
)
raise
'pages failed to extract'
raise
FailedToExtractError
,
'pages failed to extract'
end
end
end
end
...
...
spec/features/projects/jobs/user_browses_job_spec.rb
View file @
7421604b
...
@@ -31,7 +31,5 @@ describe 'User browses a job', :js do
...
@@ -31,7 +31,5 @@ describe 'User browses a job', :js do
page
.
within
(
'.erased'
)
do
page
.
within
(
'.erased'
)
do
expect
(
page
).
to
have_content
(
'Job has been erased'
)
expect
(
page
).
to
have_content
(
'Job has been erased'
)
end
end
expect
(
build
.
project
.
running_or_pending_build_count
).
to
eq
(
build
.
project
.
builds
.
running_or_pending
.
count
(
:all
))
end
end
end
end
spec/features/projects/pages_spec.rb
View file @
7421604b
...
@@ -258,7 +258,7 @@ feature 'Pages' do
...
@@ -258,7 +258,7 @@ feature 'Pages' do
end
end
let
(
:ci_build
)
do
let
(
:ci_build
)
do
build
(
create
(
:ci_build
,
:ci_build
,
project:
project
,
project:
project
,
pipeline:
pipeline
,
pipeline:
pipeline
,
...
...
spec/services/projects/update_pages_service_spec.rb
View file @
7421604b
...
@@ -34,6 +34,7 @@ describe Projects::UpdatePagesService do
...
@@ -34,6 +34,7 @@ describe Projects::UpdatePagesService do
context
'with expiry date'
do
context
'with expiry date'
do
before
do
before
do
build
.
artifacts_expire_in
=
"2 days"
build
.
artifacts_expire_in
=
"2 days"
build
.
save!
end
end
it
"doesn't delete artifacts"
do
it
"doesn't delete artifacts"
do
...
@@ -105,6 +106,7 @@ describe Projects::UpdatePagesService do
...
@@ -105,6 +106,7 @@ describe Projects::UpdatePagesService do
context
'with expiry date'
do
context
'with expiry date'
do
before
do
before
do
build
.
artifacts_expire_in
=
"2 days"
build
.
artifacts_expire_in
=
"2 days"
build
.
save!
end
end
it
"doesn't delete artifacts"
do
it
"doesn't delete artifacts"
do
...
@@ -159,6 +161,17 @@ describe Projects::UpdatePagesService do
...
@@ -159,6 +161,17 @@ describe Projects::UpdatePagesService do
expect
(
execute
).
not_to
eq
(
:success
)
expect
(
execute
).
not_to
eq
(
:success
)
end
end
context
'when timeout happens by DNS error'
do
before
do
allow_any_instance_of
(
Projects
::
UpdatePagesService
)
.
to
receive
(
:extract_zip_archive!
).
and_raise
(
SocketError
)
end
it
'raises an error'
do
expect
{
execute
}.
to
raise_error
(
SocketError
)
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