gpt4 book ai didi

shell - 在后台运行进程并等待其准备就绪的最佳实践

转载 作者:行者123 更新时间:2023-12-02 03:25:19 25 4
gpt4 key购买 nike

系统:

  • 用 Java (Play Framework 2.3.x) 编写的后端应用程序 (RESTful HTTP API)
  • 用 Javascript(angularjs 和用于构建的 grunt)编写的前端应用程序(GUI,使用 API)
  • Travis CI 用于持续集成

问题:

我想启动/运行后端应用程序,在它成功启动后,我想用 protractor 测试它(通过 grunt 任务)。

但是启动后端应用程序不会继续,因为它不是结束过程(服务器正在运行 -> 未结束)

通过添加&将服务器作为后端进程启动可以解决问题,但不能保证服务器同时启动。

网上的一些建议是这样说的:

Add sleep(x) and run your test after that

但是 x 是多少?

有没有其他方法可以做到这一点,而不是猜测(或测量)启动服务器的时间并在服务器启 Action 为后台进程运行后进入休眠状态?

编辑:启动服务器的输出(例如以周期性方式比较后台任务的输出)是这样的:

$ activator run
[info] Loading project definition from ...
[info] Set current project to ... (in build file:...)

--- (Running the application, auto-reloading is enabled) ---

[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000

(Server started, use Ctrl+D to stop and go back to the console...)

最佳答案

通过简单的外部测试来查看服务器是否已启动,您可以比猜测或估计测试前 sleep 多长时间做得更好,例如,

while ! curl -s 0:0:0:0:0:0:0:0:9000 >/dev/null; do
sleep 1
done

# now start real tests
...

关于shell - 在后台运行进程并等待其准备就绪的最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30708090/

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