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
23c8e198
Commit
23c8e198
authored
Apr 30, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix spec. Revert #truncate in stream (But still prevent redandant calls)
parent
0d99298a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
30 deletions
+27
-30
app/models/ci/build_trace_chunk.rb
app/models/ci/build_trace_chunk.rb
+4
-5
lib/gitlab/ci/trace/stream.rb
lib/gitlab/ci/trace/stream.rb
+1
-0
spec/factories/ci/build_trace_chunks.rb
spec/factories/ci/build_trace_chunks.rb
+1
-1
spec/models/ci/build_trace_chunk_spec.rb
spec/models/ci/build_trace_chunk_spec.rb
+20
-23
spec/services/ci/retry_build_service_spec.rb
spec/services/ci/retry_build_service_spec.rb
+1
-1
No files found.
app/models/ci/build_trace_chunk.rb
View file @
23c8e198
...
...
@@ -24,7 +24,7 @@ module Ci
##
# Data is memoized for optimizing #size and #end_offset
def
data
@data
||=
get_data
@data
||=
get_data
.
to_s
end
def
truncate
(
offset
=
0
)
...
...
@@ -32,11 +32,10 @@ module Ci
end
def
append
(
new_data
,
offset
)
current_data
=
self
.
data
.
to_s
raise
ArgumentError
,
'Offset is out of bound'
if
offset
>
current_data
.
bytesize
||
offset
<
0
raise
ArgumentError
,
'Outside of chunk size'
if
CHUNK_SIZE
<
offset
+
new_data
.
bytesize
raise
ArgumentError
,
'Offset is out of range'
if
offset
>
data
.
bytesize
||
offset
<
0
raise
ArgumentError
,
'Chunk size overflow'
if
CHUNK_SIZE
<
(
offset
+
new_data
.
bytesize
)
set_data
(
current_
data
.
byteslice
(
0
,
offset
)
+
new_data
)
set_data
(
data
.
byteslice
(
0
,
offset
)
+
new_data
)
end
def
size
...
...
lib/gitlab/ci/trace/stream.rb
View file @
23c8e198
...
...
@@ -52,6 +52,7 @@ module Gitlab
stream
.
seek
(
0
,
IO
::
SEEK_SET
)
stream
.
write
(
data
)
stream
.
truncate
(
data
.
bytesize
)
stream
.
flush
()
end
...
...
spec/factories/ci/build_trace_chunks.rb
View file @
23c8e198
FactoryBot
.
define
do
factory
:ci_build_trace_chunk
,
class:
Ci
::
BuildTraceChunk
do
job
factory: :ci_build
build
factory: :ci_build
chunk_index
0
data_store
:redis
end
...
...
spec/models/ci/build_trace_chunk_spec.rb
View file @
23c8e198
...
...
@@ -46,7 +46,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
end
describe
'#set_data'
do
subject
{
build_trace_chunk
.
se
t_data
(
value
)
}
subject
{
build_trace_chunk
.
se
nd
(
:set_data
,
value
)
}
let
(
:value
)
{
'Sample data'
}
...
...
@@ -131,13 +131,17 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
context
'when offset is negative'
do
let
(
:offset
)
{
-
1
}
it
{
expect
{
subject
}.
to
raise_error
(
'Offset is out of
bound
'
)
}
it
{
expect
{
subject
}.
to
raise_error
(
'Offset is out of
range
'
)
}
end
context
'when offset is bigger than data size'
do
let
(
:offset
)
{
data
.
bytesize
+
1
}
it
{
expect
{
subject
}.
to
raise_error
(
'Offset is out of bound'
)
}
it
do
expect_any_instance_of
(
described_class
).
not_to
receive
(
:append
)
{
}
subject
end
end
context
'when offset is 10'
do
...
...
@@ -182,19 +186,19 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
context
'when offset is negative'
do
let
(
:offset
)
{
-
1
}
it
{
expect
{
subject
}.
to
raise_error
(
'Offset is out of
bound
'
)
}
it
{
expect
{
subject
}.
to
raise_error
(
'Offset is out of
range
'
)
}
end
context
'when offset is bigger than data size'
do
let
(
:offset
)
{
data
.
bytesize
+
1
}
it
{
expect
{
subject
}.
to
raise_error
(
'Offset is out of
bound
'
)
}
it
{
expect
{
subject
}.
to
raise_error
(
'Offset is out of
range
'
)
}
end
context
'when offset is bigger than data size'
do
let
(
:new_data
)
{
'a'
*
(
described_class
::
CHUNK_SIZE
+
1
)
}
it
{
expect
{
subject
}.
to
raise_error
(
'
Outside of chunk size
'
)
}
it
{
expect
{
subject
}.
to
raise_error
(
'
Chunk size overflow
'
)
}
end
context
'when offset is EOF'
do
...
...
@@ -320,7 +324,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
describe
'ExclusiveLock'
do
before
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
)
{
nil
}
stub_const
(
'Ci::BuildTraceChunk::LOCK_RETRY'
,
1
)
stub_const
(
'Ci::BuildTraceChunk::
WRITE_
LOCK_RETRY'
,
1
)
end
it
'raise an error'
do
...
...
@@ -333,30 +337,31 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
before
do
pipeline
=
create
(
:ci_pipeline
,
project:
project
)
create
(
:ci_build
,
:running
,
:trace_live
,
pipeline:
pipeline
,
project:
project
)
create
(
:ci_build
,
:running
,
:trace_live
,
pipeline:
pipeline
,
project:
project
)
create
(
:ci_build
,
:running
,
:trace_live
,
pipeline:
pipeline
,
project:
project
)
@build_ids
=
[]
@build_ids
<<
create
(
:ci_build
,
:running
,
:trace_live
,
pipeline:
pipeline
,
project:
project
).
id
@build_ids
<<
create
(
:ci_build
,
:running
,
:trace_live
,
pipeline:
pipeline
,
project:
project
).
id
@build_ids
<<
create
(
:ci_build
,
:running
,
:trace_live
,
pipeline:
pipeline
,
project:
project
).
id
end
shared_examples_for
'deletes all build_trace_chunk and data in redis'
do
it
do
project
.
builds
.
each
do
|
buil
d
|
@build_ids
.
each
do
|
build_i
d
|
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
redis
.
scan_each
(
match:
"gitlab:ci:trace:
#{
build
.
id
}
:chunks:?"
)
do
|
key
|
redis
.
scan_each
(
match:
"gitlab:ci:trace:
#{
build
_
id
}
:chunks:?"
)
do
|
key
|
expect
(
redis
.
exists
(
key
)).
to
be_truthy
end
end
end
expect
(
described_class
.
count
).
not_to
eq
(
0
)
expect
(
described_class
.
count
).
to
eq
(
3
)
subject
expect
(
described_class
.
count
).
to
eq
(
0
)
project
.
builds
.
each
do
|
buil
d
|
@build_ids
.
each
do
|
build_i
d
|
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
redis
.
scan_each
(
match:
"gitlab:ci:trace:
#{
build
.
id
}
:chunks:?"
)
do
|
key
|
redis
.
scan_each
(
match:
"gitlab:ci:trace:
#{
build
_
id
}
:chunks:?"
)
do
|
key
|
expect
(
redis
.
exists
(
key
)).
to
be_falsey
end
end
...
...
@@ -364,14 +369,6 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
end
end
context
'when build_trace_chunk is destroyed'
do
let
(
:subject
)
do
project
.
builds
.
each
{
|
build
|
build
.
chunks
.
destroy_all
}
end
it_behaves_like
'deletes all build_trace_chunk and data in redis'
end
context
'when build is destroyed'
do
let
(
:subject
)
do
project
.
builds
.
destroy_all
...
...
spec/services/ci/retry_build_service_spec.rb
View file @
23c8e198
...
...
@@ -30,7 +30,7 @@ describe Ci::RetryBuildService do
runner_id tag_taggings taggings tags trigger_request_id
user_id auto_canceled_by_id retried failure_reason
artifacts_file_store artifacts_metadata_store
metadata chunks]
.
freeze
metadata
trace_
chunks]
.
freeze
shared_examples
'build duplication'
do
let
(
:another_pipeline
)
{
create
(
:ci_empty_pipeline
,
project:
project
)
}
...
...
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