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
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-07-08 09:09:14 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-07-08 09:09:14 +0300
commitcf1382025171f9e5f9147fdfbbff1d9f230a9fdd (patch)
tree69884648f385a4b8bbac858b99d54be806e1d1bf /spec/workers/gitlab_service_ping_worker_spec.rb
parent0bda4912aeafdc9753aa901bd3b03d792a50741b (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers/gitlab_service_ping_worker_spec.rb')
-rw-r--r--spec/workers/gitlab_service_ping_worker_spec.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/spec/workers/gitlab_service_ping_worker_spec.rb b/spec/workers/gitlab_service_ping_worker_spec.rb
new file mode 100644
index 00000000000..abccc0dc967
--- /dev/null
+++ b/spec/workers/gitlab_service_ping_worker_spec.rb
@@ -0,0 +1,50 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe GitlabServicePingWorker, :clean_gitlab_redis_shared_state do
+ before do
+ allow_next_instance_of(ServicePing::SubmitService) { |service| allow(service).to receive(:execute) }
+ allow(subject).to receive(:sleep)
+ end
+
+ it 'does not run for GitLab.com' do
+ allow(Gitlab).to receive(:com?).and_return(true)
+ expect(ServicePing::SubmitService).not_to receive(:new)
+
+ subject.perform
+ end
+
+ it 'delegates to ServicePing::SubmitService' do
+ expect_next_instance_of(ServicePing::SubmitService) { |service| expect(service).to receive(:execute) }
+
+ subject.perform
+ end
+
+ it "obtains a #{described_class::LEASE_TIMEOUT} second exclusive lease" do
+ expect(Gitlab::ExclusiveLeaseHelpers::SleepingLock)
+ .to receive(:new)
+ .with(described_class::LEASE_KEY, hash_including(timeout: described_class::LEASE_TIMEOUT))
+ .and_call_original
+
+ subject.perform
+ end
+
+ it 'sleeps for between 0 and 60 seconds' do
+ expect(subject).to receive(:sleep).with(0..60)
+
+ subject.perform
+ end
+
+ context 'when lease is not obtained' do
+ before do
+ Gitlab::ExclusiveLease.new(described_class::LEASE_KEY, timeout: described_class::LEASE_TIMEOUT).try_obtain
+ end
+
+ it 'does not invoke ServicePing::SubmitService' do
+ allow_next_instance_of(ServicePing::SubmitService) { |service| expect(service).not_to receive(:execute) }
+
+ expect { subject.perform }.to raise_error(Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError)
+ end
+ end
+end