diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-05-23 15:51:50 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-06-06 17:49:48 +0900 |
commit | 4b458ca79ad516cbc556ad9cd7e384c10bce037f (patch) | |
tree | ee8b2fe4287bc766c67c226b4dd7d4d7daee2658 /spec/workers | |
parent | d5e073a4726f98b728dcdf1ff7a1914e9b3aab9e (diff) | |
download | gitlab-ce-4b458ca79ad516cbc556ad9cd7e384c10bce037f.tar.gz |
Add tests
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/rescue_stale_live_trace_worker_spec.rb | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/spec/workers/rescue_stale_live_trace_worker_spec.rb b/spec/workers/rescue_stale_live_trace_worker_spec.rb new file mode 100644 index 00000000000..f2b6361c54b --- /dev/null +++ b/spec/workers/rescue_stale_live_trace_worker_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' + +describe RescueStaleLiveTraceWorker do + subject { described_class.new.perform } + + before do + stub_feature_flags(ci_enable_live_trace: true) + end + + shared_examples_for 'schedules to archive traces' do + it do + expect(ArchiveTraceWorker).to receive(:bulk_perform_async).with([[build.id]]) + + subject + end + end + + shared_examples_for 'does not schedule to archive traces' do + it do + expect(ArchiveTraceWorker).not_to receive(:bulk_perform_async) + + subject + end + end + + context 'when a job was succeeded 2 hours ago' do + let!(:build) { create(:ci_build, :success, :trace_live) } + + before do + build.update(finished_at: 2.hours.ago) + end + + it_behaves_like 'schedules to archive traces' + end + + context 'when a job was failed 2 hours ago' do + let!(:build) { create(:ci_build, :failed, :trace_live) } + + before do + build.update(finished_at: 2.hours.ago) + end + + it_behaves_like 'schedules to archive traces' + end + + context 'when a job was cancelled 2 hours ago' do + let!(:build) { create(:ci_build, :canceled, :trace_live) } + + before do + build.update(finished_at: 2.hours.ago) + end + + it_behaves_like 'schedules to archive traces' + end + + context 'when a job has been finished 10 minutes ago' do + let!(:build) { create(:ci_build, :success, :trace_live) } + + before do + build.update(finished_at: 10.minutes.ago) + end + + it_behaves_like 'does not schedule to archive traces' + 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' + end +end |