From d5344617a8b57e4d6d15f22ad3d09d5af82100fe Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Mon, 30 Apr 2018 15:27:05 +0900 Subject: [PATCH] Fix spec when parent record is destroyed --- app/models/ci/build_trace_chunk.rb | 2 +- spec/models/ci/build_trace_chunk_spec.rb | 25 ++++++++---------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/app/models/ci/build_trace_chunk.rb b/app/models/ci/build_trace_chunk.rb index a8f43fd549f..b9b84104b33 100644 --- a/app/models/ci/build_trace_chunk.rb +++ b/app/models/ci/build_trace_chunk.rb @@ -125,7 +125,7 @@ module Ci end def redis_data_key - "gitlab:ci:trace:#{build_id}:chunks:#{chunk_index}:data" + "gitlab:ci:trace:#{build_id}:chunks:#{chunk_index}" end def redis_lock_key diff --git a/spec/models/ci/build_trace_chunk_spec.rb b/spec/models/ci/build_trace_chunk_spec.rb index a122ee84b3c..cab5db9ca06 100644 --- a/spec/models/ci/build_trace_chunk_spec.rb +++ b/spec/models/ci/build_trace_chunk_spec.rb @@ -332,25 +332,20 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do end end - describe 'deletes data in redis after chunk record destroyed' do + describe 'deletes data in redis after a parent record destroyed' do let(:project) { create(:project) } before do pipeline = create(:ci_pipeline, project: project) - @build_ids = [] - @build_ids << create(:ci_build, :running, :trace_live, pipeline: pipeline, project: project).id - @build_ids << create(:ci_build, :running, :trace_live, pipeline: pipeline, project: project).id - @build_ids << create(:ci_build, :running, :trace_live, pipeline: pipeline, project: project).id + create(:ci_build, :running, :trace_live, pipeline: pipeline, project: project) + create(:ci_build, :running, :trace_live, pipeline: pipeline, project: project) + create(:ci_build, :running, :trace_live, pipeline: pipeline, project: project) end shared_examples_for 'deletes all build_trace_chunk and data in redis' do it do - @build_ids.each do |build_id| - Gitlab::Redis::SharedState.with do |redis| - redis.scan_each(match: "gitlab:ci:trace:#{build_id}:chunks:?") do |key| - expect(redis.exists(key)).to be_truthy - end - end + Gitlab::Redis::SharedState.with do |redis| + expect(redis.scan_each(match: "gitlab:ci:trace:?:chunks:?").to_a.count).to eq(3) end expect(described_class.count).to eq(3) @@ -359,12 +354,8 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do expect(described_class.count).to eq(0) - @build_ids.each do |build_id| - Gitlab::Redis::SharedState.with do |redis| - redis.scan_each(match: "gitlab:ci:trace:#{build_id}:chunks:?") do |key| - expect(redis.exists(key)).to be_falsey - end - end + Gitlab::Redis::SharedState.with do |redis| + expect(redis.scan_each(match: "gitlab:ci:trace:?:chunks:?").to_a.count).to eq(0) end end end