Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/workers/metrics
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/workers/metrics')
-rw-r--r--spec/workers/metrics/dashboard/prune_old_annotations_worker_spec.rb40
-rw-r--r--spec/workers/metrics/dashboard/schedule_annotations_prune_worker_spec.rb13
2 files changed, 53 insertions, 0 deletions
diff --git a/spec/workers/metrics/dashboard/prune_old_annotations_worker_spec.rb b/spec/workers/metrics/dashboard/prune_old_annotations_worker_spec.rb
new file mode 100644
index 00000000000..bab5a5d8740
--- /dev/null
+++ b/spec/workers/metrics/dashboard/prune_old_annotations_worker_spec.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Metrics::Dashboard::PruneOldAnnotationsWorker do
+ let_it_be(:now) { DateTime.parse('2020-06-02T00:12:00Z') }
+ let_it_be(:two_weeks_old_annotation) { create(:metrics_dashboard_annotation, starting_at: now.advance(weeks: -2)) }
+ let_it_be(:one_day_old_annotation) { create(:metrics_dashboard_annotation, starting_at: now.advance(days: -1)) }
+ let_it_be(:month_old_annotation) { create(:metrics_dashboard_annotation, starting_at: now.advance(months: -1)) }
+
+ describe '#perform' do
+ it 'removes all annotations older than cut off', :aggregate_failures do
+ Timecop.freeze(now) do
+ described_class.new.perform
+
+ expect(Metrics::Dashboard::Annotation.all).to match_array([one_day_old_annotation, two_weeks_old_annotation])
+
+ # is idempotent in the scope of 24h
+ expect { described_class.new.perform }.not_to change { Metrics::Dashboard::Annotation.all.to_a }
+ Timecop.travel(24.hours.from_now) do
+ described_class.new.perform
+ expect(Metrics::Dashboard::Annotation.all).to match_array([one_day_old_annotation])
+ end
+ end
+ end
+
+ context 'batch to be deleted is bigger than upper limit' do
+ it 'schedules second job to clear remaining records' do
+ Timecop.freeze(now) do
+ create(:metrics_dashboard_annotation, starting_at: 1.month.ago)
+ stub_const("#{described_class}::DELETE_LIMIT", 1)
+
+ expect(described_class).to receive(:perform_async)
+
+ described_class.new.perform
+ end
+ end
+ end
+ end
+end
diff --git a/spec/workers/metrics/dashboard/schedule_annotations_prune_worker_spec.rb b/spec/workers/metrics/dashboard/schedule_annotations_prune_worker_spec.rb
new file mode 100644
index 00000000000..bfe6fe3a90e
--- /dev/null
+++ b/spec/workers/metrics/dashboard/schedule_annotations_prune_worker_spec.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Metrics::Dashboard::ScheduleAnnotationsPruneWorker do
+ describe '#perform' do
+ it 'schedules annotations prune job with default cut off date' do
+ expect(Metrics::Dashboard::PruneOldAnnotationsWorker).to receive(:perform_async)
+
+ described_class.new.perform
+ end
+ end
+end