Commit 35cd5049 authored by Ash McKenzie's avatar Ash McKenzie

Guard if DB is read only

Ensure when UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker
is running the DB is not read only.
parent df3cf045
......@@ -7,6 +7,7 @@ class UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker
# rubocop: disable CodeReuse/ActiveRecord
def perform
return unless ::Gitlab::Database.postgresql?
return if ::Gitlab::Database.read_only?
return unless ::Gitlab::CurrentSettings.should_check_namespace_plan?
GitlabSubscription.with_a_paid_hosted_plan.find_in_batches(batch_size: 100) do |subscriptions|
......
......@@ -9,22 +9,41 @@ describe UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker, :postgresql do
let!(:early_adopter_plan) { create(:early_adopter_plan) }
let!(:gitlab_subscription) { create(:gitlab_subscription, namespace: group) }
let(:db_is_postgres) { true }
let(:db_is_read_only) { false }
let(:subscription_attrs) { nil }
before do
allow(Gitlab::Database).to receive(:postgresql?) { db_is_postgres }
allow(Gitlab::Database).to receive(:read_only?) { db_is_read_only }
allow(Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?) { true }
group.add_developer(user)
end
shared_examples 'keeps original max_seats_used value' do
before do
gitlab_subscription.update!(subscription_attrs)
end
it 'does not update max_seats_used' do
expect { subject.perform }.not_to change { gitlab_subscription.reload.max_seats_used }
end
end
context 'when the DB is not PostgreSQL' do
let(:db_is_postgres) { false }
include_examples 'keeps original max_seats_used value'
end
context 'where the DB is read only' do
let(:db_is_read_only) { true }
include_examples 'keeps original max_seats_used value'
end
context 'when the DB PostgreSQK AND is not read only' do
before do
gitlab_subscription.update!(subscription_attrs) if subscription_attrs
end
context 'with a free plan' do
let(:subscription_attrs) { { hosted_plan: nil } }
......@@ -58,4 +77,5 @@ describe UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker, :postgresql do
expect { subject.perform }.not_to change { gitlab_subscription.reload.max_seats_used }
end
end
end
end
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