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

Add tests for ChunkStore::Database too

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