简体   繁体   中英

Travis CI: start rails server

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.

尝试将rails绑定到该端口中的环回IP

bundle exec rails s -p 3000 -b 127.0.0.1

probably that port is in use. Type lsof -i :8000 in terminal to see if that port is beeing used U can try to start server with difrent port like rails server -p 3050

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM