BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
7a509c26
Commit
7a509c26
authored
May 26, 2017
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '31556-ci-coverage-paralel-rspec' into 'master'
Return the last coverage in trace stream Closes #31556 See merge request !11128
parents
ce6bc061
f9c9daac
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
24 deletions
+74
-24
31556-ci-coverage-paralel-rspec.yml
changelogs/unreleased/31556-ci-coverage-paralel-rspec.yml
+4
-0
stream.rb
lib/gitlab/ci/trace/stream.rb
+28
-23
stream_spec.rb
spec/lib/gitlab/ci/trace/stream_spec.rb
+42
-1
No files found.
changelogs/unreleased/31556-ci-coverage-paralel-rspec.yml
0 → 100644
View file @
7a509c26
---
title
:
Fix the last coverage in trace log should be extracted
merge_request
:
11128
author
:
dosuken123
lib/gitlab/ci/trace/stream.rb
View file @
7a509c26
...
...
@@ -73,7 +73,7 @@ module Gitlab
match
=
""
stream
.
each
_line
do
|
line
|
reverse
_line
do
|
line
|
matches
=
line
.
scan
(
regex
)
next
unless
matches
.
is_a?
(
Array
)
next
if
matches
.
empty?
...
...
@@ -86,34 +86,39 @@ module Gitlab
nil
rescue
# if bad regex or something goes wrong we dont want to interrupt transition
# so we just silent
r
ly ignore error for now
# so we just silently ignore error for now
end
private
def
read_last_lines
(
last_lines
)
chunks
=
[]
pos
=
lines
=
0
max
=
stream
.
size
# We want an extra line to make sure fist line has full contents
while
lines
<=
last_lines
&&
pos
<
max
pos
+=
BUFFER_SIZE
buf
=
if
pos
<=
max
stream
.
seek
(
-
pos
,
IO
::
SEEK_END
)
stream
.
read
(
BUFFER_SIZE
)
else
# Reached the head, read only left
stream
.
seek
(
0
)
stream
.
read
(
BUFFER_SIZE
-
(
pos
-
max
))
end
lines
+=
buf
.
count
(
"
\n
"
)
chunks
.
unshift
(
buf
)
def
read_last_lines
(
limit
)
to_enum
(
:reverse_line
).
first
(
limit
).
reverse
.
join
end
def
reverse_line
stream
.
seek
(
0
,
IO
::
SEEK_END
)
debris
=
''
until
(
buf
=
read_backward
(
BUFFER_SIZE
)).
empty?
buf
+=
debris
debris
,
*
lines
=
buf
.
each_line
.
to_a
lines
.
reverse_each
do
|
line
|
yield
(
line
.
force_encoding
(
'UTF-8'
))
end
end
chunks
.
join
.
lines
.
last
(
last_lines
).
join
yield
(
debris
.
force_encoding
(
'UTF-8'
))
unless
debris
.
empty?
end
def
read_backward
(
length
)
cur_offset
=
stream
.
tell
start
=
cur_offset
-
length
start
=
0
if
start
<
0
stream
.
seek
(
start
,
IO
::
SEEK_SET
)
stream
.
read
(
cur_offset
-
start
).
tap
do
stream
.
seek
(
start
,
IO
::
SEEK_SET
)
end
end
end
end
...
...
spec/lib/gitlab/ci/trace/stream_spec.rb
View file @
7a509c26
...
...
@@ -240,9 +240,50 @@ describe Gitlab::Ci::Trace::Stream do
end
context
'multiple results in content & regex'
do
let
(
:data
)
{
' (98.39%) covered. (98.29%) covered'
}
let
(
:data
)
do
<<~
HEREDOC
(98.39%) covered
(98.29%) covered
HEREDOC
end
let
(
:regex
)
{
'\(\d+.\d+\%\) covered'
}
it
'returns the last matched coverage'
do
is_expected
.
to
eq
(
"98.29"
)
end
end
context
'when BUFFER_SIZE is smaller than stream.size'
do
let
(
:data
)
{
'Coverage 1033 / 1051 LOC (98.29%) covered\n'
}
let
(
:regex
)
{
'\(\d+.\d+\%\) covered'
}
before
do
stub_const
(
'Gitlab::Ci::Trace::Stream::BUFFER_SIZE'
,
5
)
end
it
{
is_expected
.
to
eq
(
"98.29"
)
}
end
context
'when regex is multi-byte char'
do
let
(
:data
)
{
'95.0 ゴッドファット\n'
}
let
(
:regex
)
{
'\d+\.\d+ ゴッドファット'
}
before
do
stub_const
(
'Gitlab::Ci::Trace::Stream::BUFFER_SIZE'
,
5
)
end
it
{
is_expected
.
to
eq
(
'95.0'
)
}
end
context
'when BUFFER_SIZE is equal to stream.size'
do
let
(
:data
)
{
'Coverage 1033 / 1051 LOC (98.29%) covered\n'
}
let
(
:regex
)
{
'\(\d+.\d+\%\) covered'
}
before
do
stub_const
(
'Gitlab::Ci::Trace::Stream::BUFFER_SIZE'
,
data
.
length
)
end
it
{
is_expected
.
to
eq
(
"98.29"
)
}
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