Commit 067f5f11 authored by Tomasz Maczukin's avatar Tomasz Maczukin

Protect register_job_service from pending job with queued_at=nil

parent 2cc0c692
...@@ -110,7 +110,7 @@ module Ci ...@@ -110,7 +110,7 @@ module Ci
labels = { shared_runner: runner.shared?, labels = { shared_runner: runner.shared?,
jobs_running_for_project: jobs_running_for_project(job) } jobs_running_for_project: jobs_running_for_project(job) }
job_queue_duration_seconds.observe(labels, Time.now - job.queued_at) job_queue_duration_seconds.observe(labels, Time.now - job.queued_at) unless job.queued_at.nil?
attempt_counter.increment attempt_counter.increment
end end
......
...@@ -400,14 +400,16 @@ module Ci ...@@ -400,14 +400,16 @@ module Ci
pending_job.update(created_at: current_time - 3600, queued_at: current_time - 1800) pending_job.update(created_at: current_time - 3600, queued_at: current_time - 1800)
end end
shared_examples 'metrics collector' do shared_examples 'attempt counter collector' do
it 'increments attempt counter' do it 'increments attempt counter' do
allow(job_queue_duration_seconds).to receive(:observe) allow(job_queue_duration_seconds).to receive(:observe)
expect(attempt_counter).to receive(:increment) expect(attempt_counter).to receive(:increment)
execute(runner) execute(runner)
end end
end
shared_examples 'jobs queueing time histogram collector' do
it 'counts job queuing time histogram with expected labels' do it 'counts job queuing time histogram with expected labels' do
allow(attempt_counter).to receive(:increment) allow(attempt_counter).to receive(:increment)
expect(job_queue_duration_seconds).to receive(:observe) expect(job_queue_duration_seconds).to receive(:observe)
...@@ -432,6 +434,11 @@ module Ci ...@@ -432,6 +434,11 @@ module Ci
end end
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 context 'when shared runner is used' do
let(:runner) { shared_runner } let(:runner) { shared_runner }
let(:expected_shared_runner) { true } let(:expected_shared_runner) { true }
...@@ -439,6 +446,21 @@ module Ci ...@@ -439,6 +446,21 @@ module Ci
let(:expected_jobs_running_for_project_third_job) { 2 } let(:expected_jobs_running_for_project_third_job) { 2 }
it_behaves_like 'metrics collector' 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 end
context 'when specific runner is used' do context 'when specific runner is used' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment