Commit f5860ce6 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'rs-transient-capybara-timeout' into 'master'

Prevent transient Capybara timeouts during feature tests

The problem occurred because asset compilation takes a long time, so
when the asset cache didn't exist and the first test ran, it would often
(randomly) time out during the generation before the actual test even
had a chance to run.

Now we check if the cache exists before the suite runs, and if not, we
manually fire a request to the root URL in order to generate it. This
should allow subsequent tests to use the cached assets.

See merge request !2646
parents 74e1add2 bbe0fa91
...@@ -9,10 +9,6 @@ Capybara.register_driver :poltergeist do |app| ...@@ -9,10 +9,6 @@ Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, js_errors: true, timeout: timeout) Capybara::Poltergeist::Driver.new(app, js_errors: true, timeout: timeout)
end end
Spinach.hooks.on_tag("javascript") do
Capybara.current_driver = Capybara.javascript_driver
end
Capybara.default_wait_time = timeout Capybara.default_wait_time = timeout
Capybara.ignore_hidden_elements = false Capybara.ignore_hidden_elements = false
...@@ -22,3 +18,7 @@ unless ENV['CI'] || ENV['CI_SERVER'] ...@@ -22,3 +18,7 @@ unless ENV['CI'] || ENV['CI_SERVER']
# Keep only the screenshots generated from the last failing test suite # Keep only the screenshots generated from the last failing test suite
Capybara::Screenshot.prune_strategy = :keep_last_run Capybara::Screenshot.prune_strategy = :keep_last_run
end end
Spinach.hooks.before_run do
TestEnv.warm_asset_cache
end
...@@ -19,3 +19,9 @@ unless ENV['CI'] || ENV['CI_SERVER'] ...@@ -19,3 +19,9 @@ unless ENV['CI'] || ENV['CI_SERVER']
# Keep only the screenshots generated from the last failing test suite # Keep only the screenshots generated from the last failing test suite
Capybara::Screenshot.prune_strategy = :keep_last_run Capybara::Screenshot.prune_strategy = :keep_last_run
end end
RSpec.configure do |config|
config.before(:suite) do
TestEnv.warm_asset_cache
end
end
...@@ -146,6 +146,22 @@ module TestEnv ...@@ -146,6 +146,22 @@ module TestEnv
FileUtils.chmod_R 0755, target_repo_path FileUtils.chmod_R 0755, target_repo_path
end end
# When no cached assets exist, manually hit the root path to create them
#
# Otherwise they'd be created by the first test, often timing out and
# causing a transient test failure
def warm_asset_cache
return if warm_asset_cache?
return unless defined?(Capybara)
Capybara.current_session.driver.visit '/'
end
def warm_asset_cache?
cache = Rails.root.join(*%w(tmp cache assets test))
Dir.exist?(cache) && Dir.entries(cache).length > 2
end
private private
def factory_repo_path def factory_repo_path
...@@ -172,7 +188,6 @@ module TestEnv ...@@ -172,7 +188,6 @@ module TestEnv
'gitlab-test-fork' 'gitlab-test-fork'
end end
# Prevent developer git configurations from being persisted to test # Prevent developer git configurations from being persisted to test
# repositories # repositories
def git_env def git_env
......
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