summaryrefslogtreecommitdiff
path: root/spec/workers/namespaces/schedule_aggregation_worker_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/workers/namespaces/schedule_aggregation_worker_spec.rb')
-rw-r--r--spec/workers/namespaces/schedule_aggregation_worker_spec.rb39
1 files changed, 25 insertions, 14 deletions
diff --git a/spec/workers/namespaces/schedule_aggregation_worker_spec.rb b/spec/workers/namespaces/schedule_aggregation_worker_spec.rb
index 7432ca12f2a..d4a49a3f53a 100644
--- a/spec/workers/namespaces/schedule_aggregation_worker_spec.rb
+++ b/spec/workers/namespaces/schedule_aggregation_worker_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Namespaces::ScheduleAggregationWorker, '#perform' do
+describe Namespaces::ScheduleAggregationWorker, '#perform', :clean_gitlab_redis_shared_state do
let(:group) { create(:group) }
subject(:worker) { described_class.new }
@@ -10,6 +10,8 @@ describe Namespaces::ScheduleAggregationWorker, '#perform' do
context 'when group is the root ancestor' do
context 'when aggregation schedule exists' do
it 'does not create a new one' do
+ stub_aggregation_schedule_statistics
+
Namespace::AggregationSchedule.safe_find_or_create_by!(namespace_id: group.id)
expect do
@@ -18,26 +20,25 @@ describe Namespaces::ScheduleAggregationWorker, '#perform' do
end
end
- context 'when update_statistics_namespace is off' do
- it 'does not create a new one' do
- stub_feature_flags(update_statistics_namespace: false, namespace: group)
+ context 'when aggregation schedule does not exist' do
+ it 'creates one' do
+ stub_aggregation_schedule_statistics
expect do
worker.perform(group.id)
- end.not_to change(Namespace::AggregationSchedule, :count)
+ end.to change(Namespace::AggregationSchedule, :count).by(1)
+
+ expect(group.aggregation_schedule).to be_present
end
end
- context 'when aggregation schedule does not exist' do
- it 'creates one' do
- allow_any_instance_of(Namespace::AggregationSchedule)
- .to receive(:schedule_root_storage_statistics).and_return(nil)
+ context 'when update_statistics_namespace is off' do
+ it 'does not create a new one' do
+ stub_feature_flags(update_statistics_namespace: false, namespace: group)
expect do
worker.perform(group.id)
- end.to change(Namespace::AggregationSchedule, :count).by(1)
-
- expect(group.aggregation_schedule).to be_present
+ end.not_to change(Namespace::AggregationSchedule, :count)
end
end
end
@@ -47,8 +48,7 @@ describe Namespaces::ScheduleAggregationWorker, '#perform' do
let(:group) { create(:group, parent: parent_group) }
it 'creates an aggregation schedule for the root' do
- allow_any_instance_of(Namespace::AggregationSchedule)
- .to receive(:schedule_root_storage_statistics).and_return(nil)
+ stub_aggregation_schedule_statistics
worker.perform(group.id)
@@ -63,4 +63,15 @@ describe Namespaces::ScheduleAggregationWorker, '#perform' do
worker.perform(12345)
end
end
+
+ def stub_aggregation_schedule_statistics
+ # Namespace::Aggregations are deleted by
+ # Namespace::AggregationSchedule::schedule_root_storage_statistics,
+ # which is executed async. Stubing the service so instances are not deleted
+ # while still running the specs.
+ expect_next_instance_of(Namespace::AggregationSchedule) do |aggregation_schedule|
+ expect(aggregation_schedule)
+ .to receive(:schedule_root_storage_statistics)
+ end
+ end
end