spec: fix signal trapping in selenium specs, remove cruft
now you can Ctrl-C to stop selenium, specs \o/ remove unused error handling logic, shuffle some stuff Change-Id: I50c3dc093242d41b9764d33e50b06bc8daef1c07 Reviewed-on: https://gerrit.instructure.com/69758 Tested-by: Jenkins Reviewed-by: Jeremy Stanley <jeremy@instructure.com> Product-Review: Jon Jensen <jon@instructure.com> QA-Review: Jon Jensen <jon@instructure.com>
This commit is contained in:
parent
479be5283a
commit
e2eb88098c
|
@ -43,13 +43,9 @@ $server_port = nil
|
|||
$app_host_and_port = nil
|
||||
|
||||
at_exit do
|
||||
[1, 2, 3].each do
|
||||
begin
|
||||
$selenium_driver.try(:quit)
|
||||
break
|
||||
rescue Timeout::Error => te
|
||||
puts "rescued timeout error from selenium_driver quit : #{te}"
|
||||
end
|
||||
begin
|
||||
$selenium_driver.try(:quit)
|
||||
rescue Errno::ECONNREFUSED
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -69,6 +65,20 @@ shared_context "in-process server selenium tests" do
|
|||
# set up so you can use rails urls helpers in your selenium tests
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
around do |example|
|
||||
example.run
|
||||
exception = example.example.exception
|
||||
case exception
|
||||
when EOFError, Errno::ECONNREFUSED
|
||||
if $selenium_driver && !RSpec.wants_to_quit
|
||||
puts "SELENIUM: webdriver socket closed the connection. Will try to re-initialize."
|
||||
# this will cause the selenium driver to get re-initialized if it
|
||||
# crashes for some reason
|
||||
$selenium_driver = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
prepend_before :all do
|
||||
SeleniumDriverSetup.allow_requests!
|
||||
end
|
||||
|
@ -89,25 +99,8 @@ shared_context "in-process server selenium tests" do
|
|||
end
|
||||
|
||||
append_before :each do
|
||||
#the driver sometimes gets in a hung state and this if almost always the first line of code to catch it
|
||||
begin
|
||||
tries ||= 3
|
||||
driver.manage.timeouts.implicit_wait = 3
|
||||
driver.manage.timeouts.script_timeout = 60
|
||||
EncryptedCookieStore.test_secret = SecureRandom.hex(64)
|
||||
enable_forgery_protection
|
||||
rescue
|
||||
if ENV['PARALLEL_EXECS'] != nil
|
||||
#cleans up and provisions a new driver
|
||||
puts "ERROR: thread: #{THIS_ENV} selenium server hung, attempting to recover the node"
|
||||
$selenium_driver = nil
|
||||
$selenium_driver ||= setup_selenium
|
||||
default_url_options[:host] = $app_host_and_port
|
||||
retry unless (tries -= 1).zero?
|
||||
else
|
||||
raise # preserve original error
|
||||
end
|
||||
end
|
||||
EncryptedCookieStore.test_secret = SecureRandom.hex(64)
|
||||
enable_forgery_protection
|
||||
end
|
||||
|
||||
before do
|
||||
|
|
|
@ -20,6 +20,7 @@ module SeleniumDriverSetup
|
|||
end
|
||||
|
||||
driver.manage.timeouts.implicit_wait = 3
|
||||
driver.manage.timeouts.script_timeout = 60
|
||||
driver
|
||||
end
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ class SpecFriendlyThinServer
|
|||
def self.run(app, options = {})
|
||||
bind_address = options[:BindAddress] || IPSocket.getaddress(Socket.gethostname)
|
||||
port = options[:Port]
|
||||
@server = Thin::Server.new(bind_address, port, app)
|
||||
@server = Thin::Server.new(bind_address, port, app, signals: false)
|
||||
Thin::Logging.logger = Rails.logger
|
||||
Thread.new do
|
||||
Thread.current.abort_on_exception = true
|
||||
|
|
|
@ -32,25 +32,10 @@ RSpec.configure do |c|
|
|||
Timeout::timeout(180) do
|
||||
Rails.logger.info "STARTING SPEC #{example.full_description}"
|
||||
example.run
|
||||
exception = example.example.exception
|
||||
case exception
|
||||
when EOFError, Errno::ECONNREFUSED
|
||||
if $selenium_driver
|
||||
puts "SELENIUM: webdriver socket closed the connection. Will try to re-initialize."
|
||||
# this will cause the selenium driver to get re-initialized if it
|
||||
# crashes for some reason
|
||||
$selenium_driver = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
; require File.expand_path(File.dirname(__FILE__) + "/../parallelized_specs/lib/parallelized_specs.rb");
|
||||
rescue LoadError;
|
||||
end
|
||||
|
||||
ENV["RAILS_ENV"] = 'test'
|
||||
|
||||
require File.expand_path('../../config/environment', __FILE__) unless defined?(Rails)
|
||||
|
|
Loading…
Reference in New Issue