diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-04-30 14:52:29 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-04-30 14:52:29 +0900 |
commit | 23c8e198463d566d2e8d2351c315741903035a64 (patch) | |
tree | 47bb18d3b5b0ddf49a6c1c62237cda398322b3bc /spec/models/ci/build_trace_chunk_spec.rb | |
parent | 0d99298aa3bffb9c1df8b22cadfbd8499eaa76a8 (diff) | |
download | gitlab-ce-23c8e198463d566d2e8d2351c315741903035a64.tar.gz |
Fix spec. Revert #truncate in stream (But still prevent redandant calls)
Diffstat (limited to 'spec/models/ci/build_trace_chunk_spec.rb')
-rw-r--r-- | spec/models/ci/build_trace_chunk_spec.rb | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/spec/models/ci/build_trace_chunk_spec.rb b/spec/models/ci/build_trace_chunk_spec.rb index 81e58eca3ed..a122ee84b3c 100644 --- a/spec/models/ci/build_trace_chunk_spec.rb +++ b/spec/models/ci/build_trace_chunk_spec.rb @@ -46,7 +46,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do end describe '#set_data' do - subject { build_trace_chunk.set_data(value) } + subject { build_trace_chunk.send(:set_data, value) } let(:value) { 'Sample data' } @@ -131,13 +131,17 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do context 'when offset is negative' do let(:offset) { -1 } - it { expect { subject }.to raise_error('Offset is out of bound') } + it { expect { subject }.to raise_error('Offset is out of range') } end context 'when offset is bigger than data size' do let(:offset) { data.bytesize + 1 } - it { expect { subject }.to raise_error('Offset is out of bound') } + it do + expect_any_instance_of(described_class).not_to receive(:append) { } + + subject + end end context 'when offset is 10' do @@ -182,19 +186,19 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do context 'when offset is negative' do let(:offset) { -1 } - it { expect { subject }.to raise_error('Offset is out of bound') } + it { expect { subject }.to raise_error('Offset is out of range') } end context 'when offset is bigger than data size' do let(:offset) { data.bytesize + 1 } - it { expect { subject }.to raise_error('Offset is out of bound') } + it { expect { subject }.to raise_error('Offset is out of range') } end context 'when offset is bigger than data size' do let(:new_data) { 'a' * (described_class::CHUNK_SIZE + 1) } - it { expect { subject }.to raise_error('Outside of chunk size') } + it { expect { subject }.to raise_error('Chunk size overflow') } end context 'when offset is EOF' do @@ -320,7 +324,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do describe 'ExclusiveLock' do before do allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain) { nil } - stub_const('Ci::BuildTraceChunk::LOCK_RETRY', 1) + stub_const('Ci::BuildTraceChunk::WRITE_LOCK_RETRY', 1) end it 'raise an error' do @@ -333,30 +337,31 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do before do pipeline = create(:ci_pipeline, project: project) - 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) + @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 end shared_examples_for 'deletes all build_trace_chunk and data in redis' do it do - project.builds.each do |build| + @build_ids.each do |build_id| Gitlab::Redis::SharedState.with do |redis| - redis.scan_each(match: "gitlab:ci:trace:#{build.id}:chunks:?") do |key| + redis.scan_each(match: "gitlab:ci:trace:#{build_id}:chunks:?") do |key| expect(redis.exists(key)).to be_truthy end end end - expect(described_class.count).not_to eq(0) + expect(described_class.count).to eq(3) subject expect(described_class.count).to eq(0) - project.builds.each do |build| + @build_ids.each do |build_id| Gitlab::Redis::SharedState.with do |redis| - redis.scan_each(match: "gitlab:ci:trace:#{build.id}:chunks:?") do |key| + redis.scan_each(match: "gitlab:ci:trace:#{build_id}:chunks:?") do |key| expect(redis.exists(key)).to be_falsey end end @@ -364,14 +369,6 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do end end - context 'when build_trace_chunk is destroyed' do - let(:subject) do - project.builds.each { |build| build.chunks.destroy_all } - end - - it_behaves_like 'deletes all build_trace_chunk and data in redis' - end - context 'when build is destroyed' do let(:subject) do project.builds.destroy_all |