summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/ci/job_trace_chunk.rb10
-rw-r--r--lib/api/helpers/runner.rb1
-rw-r--r--lib/gitlab/ci/trace/chunked_io.rb10
-rw-r--r--spec/lib/gitlab/ci/trace/chunked_io_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/trace/stream_spec.rb2
5 files changed, 14 insertions, 13 deletions
diff --git a/app/models/ci/job_trace_chunk.rb b/app/models/ci/job_trace_chunk.rb
index 38374907e32..bec4405dbd6 100644
--- a/app/models/ci/job_trace_chunk.rb
+++ b/app/models/ci/job_trace_chunk.rb
@@ -9,7 +9,7 @@ module Ci
default_value_for :data_store, :redis
CHUNK_SIZE = 128.kilobytes
- CHUNK_REDIS_TTL = 1.month
+ CHUNK_REDIS_TTL = 1.day
enum data_store: {
redis: 1,
@@ -27,7 +27,7 @@ module Ci
end
def set_data(value)
- raise 'too much data' if value.bytesize > CHUNK_SIZE
+ raise ArgumentError, 'too much data' if value.bytesize > CHUNK_SIZE
if redis?
redis_set_data(value)
@@ -46,9 +46,9 @@ module Ci
end
def append(new_data, offset)
- current_data = self.data || ""
- raise 'Offset is out of bound' if offset > current_data.bytesize || offset < 0
- raise 'Outside of chunk size' if CHUNK_SIZE < offset + new_data.bytesize
+ 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
self.set_data(current_data.byteslice(0, offset) + new_data)
end
diff --git a/lib/api/helpers/runner.rb b/lib/api/helpers/runner.rb
index 382577cc931..35ac0b4cbca 100644
--- a/lib/api/helpers/runner.rb
+++ b/lib/api/helpers/runner.rb
@@ -52,7 +52,6 @@ module API
end
def job_token_valid?(job)
- # binding.pry
token = (params[JOB_TOKEN_PARAM] || env[JOB_TOKEN_HEADER]).to_s
token && job.valid_token?(token)
end
diff --git a/lib/gitlab/ci/trace/chunked_io.rb b/lib/gitlab/ci/trace/chunked_io.rb
index d768c011968..8dbe892df64 100644
--- a/lib/gitlab/ci/trace/chunked_io.rb
+++ b/lib/gitlab/ci/trace/chunked_io.rb
@@ -19,7 +19,7 @@ module Gitlab
@job = job
@chunks_cache = []
@tell = 0
- @size = job_chunks.last.try(&:end_offset).to_i
+ @size = calculate_size
yield self if block_given?
end
@@ -48,7 +48,7 @@ module Gitlab
-1
end
- raise 'new position is outside of file' if new_pos < 0 || new_pos > size
+ raise ArgumentError, 'new position is outside of file' if new_pos < 0 || new_pos > size
@tell = new_pos
end
@@ -135,7 +135,7 @@ module Gitlab
end
def truncate(offset)
- raise 'Outside of file' if offset > size
+ raise ArgumentError, 'Outside of file' if offset > size
@tell = offset
@size = offset
@@ -221,6 +221,10 @@ module Gitlab
def job_chunks
::Ci::JobTraceChunk.where(job: job)
end
+
+ def calculate_size
+ job_chunks.order(chunk_index: :desc).last.try(&:end_offset).to_i
+ end
end
end
end
diff --git a/spec/lib/gitlab/ci/trace/chunked_io_spec.rb b/spec/lib/gitlab/ci/trace/chunked_io_spec.rb
index 72211e82eab..bcef21d5f71 100644
--- a/spec/lib/gitlab/ci/trace/chunked_io_spec.rb
+++ b/spec/lib/gitlab/ci/trace/chunked_io_spec.rb
@@ -334,14 +334,12 @@ describe Gitlab::Ci::Trace::ChunkedIO, :clean_gitlab_redis_cache do
end
context "#truncate" do
- subject { chunked_io.truncate(offset) }
-
let(:offset) { 10 }
context 'when data does not exist' do
shared_examples 'truncates a trace' do
it do
- subject
+ chunked_io.truncate(offset)
chunked_io.seek(0, IO::SEEK_SET)
expect(chunked_io.read).to eq(sample_trace_raw.byteslice(0, offset))
diff --git a/spec/lib/gitlab/ci/trace/stream_spec.rb b/spec/lib/gitlab/ci/trace/stream_spec.rb
index e940a075cfe..7b6f5bf83ff 100644
--- a/spec/lib/gitlab/ci/trace/stream_spec.rb
+++ b/spec/lib/gitlab/ci/trace/stream_spec.rb
@@ -116,7 +116,7 @@ describe Gitlab::Ci::Trace::Stream, :clean_gitlab_redis_cache do
end
end
- context 'when stream is StringIO' do
+ context 'when stream is Tempfile' do
let(:tempfile) { Tempfile.new }
let(:stream) do