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-07-22 18:09:28 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-22 18:09:28 +0300
commitd1cb802bac5dc182342adb9b8f71dbf466cfa501 (patch)
tree9dc47ce978df2b05a973555a88a1f0b835f4645f /spec/migrations
parent2c171fdd723a6a1f45dedd12e62f93745318b40e (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r--spec/migrations/schedule_populate_personal_snippet_statistics_spec.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/migrations/schedule_populate_personal_snippet_statistics_spec.rb b/spec/migrations/schedule_populate_personal_snippet_statistics_spec.rb
new file mode 100644
index 00000000000..ce618449884
--- /dev/null
+++ b/spec/migrations/schedule_populate_personal_snippet_statistics_spec.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+require Rails.root.join('db', 'post_migrate', '20200714075739_schedule_populate_personal_snippet_statistics.rb')
+
+RSpec.describe SchedulePopulatePersonalSnippetStatistics do
+ let(:users) { table(:users) }
+ let(:snippets) { table(:snippets) }
+ let(:projects) { table(:projects) }
+ let(:user1) { users.create!(id: 1, email: 'user1@example.com', projects_limit: 10, username: 'test1', name: 'Test1', state: 'active') }
+ let(:user2) { users.create!(id: 2, email: 'user2@example.com', projects_limit: 10, username: 'test2', name: 'Test2', state: 'active') }
+ let(:user3) { users.create!(id: 3, email: 'user3@example.com', projects_limit: 10, username: 'test3', name: 'Test3', state: 'active') }
+
+ def create_snippet(id, user_id, type = 'PersonalSnippet')
+ params = {
+ id: id,
+ type: type,
+ author_id: user_id,
+ file_name: 'foo',
+ content: 'bar'
+ }
+
+ snippets.create!(params)
+ end
+
+ it 'correctly schedules background migrations' do
+ # Creating the snippets in different order
+ create_snippet(1, user1.id)
+ create_snippet(2, user2.id)
+ create_snippet(3, user1.id)
+ create_snippet(4, user3.id)
+ create_snippet(5, user3.id)
+ create_snippet(6, user1.id)
+ # Creating a project snippet to ensure we don't pick it
+ create_snippet(7, user1.id, 'ProjectSnippet')
+
+ stub_const("#{described_class}::BATCH_SIZE", 4)
+
+ Sidekiq::Testing.fake! do
+ Timecop.freeze do
+ migrate!
+
+ aggregate_failures do
+ expect(described_class::MIGRATION)
+ .to be_scheduled_migration([1, 3, 6, 2])
+
+ expect(described_class::MIGRATION)
+ .to be_scheduled_delayed_migration(2.minutes, [4, 5])
+
+ expect(BackgroundMigrationWorker.jobs.size).to eq(2)
+ end
+ end
+ end
+ end
+end