【问题标题】:Travis CI: start rails serverTravis CI:启动 Rails 服务器
【发布时间】:2018-04-21 09:27:07
【问题描述】:

我需要在 Travis 上启动一个 Rails 服务器来运行集成测试。 我已将此添加到配置文件中:

before_script:
  - psql -c 'create database scalia_test;' -U postgres
  - "bundle exec rails server -p 3000 &"

但是,我仍然收到来自 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)

有人知道如何在 Travis 上启动 Rails 服务器吗?

【问题讨论】:

  • 在启动服务器后尝试添加sleep 3 命令。还要确保设置了RAILS_ENV=test 环境变量
  • 这有什么更新吗?从未收到您的任何反馈

标签: ruby-on-rails travis-ci cypress


【解决方案1】:

您正在使用& 将命令发送到后台,那么您正在运行测试对吗?

当你运行测试时,Travis 仍在后台启动你的 Rails 服务器,因此它会出错,说它无法连接。在我看来,它不必对端口绑定做任何事情。

为了解决这个问题,您应该使用 -d 参数在 Rails 启动后对其进行守护:

before_script:
  - psql -c 'create database scalia_test;' -U postgres
  - "bundle exec rails server -p 3000 -d"

rails 服务器会一直阻塞,直到它监听 3000 端口,然后将自身发送到后台并继续运行您的脚本。

请注意,在您的测试运行后,您可能会再次使用以下命令终止 rails 服务器:

kill -9 $(cat tmp/pids/server.pid)

否则,您会从 travis 收到超时或其他错误。

【讨论】:

    【解决方案2】:

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

    bundle exec rails s -p 3000 -b 127.0.0.1
    

    【讨论】:

      【解决方案3】:

      可能该端口正在使用中。在终端中输入lsof -i :8000 以查看该端口是否正在使用 你可以尝试用不同的端口启动服务器,比如rails server -p 3050

      【讨论】:

      • 我问的是 Travis,而不是我的本地机器。我无法在终端中运行“lsof -i :8000”
      • 顺便说一句,你是否意识到那些试图帮助你的人对未来帮助你或试图解决你的问题没有兴趣
      • 试图通过几乎不阅读问题并回答超出范围的内容来获取 SO 分数并没有帮助,并且可能会使未来的读者感到困惑,因此投反对票。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-24
      • 2012-04-20
      • 1970-01-01
      • 2012-12-12
      • 1970-01-01
      • 2023-03-12
      相关资源
      最近更新 更多