Commit 0d8a8b84 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'validate-background-migration-arguments' into 'master'

Verify background migration arguments in specs [RUN ALL RSPEC]

See merge request gitlab-org/gitlab!54339
parents 59255eb7 f90efdc2
......@@ -6,11 +6,15 @@ require Rails.root.join('db', 'post_migrate', '20200714075739_schedule_populate_
RSpec.describe SchedulePopulatePersonalSnippetStatistics do
let(:users) { table(:users) }
let(:namespaces) { table(:namespaces) }
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') }
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') }
def create_snippet(id, user_id, type = 'PersonalSnippet')
params = {
......
# frozen_string_literal: true
RSpec::Matchers.define :be_background_migration_with_arguments do |arguments|
define_method :matches? do |migration|
expect do
Gitlab::BackgroundMigration.perform(migration, arguments)
end.not_to raise_error
end
end
RSpec::Matchers.define :be_scheduled_delayed_migration do |delay, *expected|
match do |migration|
define_method :matches? do |migration|
expect(migration).to be_background_migration_with_arguments(expected)
BackgroundMigrationWorker.jobs.any? do |job|
job['args'] == [migration, expected] &&
job['at'].to_i == (delay.to_i + Time.now.to_i)
......@@ -16,7 +26,9 @@ RSpec::Matchers.define :be_scheduled_delayed_migration do |delay, *expected|
end
RSpec::Matchers.define :be_scheduled_migration do |*expected|
match do |migration|
define_method :matches? do |migration|
expect(migration).to be_background_migration_with_arguments(expected)
BackgroundMigrationWorker.jobs.any? do |job|
args = job['args'].size == 1 ? [BackgroundMigrationWorker.jobs[0]['args'][0], []] : job['args']
args == [migration, expected]
......@@ -29,7 +41,9 @@ RSpec::Matchers.define :be_scheduled_migration do |*expected|
end
RSpec::Matchers.define :be_scheduled_migration_with_multiple_args do |*expected|
match do |migration|
define_method :matches? do |migration|
expect(migration).to be_background_migration_with_arguments(expected)
BackgroundMigrationWorker.jobs.any? do |job|
args = job['args'].size == 1 ? [BackgroundMigrationWorker.jobs[0]['args'][0], []] : job['args']
args[0] == migration && compare_args(args, expected)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment