2020-10-24 23:57:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
require_migration!
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
RSpec.describe SchedulePopulatePersonalSnippetStatistics do
|
|
|
|
let(:users) { table(:users) }
|
2021-04-17 20:07:23 +05:30
|
|
|
let(:namespaces) { table(:namespaces) }
|
2020-10-24 23:57:45 +05:30
|
|
|
let(:snippets) { table(:snippets) }
|
|
|
|
let(:projects) { table(:projects) }
|
2021-04-17 20:07:23 +05:30
|
|
|
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') }
|
|
|
|
let!(:namespace1) { namespaces.create!(id: 1, owner_id: user1.id, name: 'test1', path: 'test1') }
|
|
|
|
let!(:namespace2) { namespaces.create!(id: 2, owner_id: user2.id, name: 'test2', path: 'test2') }
|
|
|
|
let!(:namespace3) { namespaces.create!(id: 3, owner_id: user3.id, name: 'test3', path: 'test3') }
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
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
|
2020-11-24 15:15:51 +05:30
|
|
|
freeze_time do
|
2020-10-24 23:57:45 +05:30
|
|
|
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
|