bind selenium thin server to 0.0.0.0 by default

the selenium thin server was using getaddress/gethostname to choose
an address to bind to. this was intermittently prevening the browser
from connecting to the server because the bind ip was selected
differently than the ip given to the browser.

fixes #CNVS-5761

Change-Id: I759f667d3eb677014faf5a539434849a8c7e58d2
Reviewed-on: https://gerrit.instructure.com/20422
Reviewed-by: Bryan Madsen <bryan@instructure.com>
Product-Review: Bryan Madsen <bryan@instructure.com>
QA-Review: Bryan Madsen <bryan@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
This commit is contained in:
Mark Severson 2013-05-07 10:55:32 -06:00
parent b1751ef05c
commit d7b4f2f513
2 changed files with 8 additions and 6 deletions

View File

@ -27,6 +27,7 @@ include I18nUtilities
SELENIUM_CONFIG = Setting.from_config("selenium") || {}
SERVER_IP = SELENIUM_CONFIG[:server_ip] || UDPSocket.open { |s| s.connect('8.8.8.8', 1); s.addr.last }
BIND_ADDRESS = SELENIUM_CONFIG[:bind_address] || '0.0.0.0'
SECONDS_UNTIL_COUNTDOWN = 5
SECONDS_UNTIL_GIVING_UP = 20
MAX_SERVER_START_TIME = 60
@ -239,7 +240,7 @@ module SeleniumTestsHelperMethods
def self.start_in_process_thin_server
server = SpecFriendlyThinServer
app = self.rack_app
server.run(app, $server_port, :AccessLog => [])
server.run(app, :BindAddress => BIND_ADDRESS, :Port => $server_port, :AccessLog => [])
shutdown = self.shutdown_webserver(server)
return shutdown
end
@ -247,7 +248,7 @@ module SeleniumTestsHelperMethods
def self.start_in_process_webrick_server
server = SpecFriendlyWEBrickServer
app = self.rack_app
server.run(app, :Port => $server_port, :AccessLog => [])
server.run(app, :BindAddress => BIND_ADDRESS, :Port => $server_port, :AccessLog => [])
shutdown = self.shutdown_webserver(server)
return shutdown
end

View File

@ -2,12 +2,13 @@ require 'thin'
require 'socket'
class SpecFriendlyThinServer
def self.run(app, port, options = {})
ip = IPSocket.getaddress(Socket.gethostname)
@server = Thin::Server.new(ip, port, app)
def self.run(app, options = {})
bind_address = options[:BindAddress] || IPSocket.getaddress(Socket.gethostname)
port = options[:Port]
@server = Thin::Server.new(bind_address, port, app)
Thread.new {@server.start}
for i in 0..MAX_SERVER_START_TIME
s = TCPSocket.open(ip, port) rescue nil
s = TCPSocket.open(bind_address, port) rescue nil
break if s
sleep 1
end