diff options
author | Ash McKenzie <amckenzie@gitlab.com> | 2019-06-04 07:44:02 +0300 |
---|---|---|
committer | Ash McKenzie <amckenzie@gitlab.com> | 2019-06-05 02:08:10 +0300 |
commit | 977ba4cc150092107944f3a46734b2540d321dcf (patch) | |
tree | 23b8f60ad5efed565fb5390be95346e88d952323 /spec/workers | |
parent | 75e11922026db90ccb81b0125b18b0bd2ffbb7fb (diff) |
Ensure DB is writable before continuing jobs
In the context of a Geo setup, some jobs can be
running on a Geo secondary where the database
is read-only and therefore we should guard
against various jobs attempting to write.
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/pages_domain_verification_cron_worker_spec.rb | 7 | ||||
-rw-r--r-- | spec/workers/pages_domain_verification_worker_spec.rb | 7 |
2 files changed, 14 insertions, 0 deletions
diff --git a/spec/workers/pages_domain_verification_cron_worker_spec.rb b/spec/workers/pages_domain_verification_cron_worker_spec.rb index 186824a444f..3fb86adee11 100644 --- a/spec/workers/pages_domain_verification_cron_worker_spec.rb +++ b/spec/workers/pages_domain_verification_cron_worker_spec.rb @@ -10,6 +10,13 @@ describe PagesDomainVerificationCronWorker do let!(:reverify) { create(:pages_domain, :reverify) } let!(:disabled) { create(:pages_domain, :disabled) } + it 'does nothing if the database is read-only' do + allow(Gitlab::Database).to receive(:read_only?).and_return(true) + expect(PagesDomainVerificationWorker).not_to receive(:perform_async).with(reverify.id) + + worker.perform + end + it 'enqueues a PagesDomainVerificationWorker for domains needing verification' do [reverify, disabled].each do |domain| expect(PagesDomainVerificationWorker).to receive(:perform_async).with(domain.id) diff --git a/spec/workers/pages_domain_verification_worker_spec.rb b/spec/workers/pages_domain_verification_worker_spec.rb index 2f23dcb487f..f51ac1f4323 100644 --- a/spec/workers/pages_domain_verification_worker_spec.rb +++ b/spec/workers/pages_domain_verification_worker_spec.rb @@ -8,6 +8,13 @@ describe PagesDomainVerificationWorker do let(:domain) { create(:pages_domain) } describe '#perform' do + it 'does nothing if the database is read-only' do + allow(Gitlab::Database).to receive(:read_only?).and_return(true) + expect(PagesDomain).not_to receive(:find_by).with(id: domain.id) + + worker.perform(domain.id) + end + it 'does nothing for a non-existent domain' do domain.destroy |