BigW Consortium Gitlab

Commit 7761afe0 by Kamil Trzciński

Merge branch 'fix-trace-seeking-readline' into 'master'

After Trace#limit, we seek to the next line in case Closes #30796 See merge request !10681
parents 992aafbc 0a3c98a7
---
title: Fix invalid encoding when showing some traces
merge_request: 10681
author:
...@@ -25,11 +25,10 @@ module Gitlab ...@@ -25,11 +25,10 @@ module Gitlab
end end
def limit(last_bytes = LIMIT_SIZE) def limit(last_bytes = LIMIT_SIZE)
stream_size = size if last_bytes < size
if stream_size < last_bytes stream.seek(-last_bytes, IO::SEEK_END)
last_bytes = stream_size stream.readline
end end
stream.seek(-last_bytes, IO::SEEK_END)
end end
def append(data, offset) def append(data, offset)
......
.
..
😺
ヾ(´༎ຶД༎ຶ`)ノ
許功蓋
...@@ -17,12 +17,12 @@ describe Gitlab::Ci::Trace::Stream do ...@@ -17,12 +17,12 @@ describe Gitlab::Ci::Trace::Stream do
describe '#limit' do describe '#limit' do
let(:stream) do let(:stream) do
described_class.new do described_class.new do
StringIO.new("12345678") StringIO.new((1..8).to_a.join("\n"))
end end
end end
it 'if size is larger we start from beggining' do it 'if size is larger we start from beginning' do
stream.limit(10) stream.limit(20)
expect(stream.tell).to eq(0) expect(stream.tell).to eq(0)
end end
...@@ -30,7 +30,27 @@ describe Gitlab::Ci::Trace::Stream do ...@@ -30,7 +30,27 @@ describe Gitlab::Ci::Trace::Stream do
it 'if size is smaller we start from the end' do it 'if size is smaller we start from the end' do
stream.limit(2) stream.limit(2)
expect(stream.tell).to eq(6) expect(stream.raw).to eq("8")
end
context 'when the trace contains ANSI sequence and Unicode' do
let(:stream) do
described_class.new do
File.open(expand_fixture_path('trace/ansi-sequence-and-unicode'))
end
end
it 'forwards to the next linefeed, case 1' do
stream.limit(7)
expect(stream.raw).to eq('')
end
it 'forwards to the next linefeed, case 2' do
stream.limit(29)
expect(stream.raw).to eq("\e[01;32m許功蓋\e[0m\n")
end
end end
end end
......
module FixtureHelpers module FixtureHelpers
def fixture_file(filename) def fixture_file(filename)
return '' if filename.blank? return '' if filename.blank?
file_path = File.expand_path(Rails.root.join('spec/fixtures/', filename)) File.read(expand_fixture_path(filename))
File.read(file_path) end
def expand_fixture_path(filename)
File.expand_path(Rails.root.join('spec/fixtures/', filename))
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment