URL blocker can make specs really slow
I'm working from somewhere different right now, and I noticed that specs using the Redmine and Jira services were really slow. I added this spec to spec/project_factory_spec.rb
:
require 'spec_helper'
describe 'Project factories' do
it 'is slow' do
[:project, :redmine_project, :jira_project, :project_empty_repo].each do |factory|
pp [factory, Benchmark.realtime { create(factory) }]
end
end
end
Which gave me this output:
[:project, 1.1186170000000857]
[:redmine_project, 90.4382639999967]
[:jira_project, 60.389681999979075]
[:project_empty_repo, 0.19306000001961365]
After profiling, the problem appears to be the URL blocker, where we try to validate the IP the hostname resolves to:
%self total self wait child calls name
# snip
0.00 90.765 0.000 0.000 90.765 1 Project::GeneratedAssociationMethods#create_redmine_service
0.00 90.481 0.000 0.000 90.481 91 ActiveModel::EachValidator#validate
0.00 90.094 0.000 0.000 90.094 3 UrlValidator#validate_each
0.00 90.016 0.000 0.000 90.016 3 <Class::Gitlab::UrlBlocker>#validate!
91.54 90.015 90.015 0.000 0.000 3 <Class::Addrinfo>#getaddrinfo
Redmine makes three of these calls, and JIRA two - all time out after 30 seconds.
So something's messed up with my network here, but having the specs be this slow is not great, especially if this ever happened on CI. @DouweM @fjsanpedro should we skip the validations in specs (or at least, in factories) somehow, or is there another solution we can use?