summaryrefslogtreecommitdiff
path: root/spec/services/ci/register_job_service_spec.rb
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2018-04-10 15:13:09 +0200
committerTomasz Maczukin <tomasz@maczukin.pl>2018-04-10 15:13:55 +0200
commit067f5f11c2f5c987697a78a42f23db1db1a90856 (patch)
tree783f1a5832eb6dc6b79e8ead7631773985240e43 /spec/services/ci/register_job_service_spec.rb
parent2cc0c692c082fddabcbb5ddc51e46d7996f5c3d7 (diff)
downloadgitlab-ce-067f5f11c2f5c987697a78a42f23db1db1a90856.tar.gz
Protect register_job_service from pending job with queued_at=nil
Diffstat (limited to 'spec/services/ci/register_job_service_spec.rb')
-rw-r--r--spec/services/ci/register_job_service_spec.rb24
1 files changed, 23 insertions, 1 deletions
diff --git a/spec/services/ci/register_job_service_spec.rb b/spec/services/ci/register_job_service_spec.rb
index aa7cc268dd7..8a537e83d5f 100644
--- a/spec/services/ci/register_job_service_spec.rb
+++ b/spec/services/ci/register_job_service_spec.rb
@@ -400,14 +400,16 @@ module Ci
pending_job.update(created_at: current_time - 3600, queued_at: current_time - 1800)
end
- shared_examples 'metrics collector' do
+ shared_examples 'attempt counter collector' do
it 'increments attempt counter' do
allow(job_queue_duration_seconds).to receive(:observe)
expect(attempt_counter).to receive(:increment)
execute(runner)
end
+ end
+ shared_examples 'jobs queueing time histogram collector' do
it 'counts job queuing time histogram with expected labels' do
allow(attempt_counter).to receive(:increment)
expect(job_queue_duration_seconds).to receive(:observe)
@@ -432,6 +434,11 @@ module Ci
end
end
+ shared_examples 'metrics collector' do
+ it_behaves_like 'attempt counter collector'
+ it_behaves_like 'jobs queueing time histogram collector'
+ end
+
context 'when shared runner is used' do
let(:runner) { shared_runner }
let(:expected_shared_runner) { true }
@@ -439,6 +446,21 @@ module Ci
let(:expected_jobs_running_for_project_third_job) { 2 }
it_behaves_like 'metrics collector'
+
+ context 'when pending job with queued_at=nil is used' do
+ before do
+ pending_job.update(queued_at: nil)
+ end
+
+ it_behaves_like 'attempt counter collector'
+
+ it "doesn't count job queuing time histogram" do
+ allow(attempt_counter).to receive(:increment)
+ expect(job_queue_duration_seconds).not_to receive(:observe)
+
+ execute(runner)
+ end
+ end
end
context 'when specific runner is used' do