DEV: Monkey patch `Selenium::WebDriver::Platform.localhost` to retry (#27335)
On Github Actions, system tests which uses `Capybara#using_session` are failing intermittently with the error "Socket::ResolutionError: getaddrinfo: Temporary failure in name resolution" when `Selenium::WebDriver::Platform.localhost` tries to resolve `localhost`. Too much time has been spent trying to figure out why so we are giving up here and just retrying the resolution of `localhost` on Github Actions.
This commit is contained in:
parent
9705bd6cbe
commit
9ff0805a1d
|
@ -519,29 +519,34 @@ RSpec.configure do |config|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
config.around do |example|
|
# This is a monkey patch for the `Selenium::WebDriver::Platform.localhost` method in `selenium-webdriver`. For some
|
||||||
example.run
|
# unknown reasons on Github Actions, we are seeing system tests failing intermittently with the error
|
||||||
|
# `Socket::ResolutionError: getaddrinfo: Temporary failure in name resolution` when `selenium-webdriver` tries to
|
||||||
|
# resolve `localhost` in a `Capybara#using_session` block.
|
||||||
|
#
|
||||||
|
# Too much time has been spent trying to debug this issue and the root cause is still unknown so we are just dropping
|
||||||
|
# this workaround for now.
|
||||||
|
module Selenium
|
||||||
|
module WebDriver
|
||||||
|
module Platform
|
||||||
|
def self.localhost_with_retry
|
||||||
|
attempts = 0
|
||||||
|
|
||||||
if example.exception.is_a?(Socket::ResolutionError)
|
begin
|
||||||
info = Socket.getaddrinfo("localhost", 80, Socket::AF_INET, Socket::SOCK_STREAM)
|
localhost_without_retry
|
||||||
etc_hosts = `cat /etc/hosts`
|
rescue Socket::ResolutionError
|
||||||
resolve_conf = `cat /etc/resolv.conf`
|
attempts += 1
|
||||||
nsswitch = `cat /etc/nsswitch.conf`
|
attempts <= 3 ? retry : raise
|
||||||
|
end
|
||||||
puts <<~MSG
|
end
|
||||||
Failed to resolve localhost, available addresses: #{info}
|
end
|
||||||
|
|
||||||
/etc/hosts:
|
|
||||||
#{etc_hosts}
|
|
||||||
|
|
||||||
/etc/resolv.conf:
|
|
||||||
#{resolve_conf}
|
|
||||||
|
|
||||||
/etc/nsswitch.conf:
|
|
||||||
#{nsswitch}
|
|
||||||
MSG
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Selenium::WebDriver::Platform.singleton_class.class_eval do
|
||||||
|
alias_method :localhost_without_retry, :localhost
|
||||||
|
alias_method :localhost, :localhost_with_retry
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if ENV["DISCOURSE_RSPEC_PROFILE_EACH_EXAMPLE"]
|
if ENV["DISCOURSE_RSPEC_PROFILE_EACH_EXAMPLE"]
|
||||||
|
|
Loading…
Reference in New Issue