Reputation: 183
When rspec is executed, there is no response for a long time, then Net :: ReadTimeout: occurs and the test fails.
Currently, we are building a development environment for rails 5.1.7 on Ubuntu docker. And on that, in order to do the view test including js, the test environment is built with selenium_chrome_headless of system test.
I removed the source for application.html.erb to identify where the error occurred.
As a result, we found that <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
would time out.
Below is some code for that.
application.html.erb
<!DOCTYPE html>
<html>
<head>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
</head>
<body>
</body>
</html>
spec/views/hoges/index_spec.rb
require 'rails_helper'
RSpec.feature 'MetaFramesIndex', type: :system, js: true do
scenario 'sample' do
visit hoges_index_path
end
end
Part of rails_helper.rb
Capybara.register_driver :selenium_chrome_headless do |app|
browser_options = ::Selenium::WebDriver::Chrome::Options.new
browser_options.args << '--headless'
browser_options.args << '--no-sandbox'
browser_options.args << '--disable-gpu'
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end
config.before(:each) do |example|
if example.metadata[:type] == :system
driven_by :selenium_chrome_headless, screen_size: [1400, 1400]
end
end
error log
Failure/Error: visit hoges_index_path
Net::ReadTimeout:
Net::ReadTimeout
[Screenshot]: tmp/screenshots/failures_r_spec_example_groups_hoges_index_sample_529.png
~~~~
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/http/default.rb:129:in `response_for'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/http/default.rb:82:in `request'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/http/common.rb:64:in `call'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/bridge.rb:167:in `execute'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/w3c/bridge.rb:567:in `execute'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/w3c/bridge.rb:59:in `get'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/navigation.rb:32:in `to'
# /usr/local/bundle/gems/capybara-2.18.0/lib/capybara/selenium/driver.rb:49:in `visit'
# /usr/local/bundle/gems/capybara-2.18.0/lib/capybara/session.rb:274:in `visit'
# /usr/local/bundle/gems/capybara-2.18.0/lib/capybara/dsl.rb:50:in `block (2 levels) in <module:DSL>'
# ./spec/views/hoges/index_spec.rb:7:in `block (2 levels) in <top (required)>'
I want the response to come back early and not time out.
We will wait for the answer.
Upvotes: 2
Views: 4513
Reputation: 49950
If the response only times out for the first test it's probably that building your asset pipeline is taking too long. One solution for that is to precompile assets for the test environment before running the tests. Another potential issue is if the chromedriver you have installed doesn't match the Chrome version you're running. You can solve that by using the webdrivers
gem (fully remove the chromedriver-helper
gem first - including any binary shims it has installed).
Other issues brought up by your logs/code is that the version of Capybara you're running was released 18 months ago, it's time to update (In current versions you can increase the comms timeout by passing a :timeout option to Capybara::Selenium::Driver.new
- https://github.com/teamcapybara/capybara/blob/master/lib/capybara/selenium/driver.rb#L42). Additionally it's not really clear why you're writing view specs that are actually system specs.
Upvotes: 6