gpt4 book ai didi

ruby-on-rails - 特拉维斯 CI : start rails server

转载 作者:行者123 更新时间:2023-12-04 11:49:11 24 4
gpt4 key购买 nike

我需要在 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 服务器吗?

最佳答案

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

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

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

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

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

请注意,在您的测试运行后,您可能会再次使用以下命令终止 rails 服务器:
kill -9 $(cat tmp/pids/server.pid)

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

关于ruby-on-rails - 特拉维斯 CI : start rails server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49954283/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com