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
No related merge requests found
...@@ -7,6 +7,7 @@ class UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker ...@@ -7,6 +7,7 @@ class UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def perform def perform
return unless ::Gitlab::Database.postgresql? return unless ::Gitlab::Database.postgresql?
return if ::Gitlab::Database.read_only?
return unless ::Gitlab::CurrentSettings.should_check_namespace_plan? return unless ::Gitlab::CurrentSettings.should_check_namespace_plan?
GitlabSubscription.with_a_paid_hosted_plan.find_in_batches(batch_size: 100) do |subscriptions| GitlabSubscription.with_a_paid_hosted_plan.find_in_batches(batch_size: 100) do |subscriptions|
......
...@@ -9,22 +9,41 @@ describe UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker, :postgresql do ...@@ -9,22 +9,41 @@ describe UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker, :postgresql do
let!(:early_adopter_plan) { create(:early_adopter_plan) } let!(:early_adopter_plan) { create(:early_adopter_plan) }
let!(:gitlab_subscription) { create(:gitlab_subscription, namespace: group) } 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 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 } allow(Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?) { true }
group.add_developer(user) group.add_developer(user)
end end
shared_examples 'keeps original max_seats_used value' do 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 it 'does not update max_seats_used' do
expect { subject.perform }.not_to change { gitlab_subscription.reload.max_seats_used } expect { subject.perform }.not_to change { gitlab_subscription.reload.max_seats_used }
end end
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 context 'with a free plan' do
let(:subscription_attrs) { { hosted_plan: nil } } let(:subscription_attrs) { { hosted_plan: nil } }
...@@ -58,4 +77,5 @@ describe UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker, :postgresql do ...@@ -58,4 +77,5 @@ describe UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker, :postgresql do
expect { subject.perform }.not_to change { gitlab_subscription.reload.max_seats_used } expect { subject.perform }.not_to change { gitlab_subscription.reload.max_seats_used }
end end
end 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