I am trying to do browser testing using Selenium, Chrome and a Ruby/Rails application using RSpec an Capybara. My builds pass successfully about every 1 in 4 runs; in the other 3, at some point all tests using Selenium fail with “connection refused” errors:
# Errno::ECONNREFUSED:
# Connection refused - connect(2) for "127.0.0.1" port 9515
I don’t have any other debug information to go on other than the connection refused errors. I also cannot reproduce it locally. I have tried using different versions of Chrome, chromedriver, running Selenium locally as a .jar and using a Selenium chrome-standalone docker image. But, as the tests sometimes pass and sometimes fail, I suspect the basic configuration is alright, but something in my tests breaks it, or some memory limit is hit somewhere.
Does anyone have any idea what might be wrong, or what might possibly fix it?
At a guess, you have a race condition between your tests starting and the Selenium server being ready to accept connections. Try waiting for five seconds before your tests using sleep.
If that fixes it, you can probably use a waitforit script that repeatedly tests a specified port and quits once the port is available.
I think I have found a test order in which the error does not occur, even without using the waitforit script. That means my environment is probably fine and something in my tests breaks it, although I’m at a loss to explain what. A tool like rspec --bisect will not produce any output for too long to be able to run it on CircleCI.