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-04-14 21:09:54 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-14 21:09:54 +0300
commitf697dc5e76dfc5894df006d53b2b7e751653cf05 (patch)
tree1387cd225039e611f3683f96b318bb17d4c422cb /spec/migrations
parent874ead9c3a50de4c4ca4551eaf5b7eb976d26b50 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r--spec/migrations/20200406102120_backfill_deployment_clusters_from_deployments_spec.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/spec/migrations/20200406102120_backfill_deployment_clusters_from_deployments_spec.rb b/spec/migrations/20200406102120_backfill_deployment_clusters_from_deployments_spec.rb
new file mode 100644
index 00000000000..fcb253677e1
--- /dev/null
+++ b/spec/migrations/20200406102120_backfill_deployment_clusters_from_deployments_spec.rb
@@ -0,0 +1,50 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20200406102120_backfill_deployment_clusters_from_deployments.rb')
+
+describe BackfillDeploymentClustersFromDeployments, :migration, :sidekiq, schema: 20200227140242 do
+ describe '#up' do
+ it 'schedules BackfillDeploymentClustersFromDeployments background jobs' do
+ stub_const("#{described_class}::BATCH_SIZE", 2)
+
+ namespace = table(:namespaces).create(name: 'the-namespace', path: 'the-path')
+ project = table(:projects).create(name: 'the-project', namespace_id: namespace.id)
+ environment = table(:environments).create(name: 'the-environment', project_id: project.id, slug: 'slug')
+ cluster = table(:clusters).create(name: 'the-cluster')
+
+ deployment_data = { cluster_id: cluster.id, project_id: project.id, environment_id: environment.id, ref: 'abc', tag: false, sha: 'sha', status: 1 }
+
+ # batch 1
+ batch_1_begin = create_deployment(**deployment_data)
+ batch_1_end = create_deployment(**deployment_data)
+
+ # value that should not be included due to default scope
+ create_deployment(**deployment_data, cluster_id: nil)
+
+ # batch 2
+ batch_2_begin = create_deployment(**deployment_data)
+ batch_2_end = create_deployment(**deployment_data)
+
+ Sidekiq::Testing.fake! do
+ Timecop.freeze do
+ migrate!
+
+ # batch 1
+ expect(described_class::MIGRATION).to be_scheduled_delayed_migration(2.minutes, batch_1_begin.id, batch_1_end.id)
+
+ # batch 2
+ expect(described_class::MIGRATION).to be_scheduled_delayed_migration(4.minutes, batch_2_begin.id, batch_2_end.id)
+
+ expect(BackgroundMigrationWorker.jobs.size).to eq(2)
+ end
+ end
+ end
+
+ def create_deployment(**data)
+ @iid ||= 0
+ @iid += 1
+ table(:deployments).create(iid: @iid, **data)
+ end
+ end
+end