I need to start a rails server on Travis to run integration tests. I've added this to the config file:
before_script:
- psql -c 'create database scalia_test;' -U postgres
- "bundle exec rails server -p 3000 &"
However, I still get an error from Cypress:
http://localhost:3000/users/sign_in
We attempted to make an http request to this URL but the request failed without a response.
We received this error at the network level:
> Error: connect ECONNREFUSED 127.0.0.1:3000
Common situations why this would fail:
- you don't have internet access
- you forgot to run / boot your web server
- your web server isn't accessible
- you have weird network configuration settings on your computer
The stack trace for this error is:
Error: connect ECONNREFUSED 127.0.0.1:3000
at Object.exports._errnoException (util.js:1024:11)
at exports._exceptionWithHostPort (util.js:1047:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1150:14)
Does anybody knows how to start a Rails server on Travis ?
You are using &
to send the command to the background, then you are running your tests right?
By the time you are running the tests Travis is still booting up your Rails server in the background therefore it's erroring out saying it can't connect. In my opinion it doesn't have to do anything with port binding.
In order to fix that you should use the -d parameter to daemonize rails after it started:
before_script:
- psql -c 'create database scalia_test;' -U postgres
- "bundle exec rails server -p 3000 -d"
rails server will block until it listens on port 3000 then sends itself to the background and continue running your scripts.
Do note that after your tests have run you may kill the rails server again using:
kill -9 $(cat tmp/pids/server.pid)
Otherwise you'll get a timeout or another error from travis.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With