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-02-07 18:09:52 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-07 18:09:52 +0300
commite43077ab4742ba5083a01a1e5341db1a1b7a1701 (patch)
treec33a00fb176caff735243c484bbd594a3b08bb6e /spec/migrations
parent211a8c3361ccf4eb92f36edbdcf15c98fcdcc8b7 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r--spec/migrations/drop_activate_prometheus_services_for_shared_cluster_applications_background_migration_spec.rb61
-rw-r--r--spec/migrations/patch_prometheus_services_for_shared_cluster_applications_spec.rb134
2 files changed, 61 insertions, 134 deletions
diff --git a/spec/migrations/drop_activate_prometheus_services_for_shared_cluster_applications_background_migration_spec.rb b/spec/migrations/drop_activate_prometheus_services_for_shared_cluster_applications_background_migration_spec.rb
new file mode 100644
index 00000000000..5851b26dba4
--- /dev/null
+++ b/spec/migrations/drop_activate_prometheus_services_for_shared_cluster_applications_background_migration_spec.rb
@@ -0,0 +1,61 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'migrate', '20200116051619_drop_activate_prometheus_services_for_shared_cluster_applications_background_migration.rb')
+
+describe DropActivatePrometheusServicesForSharedClusterApplicationsBackgroundMigration, :sidekiq, :redis, :migration, schema: 2020_01_16_051619 do
+ subject(:migration) { described_class.new }
+
+ describe '#up' do
+ context 'there are only affected jobs on the queue' do
+ it 'removes enqueued ActivatePrometheusServicesForSharedClusterApplications background jobs' do
+ Sidekiq::Testing.disable! do # https://github.com/mperham/sidekiq/wiki/testing#api Sidekiq's API does not have a testing mode
+ Sidekiq::Client.push('queue' => described_class::QUEUE, 'class' => ::BackgroundMigrationWorker, 'args' => [described_class::DROPPED_JOB_CLASS, 1])
+
+ expect { migration.up }.to change { Sidekiq::Queue.new(described_class::QUEUE).size }.from(1).to(0)
+ end
+ end
+ end
+
+ context "there aren't any affected jobs on the queue" do
+ it 'skips other enqueued jobs' do
+ Sidekiq::Testing.disable! do
+ Sidekiq::Client.push('queue' => described_class::QUEUE, 'class' => ::BackgroundMigrationWorker, 'args' => ['SomeOtherClass', 1])
+
+ expect { migration.up }.not_to change { Sidekiq::Queue.new(described_class::QUEUE).size }
+ end
+ end
+ end
+
+ context "there are multiple types of jobs on the queue" do
+ it 'skips other enqueued jobs' do
+ Sidekiq::Testing.disable! do
+ queue = Sidekiq::Queue.new(described_class::QUEUE)
+ # this job will be deleted
+ Sidekiq::Client.push('queue' => described_class::QUEUE, 'class' => ::BackgroundMigrationWorker, 'args' => [described_class::DROPPED_JOB_CLASS, 1])
+ # this jobs will be skipped
+ skipped_jobs_args = [['SomeOtherClass', 1], [described_class::DROPPED_JOB_CLASS, 'wrong id type'], [described_class::DROPPED_JOB_CLASS, 1, 'some wired argument']]
+ skipped_jobs_args.each do |args|
+ Sidekiq::Client.push('queue' => described_class::QUEUE, 'class' => ::BackgroundMigrationWorker, 'args' => args)
+ end
+
+ migration.up
+
+ expect(queue.size).to be 3
+ expect(queue.map(&:args)).to match_array skipped_jobs_args
+ end
+ end
+ end
+
+ context "other queues" do
+ it 'does not modify them' do
+ Sidekiq::Testing.disable! do
+ Sidekiq::Client.push('queue' => 'other', 'class' => ::BackgroundMigrationWorker, 'args' => ['SomeOtherClass', 1])
+ Sidekiq::Client.push('queue' => 'other', 'class' => ::BackgroundMigrationWorker, 'args' => [described_class::DROPPED_JOB_CLASS, 1])
+
+ expect { migration.up }.not_to change { Sidekiq::Queue.new('other').size }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/migrations/patch_prometheus_services_for_shared_cluster_applications_spec.rb b/spec/migrations/patch_prometheus_services_for_shared_cluster_applications_spec.rb
deleted file mode 100644
index 170251277e2..00000000000
--- a/spec/migrations/patch_prometheus_services_for_shared_cluster_applications_spec.rb
+++ /dev/null
@@ -1,134 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require Rails.root.join('db', 'post_migrate', '20200114113341_patch_prometheus_services_for_shared_cluster_applications.rb')
-
-describe PatchPrometheusServicesForSharedClusterApplications, :migration do
- include MigrationHelpers::PrometheusServiceHelpers
-
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
- let(:services) { table(:services) }
- let(:clusters) { table(:clusters) }
- let(:cluster_groups) { table(:cluster_groups) }
- let(:clusters_applications_prometheus) { table(:clusters_applications_prometheus) }
- let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
-
- let(:application_statuses) do
- {
- errored: -1,
- installed: 3,
- updated: 5
- }
- end
-
- let(:cluster_types) do
- {
- instance_type: 1,
- group_type: 2
- }
- end
-
- describe '#up' do
- let!(:project_with_missing_service) { projects.create!(name: 'gitlab', path: 'gitlab-ce', namespace_id: namespace.id) }
- let(:project_with_inactive_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) }
- let(:project_with_active_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) }
- let(:project_with_manual_active_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) }
- let(:project_with_manual_inactive_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) }
- let(:project_with_active_not_prometheus_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) }
- let(:project_with_inactive_not_prometheus_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) }
-
- before do
- services.create(service_params_for(project_with_inactive_service.id, active: false))
- services.create(service_params_for(project_with_active_service.id, active: true))
- services.create(service_params_for(project_with_active_not_prometheus_service.id, active: true, type: 'other'))
- services.create(service_params_for(project_with_inactive_not_prometheus_service.id, active: false, type: 'other'))
- services.create(service_params_for(project_with_manual_inactive_service.id, active: false, properties: { some: 'data' }.to_json))
- services.create(service_params_for(project_with_manual_active_service.id, active: true, properties: { some: 'data' }.to_json))
- end
-
- shared_examples 'patch prometheus services post migration' do
- context 'prometheus application is installed on the cluster' do
- it 'schedules a background migration' do
- clusters_applications_prometheus.create(cluster_id: cluster.id, status: application_statuses[:installed], version: '123')
-
- Sidekiq::Testing.fake! do
- Timecop.freeze do
- background_migrations = [["ActivatePrometheusServicesForSharedClusterApplications", project_with_missing_service.id],
- ["ActivatePrometheusServicesForSharedClusterApplications", project_with_inactive_service.id],
- ["ActivatePrometheusServicesForSharedClusterApplications", project_with_active_not_prometheus_service.id],
- ["ActivatePrometheusServicesForSharedClusterApplications", project_with_inactive_not_prometheus_service.id]]
-
- migrate!
-
- enqueued_migrations = BackgroundMigrationWorker.jobs.map { |job| job['args'] }
- expect(enqueued_migrations).to match_array(background_migrations)
- end
- end
- end
- end
-
- context 'prometheus application was recently updated on the cluster' do
- it 'schedules a background migration' do
- clusters_applications_prometheus.create(cluster_id: cluster.id, status: application_statuses[:updated], version: '123')
-
- Sidekiq::Testing.fake! do
- Timecop.freeze do
- background_migrations = [["ActivatePrometheusServicesForSharedClusterApplications", project_with_missing_service.id],
- ["ActivatePrometheusServicesForSharedClusterApplications", project_with_inactive_service.id],
- ["ActivatePrometheusServicesForSharedClusterApplications", project_with_active_not_prometheus_service.id],
- ["ActivatePrometheusServicesForSharedClusterApplications", project_with_inactive_not_prometheus_service.id]]
-
- migrate!
-
- enqueued_migrations = BackgroundMigrationWorker.jobs.map { |job| job['args'] }
- expect(enqueued_migrations).to match_array(background_migrations)
- end
- end
- end
- end
-
- context 'prometheus application failed to install on the cluster' do
- it 'does not schedule a background migration' do
- clusters_applications_prometheus.create(cluster_id: cluster.id, status: application_statuses[:errored], version: '123')
-
- Sidekiq::Testing.fake! do
- Timecop.freeze do
- migrate!
-
- expect(BackgroundMigrationWorker.jobs.size).to eq 0
- end
- end
- end
- end
-
- context 'prometheus application is NOT installed on the cluster' do
- it 'does not schedule a background migration' do
- Sidekiq::Testing.fake! do
- Timecop.freeze do
- migrate!
-
- expect(BackgroundMigrationWorker.jobs.size).to eq 0
- end
- end
- end
- end
- end
-
- context 'Cluster is group_type' do
- let(:cluster) { clusters.create(name: 'cluster', cluster_type: cluster_types[:group_type]) }
-
- before do
- cluster_groups.create(group_id: namespace.id, cluster_id: cluster.id)
- end
-
- it_behaves_like 'patch prometheus services post migration'
- end
-
- context 'Cluster is instance_type' do
- let(:cluster) { clusters.create(name: 'cluster', cluster_type: cluster_types[:instance_type]) }
-
- it_behaves_like 'patch prometheus services post migration'
- end
- end
-end