diff --git a/lib/gitlab/ci/trace/chunked_file/chunk_store/redis.rb b/lib/gitlab/ci/trace/chunked_file/chunk_store/redis.rb index c87275319d9..dc3756a6339 100644 --- a/lib/gitlab/ci/trace/chunked_file/chunk_store/redis.rb +++ b/lib/gitlab/ci/trace/chunked_file/chunk_store/redis.rb @@ -24,7 +24,7 @@ module Gitlab def chunks_count(job_id) Gitlab::Redis::Cache.with do |redis| - redis.scan_each(:match => buffer_key(job_id, '?')).inject(0) do |sum, key| + redis.scan_each(match: buffer_key(job_id, '?')).inject(0) do |sum, key| sum + 1 end end @@ -32,15 +32,15 @@ module Gitlab def chunks_size(job_id) Gitlab::Redis::Cache.with do |redis| - redis.scan_each(:match => buffer_key(job_id, '?')).inject(0) do |sum, key| - sum += redis.strlen(key) + redis.scan_each(match: buffer_key(job_id, '?')).inject(0) do |sum, key| + sum + redis.strlen(key) end end end def delete_all(job_id) Gitlab::Redis::Cache.with do |redis| - redis.scan_each(:match => buffer_key(job_id, '?')) do |key| + redis.scan_each(match: buffer_key(job_id, '?')) do |key| redis.del(key) end end diff --git a/lib/gitlab/ci/trace/chunked_file/chunked_io.rb b/lib/gitlab/ci/trace/chunked_file/chunked_io.rb index c9e5de8d32c..f3d3aae5a5b 100644 --- a/lib/gitlab/ci/trace/chunked_file/chunked_io.rb +++ b/lib/gitlab/ci/trace/chunked_file/chunked_io.rb @@ -189,10 +189,10 @@ module Gitlab chunk_store.open(job_id, chunk_index, params_for_store) do |store| with_callbacks(:write_chunk, store) do - written_size = if buffer_size == data.length || store.size == 0 - store.write!(data) - else + written_size = if store.size > 0 # # rubocop:disable ZeroLengthPredicate store.append!(data) + else + store.write!(data) end raise WriteError, 'Written size mismatch' unless data.length == written_size diff --git a/lib/gitlab/ci/trace/chunked_file/concerns/callbacks.rb b/lib/gitlab/ci/trace/chunked_file/concerns/callbacks.rb index 0a49ac4dbbf..3990a492612 100644 --- a/lib/gitlab/ci/trace/chunked_file/concerns/callbacks.rb +++ b/lib/gitlab/ci/trace/chunked_file/concerns/callbacks.rb @@ -7,27 +7,26 @@ module Gitlab extend ActiveSupport::Concern included do - class_attribute :_before_callbacks, :_after_callbacks, - :instance_writer => false + class_attribute :_before_callbacks, :_after_callbacks, instance_writer: false self._before_callbacks = Hash.new [] self._after_callbacks = Hash.new [] end def with_callbacks(kind, *args) - self.class._before_callbacks[kind].each { |c| send c, *args } + self.class._before_callbacks[kind].each { |c| send c, *args } # rubocop:disable GitlabSecurity/PublicSend yield - self.class._after_callbacks[kind].each { |c| send c, *args } + self.class._after_callbacks[kind].each { |c| send c, *args } # rubocop:disable GitlabSecurity/PublicSend end module ClassMethods def before_callback(kind, callback) - self._before_callbacks = self._before_callbacks. - merge kind => _before_callbacks[kind] + [callback] + self._before_callbacks = self._before_callbacks + .merge kind => _before_callbacks[kind] + [callback] end def after_callback(kind, callback) - self._after_callbacks = self._after_callbacks. - merge kind => _after_callbacks[kind] + [callback] + self._after_callbacks = self._after_callbacks + .merge kind => _after_callbacks[kind] + [callback] end end end diff --git a/lib/gitlab/ci/trace/chunked_file/concerns/errors.rb b/lib/gitlab/ci/trace/chunked_file/concerns/errors.rb index ccdb17005e2..0c75afde96b 100644 --- a/lib/gitlab/ci/trace/chunked_file/concerns/errors.rb +++ b/lib/gitlab/ci/trace/chunked_file/concerns/errors.rb @@ -8,7 +8,6 @@ module Gitlab included do WriteError = Class.new(StandardError) - FailedToGetChunkError = Class.new(StandardError) end end end diff --git a/lib/gitlab/ci/trace/chunked_file/concerns/permissions.rb b/lib/gitlab/ci/trace/chunked_file/concerns/permissions.rb index 11d8fd0cdfc..016b796afc2 100644 --- a/lib/gitlab/ci/trace/chunked_file/concerns/permissions.rb +++ b/lib/gitlab/ci/trace/chunked_file/concerns/permissions.rb @@ -6,12 +6,10 @@ module Gitlab module Permissions extend ActiveSupport::Concern - WRITABLE_MODE = %w[a] - READABLE_MODE = %w[r +] + WRITABLE_MODE = %w[a].freeze + READABLE_MODE = %w[r +].freeze included do - PermissionError = Class.new(StandardError) - attr_reader :write_lock_uuid end @@ -20,7 +18,7 @@ module Gitlab @write_lock_uuid = Gitlab::ExclusiveLease .new(write_lock_key(job_id), timeout: 1.hour.to_i).try_obtain - raise PermissionError, 'Already opened by another process' unless write_lock_uuid + raise IOError, 'Already opened by another process' unless write_lock_uuid end super diff --git a/spec/factories/ci/job_trace_chunks.rb b/spec/factories/ci/job_trace_chunks.rb index c7fe1921f3a..f24e015f186 100644 --- a/spec/factories/ci/job_trace_chunks.rb +++ b/spec/factories/ci/job_trace_chunks.rb @@ -1,7 +1,5 @@ -include ActionDispatch::TestProcess - FactoryBot.define do - factory :job_trace_chunk, class: Ci::JobTraceChunk do + factory :ci_job_trace_chunk, class: Ci::JobTraceChunk do job factory: :ci_build end end diff --git a/spec/lib/gitlab/ci/trace/chunked_file/live_trace_spec.rb b/spec/lib/gitlab/ci/trace/chunked_file/live_trace_spec.rb index ad91834f320..c2c7fe1c8d3 100644 --- a/spec/lib/gitlab/ci/trace/chunked_file/live_trace_spec.rb +++ b/spec/lib/gitlab/ci/trace/chunked_file/live_trace_spec.rb @@ -10,7 +10,7 @@ describe Gitlab::Ci::Trace::ChunkedFile::LiveTrace, :clean_gitlab_redis_cache do let(:chunk_stores) do [Gitlab::Ci::Trace::ChunkedFile::ChunkStore::Redis, - Gitlab::Ci::Trace::ChunkedFile::ChunkStore::Database] + Gitlab::Ci::Trace::ChunkedFile::ChunkStore::Database] end describe 'ChunkStores are Redis and Database', :partial_support do