summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-06-25 19:59:28 +0900
committerShinya Maeda <shinya@gitlab.com>2018-06-25 19:59:28 +0900
commit58a1a0b70c7df0947864d0be933faf0153b537ec (patch)
tree12981201dfc7b9258bdd0bb4bbcdaa035e4475ff
parent44cc58765242afc2e035c2972447be2afae8d153 (diff)
downloadgitlab-ce-58a1a0b70c7df0947864d0be933faf0153b537ec.tar.gz
Support append/truncate for fog storebuild-chunks-on-object-storage
-rw-r--r--app/models/ci/build_trace_chunk.rb4
-rw-r--r--spec/models/ci/build_trace_chunk_spec.rb39
2 files changed, 32 insertions, 11 deletions
diff --git a/app/models/ci/build_trace_chunk.rb b/app/models/ci/build_trace_chunk.rb
index 8a34db798db..4362570b5ee 100644
--- a/app/models/ci/build_trace_chunk.rb
+++ b/app/models/ci/build_trace_chunk.rb
@@ -63,7 +63,6 @@ module Ci
end
def truncate(offset = 0)
- raise ArgumentError, 'Fog store does not support truncating' if fog? # If data is null, get_data returns Excon::Error::NotFound
raise ArgumentError, 'Offset is out of range' if offset > size || offset < 0
return if offset == size # Skip the following process as it doesn't affect anything
@@ -71,7 +70,6 @@ module Ci
end
def append(new_data, offset)
- raise ArgumentError, 'Fog store does not support appending' if fog? # If data is null, get_data returns Excon::Error::NotFound
raise ArgumentError, 'New data is nil' unless new_data
raise ArgumentError, 'Offset is out of range' if offset > size || offset < 0
raise ArgumentError, 'Chunk size overflow' if CHUNK_SIZE < (offset + new_data.bytesize)
@@ -124,6 +122,8 @@ module Ci
def get_data
self.class.get_store_class(data_store).data(self)&.force_encoding(Encoding::BINARY) # Redis/Database return UTF-8 string as default
+ rescue Excon::Error::NotFound
+ # If the data store is :fog and the file does not exist in the object storage, this method returns nil.
end
def unsafe_set_data!(value)
diff --git a/spec/models/ci/build_trace_chunk_spec.rb b/spec/models/ci/build_trace_chunk_spec.rb
index 2b4dfba5c2a..94a5fe8e5f8 100644
--- a/spec/models/ci/build_trace_chunk_spec.rb
+++ b/spec/models/ci/build_trace_chunk_spec.rb
@@ -256,11 +256,31 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
context 'when data_store is fog' do
let(:data_store) { :fog }
- let(:data) { '' }
- let(:offset) { 0 }
- it 'can not append' do
- expect { subject }.to raise_error('Fog store does not support appending')
+ context 'when there are no data' do
+ let(:data) { '' }
+
+ it 'has no data' do
+ expect(build_trace_chunk.data).to be_empty
+ end
+
+ it_behaves_like 'Appending correctly'
+ it_behaves_like 'Scheduling no sidekiq worker'
+ end
+
+ context 'when there are some data' do
+ let(:data) { 'Sample data in fog' }
+
+ before do
+ build_trace_chunk.send(:unsafe_set_data!, data)
+ end
+
+ it 'has data' do
+ expect(build_trace_chunk.data).to eq(data)
+ end
+
+ it_behaves_like 'Appending correctly'
+ it_behaves_like 'Scheduling no sidekiq worker'
end
end
end
@@ -313,12 +333,13 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
context 'when data_store is fog' do
let(:data_store) { :fog }
- let(:data) { '' }
- let(:offset) { 0 }
+ let(:data) { 'Sample data in fog' }
- it 'can not truncate' do
- expect { subject }.to raise_error('Fog store does not support truncating')
+ before do
+ build_trace_chunk.send(:unsafe_set_data!, data)
end
+
+ it_behaves_like 'truncates'
end
end
@@ -373,7 +394,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
end
context 'when data does not exist' do
- it { expect { subject }.to raise_error(Excon::Error::NotFound) }
+ it { is_expected.to eq(0) }
end
end
end