Commit 382684ae authored by James Lopez's avatar James Lopez

Merge branch '249040-fix-subscription-without-namespace' into 'master'

Fix subscription seats update when namespace is absent

Closes #249040

See merge request gitlab-org/gitlab!42184
parents c873e289 244fb0d9
---
title: Fix max seats used not updated in billing summary
merge_request: 42184
author:
type: fixed
...@@ -16,6 +16,11 @@ class UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker # rubocop:disable Scalab ...@@ -16,6 +16,11 @@ class UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker # rubocop:disable Scalab
tuples = [] tuples = []
subscriptions.each do |subscription| subscriptions.each do |subscription|
unless subscription.namespace
track_error(subscription)
next
end
subscription.refresh_seat_attributes! subscription.refresh_seat_attributes!
tuples << [subscription.id, subscription.max_seats_used, subscription.seats_in_use, subscription.seats_owed] tuples << [subscription.id, subscription.max_seats_used, subscription.seats_in_use, subscription.seats_owed]
...@@ -33,4 +38,14 @@ class UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker # rubocop:disable Scalab ...@@ -33,4 +38,14 @@ class UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker # rubocop:disable Scalab
end end
end end
end end
private
def track_error(subscription)
Gitlab::ErrorTracking.track_exception(
StandardError.new('Namespace absent'),
gitlab_subscription_id: subscription.id,
namespace_id: subscription.namespace_id
)
end
end end
...@@ -96,6 +96,28 @@ RSpec.describe UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker do ...@@ -96,6 +96,28 @@ RSpec.describe UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker do
.and change(gitlab_subscription_2, :seats_in_use).from(0).to(13) .and change(gitlab_subscription_2, :seats_in_use).from(0).to(13)
.and change(gitlab_subscription_2, :seats_owed).from(0).to(12) .and change(gitlab_subscription_2, :seats_owed).from(0).to(12)
end end
context 'when namespace is absent' do
before do
gitlab_subscription.update!(namespace_id: nil)
end
it 'skips the subscription' do
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
an_instance_of(StandardError),
{ gitlab_subscription_id: gitlab_subscription.id, namespace_id: nil }
)
expect do
perform_and_reload
end.to not_change(gitlab_subscription, :max_seats_used).from(0)
.and not_change(gitlab_subscription, :seats_in_use).from(0)
.and not_change(gitlab_subscription, :seats_owed).from(0)
.and change(gitlab_subscription_2, :max_seats_used).from(0).to(14)
.and change(gitlab_subscription_2, :seats_in_use).from(0).to(13)
.and change(gitlab_subscription_2, :seats_owed).from(0).to(12)
end
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