Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-06-01 08:22:31 +0300
committerShinya Maeda <shinya@gitlab.com>2018-06-06 11:49:48 +0300
commit32f825c648cb5fc829cd32b3392530613c62e983 (patch)
treed1eab8df0cab0a99f0f78cf70004e6ea89f5b8f0 /spec
parent10acdc30df99ede1356493c14a57b94ed1ae7950 (diff)
Add tests for each new code
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/ci/trace_spec.rb2
-rw-r--r--spec/models/ci/build_trace_chunk_spec.rb40
-rw-r--r--spec/support/shared_examples/ci_trace_shared_examples.rb25
-rw-r--r--spec/workers/ci/rescue_stale_live_trace_worker_spec.rb34
4 files changed, 89 insertions, 12 deletions
diff --git a/spec/lib/gitlab/ci/trace_spec.rb b/spec/lib/gitlab/ci/trace_spec.rb
index e9d755c2021..d6510649dba 100644
--- a/spec/lib/gitlab/ci/trace_spec.rb
+++ b/spec/lib/gitlab/ci/trace_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Gitlab::Ci::Trace, :clean_gitlab_redis_cache do
+describe Gitlab::Ci::Trace, :clean_gitlab_redis_shared_state do
let(:build) { create(:ci_build) }
let(:trace) { described_class.new(build) }
diff --git a/spec/models/ci/build_trace_chunk_spec.rb b/spec/models/ci/build_trace_chunk_spec.rb
index cbcf1e55979..246152d1c8f 100644
--- a/spec/models/ci/build_trace_chunk_spec.rb
+++ b/spec/models/ci/build_trace_chunk_spec.rb
@@ -35,6 +35,46 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
end
end
+ describe '.find_stale_in_batches' do
+ subject { described_class.find_stale_in_batches }
+
+ context 'when build status is finished' do
+ context 'when build finished 2 days ago' do
+ context 'when build has an archived trace' do
+ let!(:build) { create(:ci_build, :success, :trace_artifact, finished_at: 2.days.ago) }
+
+ it 'does not yield build id' do
+ expect { |b| described_class.find_stale_in_batches(&b) }.not_to yield_control
+ end
+ end
+
+ context 'when build has a live trace' do
+ let!(:build) { create(:ci_build, :success, :trace_live, finished_at: 2.days.ago) }
+
+ it 'yields build id' do
+ expect { |b| described_class.find_stale_in_batches(&b) }.to yield_with_args([build.id])
+ end
+ end
+ end
+
+ context 'when build finished 10 minutes ago' do
+ let!(:build) { create(:ci_build, :success, :trace_live, finished_at: 10.minutes.ago) }
+
+ it 'does not yield build id' do
+ expect { |b| described_class.find_stale_in_batches(&b) }.not_to yield_control
+ end
+ end
+ end
+
+ context 'when build status is running' do
+ let!(:build) { create(:ci_build, :running, :trace_live) }
+
+ it 'does not yield build id' do
+ expect { |b| described_class.find_stale_in_batches(&b) }.not_to yield_control
+ end
+ end
+ end
+
describe '#data' do
subject { build_trace_chunk.data }
diff --git a/spec/support/shared_examples/ci_trace_shared_examples.rb b/spec/support/shared_examples/ci_trace_shared_examples.rb
index 21c6f3c829f..a3a0b2d0eb5 100644
--- a/spec/support/shared_examples/ci_trace_shared_examples.rb
+++ b/spec/support/shared_examples/ci_trace_shared_examples.rb
@@ -227,6 +227,31 @@ shared_examples_for 'common trace features' do
end
end
end
+
+ describe '#archive!' do
+ subject { trace.archive! }
+
+ context 'when build status is success' do
+ let!(:build) { create(:ci_build, :success, :trace_live) }
+
+ it 'archives a trace' do
+ subject
+
+ expect(build.job_artifacts_trace).to be_exist
+ end
+
+ context 'when anothe process had already been archiving', :clean_gitlab_redis_shared_state do
+ before do
+ Gitlab::ExclusiveLease.new("trace:archive:#{trace.job.id}", timeout: 1.hour).try_obtain
+ end
+
+ it 'prevents multiple archiving' do
+ build.reload
+ expect(build.job_artifacts_trace).to be_nil
+ end
+ end
+ end
+ end
end
shared_examples_for 'trace with disabled live trace feature' do
diff --git a/spec/workers/ci/rescue_stale_live_trace_worker_spec.rb b/spec/workers/ci/rescue_stale_live_trace_worker_spec.rb
index 87796fd66db..43a6362a131 100644
--- a/spec/workers/ci/rescue_stale_live_trace_worker_spec.rb
+++ b/spec/workers/ci/rescue_stale_live_trace_worker_spec.rb
@@ -7,19 +7,20 @@ describe Ci::RescueStaleLiveTraceWorker do
stub_feature_flags(ci_enable_live_trace: true)
end
- shared_examples_for 'schedules to archive traces' do
+ shared_examples_for 'archives trace' do
it do
- expect(ArchiveTraceWorker).to receive(:bulk_perform_async).with([[build.id]])
-
subject
+
+ expect(build.job_artifacts_trace).to be_exist
end
end
- shared_examples_for 'does not schedule to archive traces' do
+ shared_examples_for 'does not archive trace' do
it do
- expect(ArchiveTraceWorker).not_to receive(:bulk_perform_async)
-
subject
+
+ build.reload
+ expect(build.job_artifacts_trace).to be_nil
end
end
@@ -30,7 +31,18 @@ describe Ci::RescueStaleLiveTraceWorker do
build.update(finished_at: 2.hours.ago)
end
- it_behaves_like 'schedules to archive traces'
+ it_behaves_like 'archives trace'
+
+ context 'when build has both archived trace and live trace' do
+ let!(:build2) { create(:ci_build, :success, :trace_live, finished_at: 2.days.ago) }
+
+ it 'archives only available targets' do
+ subject
+
+ build.reload
+ expect(build.job_artifacts_trace).to be_exist
+ end
+ end
end
context 'when a job was failed 2 hours ago' do
@@ -40,7 +52,7 @@ describe Ci::RescueStaleLiveTraceWorker do
build.update(finished_at: 2.hours.ago)
end
- it_behaves_like 'schedules to archive traces'
+ it_behaves_like 'archives trace'
end
context 'when a job was cancelled 2 hours ago' do
@@ -50,7 +62,7 @@ describe Ci::RescueStaleLiveTraceWorker do
build.update(finished_at: 2.hours.ago)
end
- it_behaves_like 'schedules to archive traces'
+ it_behaves_like 'archives trace'
end
context 'when a job has been finished 10 minutes ago' do
@@ -60,12 +72,12 @@ describe Ci::RescueStaleLiveTraceWorker do
build.update(finished_at: 10.minutes.ago)
end
- it_behaves_like 'does not schedule to archive traces'
+ it_behaves_like 'does not archive trace'
end
context 'when a job is running' do
let!(:build) { create(:ci_build, :running, :trace_live) }
- it_behaves_like 'does not schedule to archive traces'
+ it_behaves_like 'does not archive trace'
end
end