debian-mirror-gitlab/spec/uploaders/workers/object_storage/migrate_uploads_worker_spec.rb

69 lines
2 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2018-05-09 12:01:36 +05:30
require 'spec_helper'
2020-03-13 15:44:24 +05:30
describe ObjectStorage::MigrateUploadsWorker do
2018-05-09 12:01:36 +05:30
let(:model_class) { Project }
2018-10-15 14:42:47 +05:30
let(:uploads) { Upload.all }
2018-05-09 12:01:36 +05:30
let(:to_store) { ObjectStorage::Store::REMOTE }
2019-12-21 20:55:43 +05:30
def perform(uploads, store = nil)
described_class.new.perform(uploads.ids, model_class.to_s, mounted_as, store || to_store)
2018-11-08 19:23:39 +05:30
rescue ObjectStorage::MigrateUploadsWorker::Report::MigrationFailures
# swallow
end
2018-10-15 14:42:47 +05:30
context "for AvatarUploader" do
let!(:projects) { create_list(:project, 10, :with_avatar) }
let(:mounted_as) { :avatar }
2018-05-09 12:01:36 +05:30
2018-10-15 14:42:47 +05:30
before do
stub_uploads_object_storage(AvatarUploader)
end
it_behaves_like "uploads migration worker"
2018-11-08 19:23:39 +05:30
describe "limits N+1 queries" do
it "to N*5" do
query_count = ActiveRecord::QueryRecorder.new { perform(uploads) }
more_projects = create_list(:project, 3, :with_avatar)
expected_queries_per_migration = 5 * more_projects.count
expect { perform(Upload.all) }.not_to exceed_query_limit(query_count).with_threshold(expected_queries_per_migration)
end
end
2018-10-15 14:42:47 +05:30
end
context "for FileUploader" do
let!(:projects) { create_list(:project, 10) }
let(:secret) { SecureRandom.hex }
let(:mounted_as) { nil }
2018-11-08 19:23:39 +05:30
def upload_file(project)
uploader = FileUploader.new(project)
uploader.store!(fixture_file_upload('spec/fixtures/doc_sample.txt'))
end
2018-10-15 14:42:47 +05:30
before do
stub_uploads_object_storage(FileUploader)
2018-11-08 19:23:39 +05:30
projects.map(&method(:upload_file))
2018-05-09 12:01:36 +05:30
end
2018-10-15 14:42:47 +05:30
it_behaves_like "uploads migration worker"
2018-11-08 19:23:39 +05:30
describe "limits N+1 queries" do
it "to N*5" do
query_count = ActiveRecord::QueryRecorder.new { perform(uploads) }
more_projects = create_list(:project, 3)
more_projects.map(&method(:upload_file))
expected_queries_per_migration = 5 * more_projects.count
expect { perform(Upload.all) }.not_to exceed_query_limit(query_count).with_threshold(expected_queries_per_migration)
end
end
2018-05-09 12:01:36 +05:30
end
end