Commit aef34407 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch 'sh-fix-capybara-fd-leak' into 'master'

Fix file descriptor leak with Capybara

See merge request gitlab-org/gitlab!30422
parents 9175aaf2 a8abf6da
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe 'Cluster Health board', :js, :use_clean_rails_memory_store_caching, :sidekiq_inline do describe 'Cluster Health board', :js, :kubeclient, :use_clean_rails_memory_store_caching, :sidekiq_inline do
include KubernetesHelpers include KubernetesHelpers
include PrometheusHelpers include PrometheusHelpers
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidekiq_inline do describe 'Metrics rendering', :js, :kubeclient, :use_clean_rails_memory_store_caching, :sidekiq_inline do
include PrometheusHelpers include PrometheusHelpers
include KubernetesHelpers include KubernetesHelpers
include MetricsDashboardUrlHelpers include MetricsDashboardUrlHelpers
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe 'Environment > Pod Logs', :js do describe 'Environment > Pod Logs', :js, :kubeclient do
include KubernetesHelpers include KubernetesHelpers
let(:pod_names) { %w(kube-pod) } let(:pod_names) { %w(kube-pod) }
......
...@@ -40,7 +40,7 @@ describe 'Functions', :js do ...@@ -40,7 +40,7 @@ describe 'Functions', :js do
it_behaves_like "it's missing knative installation" it_behaves_like "it's missing knative installation"
end end
context 'when the user has a cluster and knative installed and visits the serverless page' do context 'when the user has a cluster and knative installed and visits the serverless page', :kubeclient do
let(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) } let(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) }
let(:service) { cluster.platform_kubernetes } let(:service) { cluster.platform_kubernetes }
let(:environment) { create(:environment, project: project) } let(:environment) { create(:environment, project: project) }
......
...@@ -95,12 +95,23 @@ RSpec.configure do |config| ...@@ -95,12 +95,23 @@ RSpec.configure do |config|
config.include CapybaraHelpers, type: :feature config.include CapybaraHelpers, type: :feature
config.before(:context, :js) do config.before(:context, :js) do
# This prevents Selenium from creating thousands of connections while waiting for
# an element to appear
webmock_enable_with_http_connect_on_start!
next if $capybara_server_already_started next if $capybara_server_already_started
TestEnv.eager_load_driver_server TestEnv.eager_load_driver_server
$capybara_server_already_started = true $capybara_server_already_started = true
end end
config.after(:context, :js) do
# WebMock doesn't stub connections, so we need to restore the original behavior
# to prevent many specs from failing:
# https://github.com/bblimke/webmock/blob/master/README.md#connecting-on-nethttpstart
webmock_enable!
end
config.before(:example, :js) do config.before(:example, :js) do
session = Capybara.current_session session = Capybara.current_session
......
# frozen_string_literal: true
RSpec.configure do |config|
# Feature specs call webmock_enable_with_http_connect_on_start! by
# default. This is needed to prevent Kubeclient from connecting to a
# host before the request is stubbed.
config.before(:each, :kubeclient) do
webmock_enable!
end
end
...@@ -15,4 +15,20 @@ def webmock_allowed_hosts ...@@ -15,4 +15,20 @@ def webmock_allowed_hosts
end.compact.uniq end.compact.uniq
end end
WebMock.disable_net_connect!(allow_localhost: true, allow: webmock_allowed_hosts) # This prevents Selenium/WebMock from spawning thousands of connections
# while waiting for an element to appear via Capybara's find:
# https://github.com/teamcapybara/capybara/issues/2322#issuecomment-619321520
def webmock_enable_with_http_connect_on_start!
webmock_enable!(net_http_connect_on_start: true)
end
def webmock_enable!(options = {})
WebMock.disable_net_connect!(
{
allow_localhost: true,
allow: webmock_allowed_hosts
}.merge(options)
)
end
webmock_enable!
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