Commit 113d2c11 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Fix DB seeds to not require RSpec

Split `spec/support/sidekiq.rb` into two separate files. One for
adding the middleware and the other for Rspec configuration.
parent ba6941e1
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
Gitlab::Seeder.quiet do
User.create!(
......
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
class Gitlab::Seeder::Projects
include ActionView::Helpers::NumberHelper
......
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
Sidekiq::Testing.inline! do
Gitlab::Seeder.quiet do
......
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
Gitlab::Seeder.quiet do
Project.not_mass_generated.each do |project|
......
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
Gitlab::Seeder.quiet do
Rake::Task["gitlab:seed:issues"].invoke
......
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
Gitlab::Seeder.quiet do
# Limit the number of merge requests per project to avoid long seeds
......
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
# Creating keys runs a gitlab-shell worker. Since we may not have the right
......
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
Gitlab::Seeder.quiet do
content =<<eos
......
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
Gitlab::Seeder.quiet do
Issue.find_each do |issue|
......
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
class Gitlab::Seeder::Pipelines
STAGES = %w[build test deploy notify]
......
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
Gitlab::Seeder.quiet do
EMOJI = Gitlab::Emoji.emojis.keys
......
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
Gitlab::Seeder.quiet do
admin_user = User.find(1)
......
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
require './spec/support/helpers/test_env'
class Gitlab::Seeder::CycleAnalytics
......
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
class Gitlab::Seeder::Environments
def initialize(project)
......
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
Sidekiq::Testing.inline! do
Gitlab::Seeder.quiet do
......
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
Sidekiq::Testing.inline! do
Gitlab::Seeder.quiet do
......
# frozen_string_literal: true
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
# Create an api access token for root user with the value: ypCa3Dzb23o5nvsixwPA
Gitlab::Seeder.quiet do
......
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
require './spec/support/helpers/test_env'
class Gitlab::Seeder::Burndown
......
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
class Gitlab::Seeder::Vulnerabilities
attr_reader :project
......
# frozen_string_literal: true
require './spec/support/sidekiq'
require './spec/support/sidekiq_middleware'
class Gitlab::Seeder::ProductivityAnalytics
def initialize(project)
......
# frozen_string_literal: true
require 'sidekiq/testing'
# If Sidekiq::Testing.inline! is used, SQL transactions done inside
# Sidekiq worker are included in the SQL query limit (in a real
# deployment sidekiq worker is executed separately). To avoid
# increasing SQL limit counter, the request is marked as whitelisted
# during Sidekiq block
class DisableQueryLimit
def call(worker_instance, msg, queue)
transaction = Gitlab::QueryLimiting::Transaction.current
if !transaction.respond_to?(:whitelisted) || transaction.whitelisted
yield
else
transaction.whitelisted = true
yield
transaction.whitelisted = false
end
end
end
Sidekiq::Testing.server_middleware do |chain|
chain.add Gitlab::SidekiqStatus::ServerMiddleware
chain.add DisableQueryLimit
end
RSpec.configure do |config|
config.around(:each, :sidekiq) do |example|
Sidekiq::Worker.clear_all
......
# frozen_string_literal: true
require 'sidekiq/testing'
# If Sidekiq::Testing.inline! is used, SQL transactions done inside
# Sidekiq worker are included in the SQL query limit (in a real
# deployment sidekiq worker is executed separately). To avoid
# increasing SQL limit counter, the request is marked as whitelisted
# during Sidekiq block
class DisableQueryLimit
def call(worker_instance, msg, queue)
transaction = Gitlab::QueryLimiting::Transaction.current
if !transaction.respond_to?(:whitelisted) || transaction.whitelisted
yield
else
transaction.whitelisted = true
yield
transaction.whitelisted = false
end
end
end
Sidekiq::Testing.server_middleware do |chain|
chain.add Gitlab::SidekiqStatus::ServerMiddleware
chain.add DisableQueryLimit
end
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