From 32fd4cd5e2134511936899d6bcc4aaf18b9be6fd Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 25 Feb 2020 21:09:23 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/lib/gitlab/job_waiter_spec.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'spec/lib/gitlab/job_waiter_spec.rb') diff --git a/spec/lib/gitlab/job_waiter_spec.rb b/spec/lib/gitlab/job_waiter_spec.rb index efa7fd4b975..da6a6a9149b 100644 --- a/spec/lib/gitlab/job_waiter_spec.rb +++ b/spec/lib/gitlab/job_waiter_spec.rb @@ -37,5 +37,40 @@ describe Gitlab::JobWaiter do expect(result).to contain_exactly('a') end + + context 'when a label is provided' do + let(:waiter) { described_class.new(2, worker_label: 'Foo') } + let(:started_total) { double(:started_total) } + let(:timeouts_total) { double(:timeouts_total) } + + before do + allow(Gitlab::Metrics).to receive(:counter) + .with(described_class::STARTED_METRIC, anything) + .and_return(started_total) + + allow(Gitlab::Metrics).to receive(:counter) + .with(described_class::TIMEOUTS_METRIC, anything) + .and_return(timeouts_total) + end + + it 'increments just job_waiter_started_total when all jobs complete' do + expect(started_total).to receive(:increment).with(worker: 'Foo') + expect(timeouts_total).not_to receive(:increment) + + described_class.notify(waiter.key, 'a') + described_class.notify(waiter.key, 'b') + + result = nil + expect { Timeout.timeout(1) { result = waiter.wait(2) } }.not_to raise_error + end + + it 'increments job_waiter_started_total and job_waiter_timeouts_total when it times out' do + expect(started_total).to receive(:increment).with(worker: 'Foo') + expect(timeouts_total).to receive(:increment).with(worker: 'Foo') + + result = nil + expect { Timeout.timeout(2) { result = waiter.wait(1) } }.not_to raise_error + end + end end end -- cgit v1.2.1