Commit 7dae2c96 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch...

Merge branch '9933-updatemaxseatsusedforgitlabcomsubscriptionsworker-attempts-to-run-on-geo-secondary' into 'master'

Guard if DB is read only

Closes #9933

See merge request gitlab-org/gitlab-ee!9703
parents 489b3a2d 35cd5049
......@@ -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,53 +9,73 @@ 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 'with a free plan' do
let(:subscription_attrs) { { hosted_plan: nil } }
context 'when the DB is not PostgreSQL' do
let(:db_is_postgres) { false }
include_examples 'keeps original max_seats_used value'
end
context 'with a trial plan' do
let(:subscription_attrs) { { hosted_plan: bronze_plan, trial: true } }
context 'where the DB is read only' do
let(:db_is_read_only) { true }
include_examples 'keeps original max_seats_used value'
end
context 'with an early adopter plan' do
let(:subscription_attrs) { { hosted_plan: early_adopter_plan } }
context 'when the DB PostgreSQK AND is not read only' do
before do
gitlab_subscription.update!(subscription_attrs) if subscription_attrs
end
include_examples 'keeps original max_seats_used value'
end
context 'with a free plan' do
let(:subscription_attrs) { { hosted_plan: nil } }
context 'with a paid plan' do
before do
gitlab_subscription.update!(hosted_plan: bronze_plan)
include_examples 'keeps original max_seats_used value'
end
it 'only updates max_seats_used if active users count is greater than it' do
expect { subject.perform }.to change { gitlab_subscription.reload.max_seats_used }.to(1)
context 'with a trial plan' do
let(:subscription_attrs) { { hosted_plan: bronze_plan, trial: true } }
include_examples 'keeps original max_seats_used value'
end
it 'does not update max_seats_used if active users count is lower than it' do
gitlab_subscription.update_attribute(:max_seats_used, 5)
context 'with an early adopter plan' do
let(:subscription_attrs) { { hosted_plan: early_adopter_plan } }
expect { subject.perform }.not_to change { gitlab_subscription.reload.max_seats_used }
include_examples 'keeps original max_seats_used value'
end
context 'with a paid plan' do
before do
gitlab_subscription.update!(hosted_plan: bronze_plan)
end
it 'only updates max_seats_used if active users count is greater than it' do
expect { subject.perform }.to change { gitlab_subscription.reload.max_seats_used }.to(1)
end
it 'does not update max_seats_used if active users count is lower than it' do
gitlab_subscription.update_attribute(:max_seats_used, 5)
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