Commit 3d42bab7 authored by Micaël Bergeron's avatar Micaël Bergeron

apply feedback

parent e1589a5c
...@@ -16,7 +16,8 @@ module ObjectStorage ...@@ -16,7 +16,8 @@ module ObjectStorage
end end
def message def message
"Exclusive lease #{@lease_key} already taken." *lease_key_group, _ = *@lease_key.split(":")
"Exclusive lease for #{lease_key_group.join(':')} is already taken."
end end
end end
......
require 'spec_helper' require 'spec_helper'
MIGRATION_QUERIES = 5
describe ObjectStorage::MigrateUploadsWorker, :sidekiq do describe ObjectStorage::MigrateUploadsWorker, :sidekiq do
shared_context 'sanity_check! fails' do shared_context 'sanity_check! fails' do
before do before do
...@@ -127,13 +125,12 @@ describe ObjectStorage::MigrateUploadsWorker, :sidekiq do ...@@ -127,13 +125,12 @@ describe ObjectStorage::MigrateUploadsWorker, :sidekiq do
it_behaves_like "uploads migration worker" it_behaves_like "uploads migration worker"
describe "limits N+1 queries" do describe "limits N+1 queries" do
let!(:projects) { create_list(:project, 10, :with_avatar) } it "to N*5" do
it "to N*#{MIGRATION_QUERIES}" do
query_count = ActiveRecord::QueryRecorder.new { perform(uploads) } query_count = ActiveRecord::QueryRecorder.new { perform(uploads) }
more_projects = create_list(:project, 100, :with_avatar) more_projects = create_list(:project, 3, :with_avatar)
expected_queries_per_migration = MIGRATION_QUERIES * more_projects.count
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) expect { perform(Upload.all) }.not_to exceed_query_limit(query_count).with_threshold(expected_queries_per_migration)
end end
end end
...@@ -144,30 +141,27 @@ describe ObjectStorage::MigrateUploadsWorker, :sidekiq do ...@@ -144,30 +141,27 @@ describe ObjectStorage::MigrateUploadsWorker, :sidekiq do
let(:secret) { SecureRandom.hex } let(:secret) { SecureRandom.hex }
let(:mounted_as) { nil } let(:mounted_as) { nil }
def upload_file(project)
uploader = FileUploader.new(project)
uploader.store!(fixture_file_upload('spec/fixtures/doc_sample.txt'))
end
before do before do
stub_uploads_object_storage(FileUploader) stub_uploads_object_storage(FileUploader)
projects.map do |project| projects.map(&method(:upload_file))
uploader = FileUploader.new(project)
uploader.store!(fixture_file_upload('spec/fixtures/doc_sample.txt'))
end
end end
it_behaves_like "uploads migration worker" it_behaves_like "uploads migration worker"
describe "limits N+1 queries" do describe "limits N+1 queries" do
let!(:projects) { create_list(:project, 10) } it "to N*5" do
it "to N*#{MIGRATION_QUERIES}" do
query_count = ActiveRecord::QueryRecorder.new { perform(uploads) } query_count = ActiveRecord::QueryRecorder.new { perform(uploads) }
more_projects = create_list(:project, 100) more_projects = create_list(:project, 3)
more_projects.map do |project| more_projects.map(&method(:upload_file))
uploader = FileUploader.new(project)
uploader.store!(fixture_file_upload('spec/fixtures/doc_sample.txt'))
end
expected_queries_per_migration = MIGRATION_QUERIES * more_projects.count
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) expect { perform(Upload.all) }.not_to exceed_query_limit(query_count).with_threshold(expected_queries_per_migration)
end end
end 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