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
Tatuya Kamada
gitlab-ce
Commits
4dab79c5
Commit
4dab79c5
authored
Oct 27, 2016
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update the updated_at of a build while patching the trace
parent
b3616e30
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
5 deletions
+86
-5
app/models/ci/build.rb
app/models/ci/build.rb
+5
-0
spec/requests/ci/api/builds_spec.rb
spec/requests/ci/api/builds_spec.rb
+81
-5
No files found.
app/models/ci/build.rb
View file @
4dab79c5
...
@@ -271,6 +271,7 @@ module Ci
...
@@ -271,6 +271,7 @@ module Ci
def
append_trace
(
trace_part
,
offset
)
def
append_trace
(
trace_part
,
offset
)
recreate_trace_dir
recreate_trace_dir
touch
if
needs_touch?
trace_part
=
hide_secrets
(
trace_part
)
trace_part
=
hide_secrets
(
trace_part
)
...
@@ -280,6 +281,10 @@ module Ci
...
@@ -280,6 +281,10 @@ module Ci
end
end
end
end
def
needs_touch?
Time
.
now
-
updated_at
>
15
.
minutes
.
to_i
end
def
trace_file_path
def
trace_file_path
if
has_old_trace_file?
if
has_old_trace_file?
old_path_to_trace
old_path_to_trace
...
...
spec/requests/ci/api/builds_spec.rb
View file @
4dab79c5
...
@@ -213,26 +213,102 @@ describe Ci::API::API do
...
@@ -213,26 +213,102 @@ describe Ci::API::API do
let
(
:build
)
{
create
(
:ci_build
,
:pending
,
:trace
,
runner_id:
runner
.
id
)
}
let
(
:build
)
{
create
(
:ci_build
,
:pending
,
:trace
,
runner_id:
runner
.
id
)
}
let
(
:headers
)
{
{
Ci
::
API
::
Helpers
::
BUILD_TOKEN_HEADER
=>
build
.
token
,
'Content-Type'
=>
'text/plain'
}
}
let
(
:headers
)
{
{
Ci
::
API
::
Helpers
::
BUILD_TOKEN_HEADER
=>
build
.
token
,
'Content-Type'
=>
'text/plain'
}
}
let
(
:headers_with_range
)
{
headers
.
merge
({
'Content-Range'
=>
'11-20'
})
}
let
(
:headers_with_range
)
{
headers
.
merge
({
'Content-Range'
=>
'11-20'
})
}
let
(
:update_interval
)
{
10
.
seconds
.
to_i
}
def
patch_the_trace
(
content
=
' appended'
,
request_headers
=
nil
)
unless
request_headers
offset
=
build
.
trace_length
limit
=
offset
+
content
.
length
-
1
request_headers
=
headers
.
merge
({
'Content-Range'
=>
"
#{
offset
}
-
#{
limit
}
"
})
end
Timecop
.
travel
(
build
.
updated_at
+
update_interval
)
do
patch
ci_api
(
"/builds/
#{
build
.
id
}
/trace.txt"
),
content
,
request_headers
build
.
reload
end
end
def
initial_patch_the_trace
patch_the_trace
(
' appended'
,
headers_with_range
)
end
def
force_patch_the_trace
2
.
times
{
patch_the_trace
(
''
)
}
end
before
do
before
do
build
.
run!
build
.
run!
patch
ci_api
(
"/builds/
#{
build
.
id
}
/trace.txt"
),
' appended'
,
headers_with_rang
e
initial_patch_the_trac
e
end
end
context
'when request is valid'
do
context
'when request is valid'
do
it
'gets correct response'
do
it
'gets correct response'
do
expect
(
response
.
status
).
to
eq
202
expect
(
response
.
status
).
to
eq
202
expect
(
build
.
reload
.
trace
).
to
eq
'BUILD TRACE appended'
expect
(
response
.
header
).
to
have_key
'Range'
expect
(
response
.
header
).
to
have_key
'Range'
expect
(
response
.
header
).
to
have_key
'Build-Status'
expect
(
response
.
header
).
to
have_key
'Build-Status'
end
end
it
{
expect
(
build
.
reload
.
trace
).
to
eq
'BUILD TRACE appended'
}
context
'when build has been updated recently'
do
it
{
expect
{
patch_the_trace
}.
not_to
change
{
build
.
updated_at
}}
it
'changes the build trace'
do
patch_the_trace
expect
(
build
.
reload
.
trace
).
to
eq
'BUILD TRACE appended appended'
end
context
'when Runner makes a force-patch'
do
it
{
expect
{
force_patch_the_trace
}.
not_to
change
{
build
.
updated_at
}}
it
"doesn't change the build.trace"
do
force_patch_the_trace
expect
(
build
.
reload
.
trace
).
to
eq
'BUILD TRACE appended'
end
end
end
context
'when build was not updated recently'
do
let
(
:update_interval
)
{
15
.
minutes
.
to_i
}
it
{
expect
{
patch_the_trace
}.
to
change
{
build
.
updated_at
}
}
it
'changes the build.trace'
do
patch_the_trace
expect
(
build
.
reload
.
trace
).
to
eq
'BUILD TRACE appended appended'
end
context
'when Runner makes a force-patch'
do
it
{
expect
{
force_patch_the_trace
}.
to
change
{
build
.
updated_at
}
}
it
"doesn't change the build.trace"
do
force_patch_the_trace
expect
(
build
.
reload
.
trace
).
to
eq
'BUILD TRACE appended'
end
end
end
end
context
'when Runner makes a force-patch'
do
before
do
force_patch_the_trace
end
it
'gets correct response'
do
expect
(
response
.
status
).
to
eq
202
expect
(
build
.
reload
.
trace
).
to
eq
'BUILD TRACE appended'
expect
(
response
.
header
).
to
have_key
'Range'
expect
(
response
.
header
).
to
have_key
'Build-Status'
end
end
end
context
'when content-range start is too big'
do
context
'when content-range start is too big'
do
let
(
:headers_with_range
)
{
headers
.
merge
({
'Content-Range'
=>
'15-20'
})
}
let
(
:headers_with_range
)
{
headers
.
merge
({
'Content-Range'
=>
'15-20'
})
}
it
'gets
correct response
'
do
it
'gets
416 error response with range headers
'
do
expect
(
response
.
status
).
to
eq
416
expect
(
response
.
status
).
to
eq
416
expect
(
response
.
header
).
to
have_key
'Range'
expect
(
response
.
header
).
to
have_key
'Range'
expect
(
response
.
header
[
'Range'
]).
to
eq
'0-11'
expect
(
response
.
header
[
'Range'
]).
to
eq
'0-11'
...
@@ -242,7 +318,7 @@ describe Ci::API::API do
...
@@ -242,7 +318,7 @@ describe Ci::API::API do
context
'when content-range start is too small'
do
context
'when content-range start is too small'
do
let
(
:headers_with_range
)
{
headers
.
merge
({
'Content-Range'
=>
'8-20'
})
}
let
(
:headers_with_range
)
{
headers
.
merge
({
'Content-Range'
=>
'8-20'
})
}
it
'gets
correct response
'
do
it
'gets
416 error response with range headers
'
do
expect
(
response
.
status
).
to
eq
416
expect
(
response
.
status
).
to
eq
416
expect
(
response
.
header
).
to
have_key
'Range'
expect
(
response
.
header
).
to
have_key
'Range'
expect
(
response
.
header
[
'Range'
]).
to
eq
'0-11'
expect
(
response
.
header
[
'Range'
]).
to
eq
'0-11'
...
@@ -250,7 +326,7 @@ describe Ci::API::API do
...
@@ -250,7 +326,7 @@ describe Ci::API::API do
end
end
context
'when Content-Range header is missing'
do
context
'when Content-Range header is missing'
do
let
(
:headers_with_range
)
{
headers
.
merge
({})
}
let
(
:headers_with_range
)
{
headers
}
it
{
expect
(
response
.
status
).
to
eq
400
}
it
{
expect
(
response
.
status
).
to
eq
400
}
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