Ruby:并行运行外部进程并跟踪退出代码



我有一个冒烟测试,在我的服务器上运行之前。目前,它以串行形式运行,每台服务器大约需要60秒。我可以并行运行这些,我已经用Thread.new做过了,这很好,因为它运行它们快得多,但我忘记了测试是否实际上通过了。

我正试图通过使用Process.spawn来管理我的流程来改善这一点。

pids = []
uris.each do |uri|
    command = get_http_tests_command("Smoke")
    update_http_tests_config( uri )
    pid = Process.spawn( system( command ) )
    pids.push pid
    Process.detach pid
end
# make sure all pids return a passing status code
# results = Process.waitall

我想启动所有的测试,但之后要确保所有的测试都返回一个通过的状态码。

我尝试使用Process.waitall,但我认为这是不正确的,用于分叉,而不是产卵。

在所有进程完成后,如果它们都通过,我希望返回true状态,如果其中任何一个失败,则返回false状态。

这里的

文档

尝试:

statuses = pids.map { |pid| Process.wait(pid, 0); $? }

等待每个进程id完成,并检查$?中为每个进程设置的结果状态

最新更新