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:
Diffstat (limited to 'spec/workers/gitlab_usage_ping_worker_spec.rb')
-rw-r--r--spec/workers/gitlab_usage_ping_worker_spec.rb38
1 files changed, 32 insertions, 6 deletions
diff --git a/spec/workers/gitlab_usage_ping_worker_spec.rb b/spec/workers/gitlab_usage_ping_worker_spec.rb
index 05d6f2e585b..a180d29fd5f 100644
--- a/spec/workers/gitlab_usage_ping_worker_spec.rb
+++ b/spec/workers/gitlab_usage_ping_worker_spec.rb
@@ -2,16 +2,42 @@
require 'spec_helper'
-RSpec.describe GitlabUsagePingWorker do
- subject { described_class.new }
+RSpec.describe GitlabUsagePingWorker, :clean_gitlab_redis_shared_state do
+ before do
+ allow_next_instance_of(SubmitUsagePingService) { |service| allow(service).to receive(:execute) }
+ allow(subject).to receive(:sleep)
+ end
it 'delegates to SubmitUsagePingService' do
- allow(subject).to receive(:try_obtain_lease).and_return(true)
+ expect_next_instance_of(SubmitUsagePingService) { |service| expect(service).to receive(:execute) }
- expect_next_instance_of(SubmitUsagePingService) do |instance|
- expect(instance).to receive(:execute)
- end
+ 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 SubmitUsagePingService' do
+ allow_next_instance_of(SubmitUsagePingService) { |service| expect(service).not_to receive(:execute) }
+
+ expect { subject.perform }.to raise_error(Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError)
+ end
+ end
end