Commit 8a1c2bc4 authored by Shinya Maeda's avatar Shinya Maeda

Add tests for ChunkStore::Database too

parent 1a05c60e
......@@ -30,6 +30,10 @@ module Gitlab
raise NotImplementedError
end
def append!(data)
raise NotImplementedError
end
def truncate!(offset)
raise NotImplementedError
end
......
......@@ -15,6 +15,7 @@ module Gitlab
end
end
BUFFER_SIZE = 128.kilobytes
WriteError = Class.new(StandardError)
FailedToGetChunkError = Class.new(StandardError)
......@@ -134,6 +135,8 @@ module Gitlab
writable_space = BUFFER_SIZE - chunk_offset
writing_size = [writable_space, data.length].min
break unless writing_size > 0
if store.size > 0
written_size = store.append!(data.slice!(0...writing_size))
else
......@@ -228,7 +231,11 @@ module Gitlab
end
def chunks_count
(size / BUFFER_SIZE) + 1
(size / BUFFER_SIZE) + (has_extra? ? 1 : 0)
end
def has_extra?
(size % BUFFER_SIZE) > 0
end
def last_chunk?
......
......@@ -6,16 +6,19 @@ module ChunkedIOHelpers
end
def sample_trace_raw
@sample_trace_raw ||= File.read(expand_fixture_path('trace/sample_trace'))
if chunk_store == Gitlab::Ci::Trace::ChunkedFile::ChunkStore::Redis
File.read(expand_fixture_path('trace/sample_trace'))
else
'01234567' * 32
end
end
def sample_trace_size
sample_trace_raw.length
end
def stub_chunk_store_redis_get_failed
allow_any_instance_of(Gitlab::Ci::Trace::ChunkedFile::ChunkStore::Redis)
.to receive(:get).and_return(nil)
def stub_chunk_store_get_failed
allow_any_instance_of(chunk_store).to receive(:get).and_return(nil)
end
def set_smaller_buffer_size_than(file_size)
......
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