咖啡脚本 cakefile 任务未完成

发布于 2024-12-15 15:46:22 字数 884 浏览 3 评论 0原文

我有以下 cakefile 任务来运行硒测试,该测试运行成功并到达测试结束但不退出。

muffin = require 'muffin'
wrench = require 'wrench'
http   = require 'http'
fs     = require 'fs'
spawn  = require('child_process').spawn
exec   = require('child_process').exec

task 'selenium', 'run selenium tests', (options) ->
    sel = require './test/selenium'
    app = spawn 'node', ['app.js']
    app.stdout.on 'data', (data) ->
        if /listening on port/.test data
            selenium = spawn 'selenium'
            selenium.stdout.on 'data', (data) ->
                console.log 'stdout: ' + data
                if /Started.*jetty.Server/.test data
                    sel.run ->
                        app.stdin.end()
                        selenium.stdin.end()
                        console.log 'completed Selenium Tests'

有什么方法可以告诉任务完成吗?我在控制台中记录了“已完成的 Selenium 测试”。

I have the following cakefile task to run selenium tests which runs successfully and gets to the end of the tests but doesn't exit.

muffin = require 'muffin'
wrench = require 'wrench'
http   = require 'http'
fs     = require 'fs'
spawn  = require('child_process').spawn
exec   = require('child_process').exec

task 'selenium', 'run selenium tests', (options) ->
    sel = require './test/selenium'
    app = spawn 'node', ['app.js']
    app.stdout.on 'data', (data) ->
        if /listening on port/.test data
            selenium = spawn 'selenium'
            selenium.stdout.on 'data', (data) ->
                console.log 'stdout: ' + data
                if /Started.*jetty.Server/.test data
                    sel.run ->
                        app.stdin.end()
                        selenium.stdin.end()
                        console.log 'completed Selenium Tests'

Is there a way I can tell the task to finish? I get the 'completed Selenium Tests' logged in the console.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

み青杉依旧 2024-12-22 15:46:23

如果两个子进程(appselenium)之一仍在运行,则主进程将继续运行。对它们调用 stdin.end() 不会改变这一点。你想要做的就是用恰当的名称 来强迫它们死亡杀死方法

app.kill()
selenium.kill()
console.log 'completed Selenium Tests'

If one of the two child processes (app and selenium) is still running, the main process will keep running. Calling stdin.end() on them doesn't change this. What you want to do is to force them to die, with the aptly-named kill method:

app.kill()
selenium.kill()
console.log 'completed Selenium Tests'
眼藏柔 2024-12-22 15:46:23

特雷弗·伯纳姆(Trevor Burnham)为我指明了正确的方向。但根本问题是我生成的 selenium 子进程是一个运行 java 进程的 shell 脚本。所以基本上,当调用 app.kill() 时,它会杀死 shell 脚本,但不会杀死底层的 java 进程。

感谢您的帮助。

Trevor Burnham, pointed my in the right direction. But the underlying issue was that the selenium child process i was spawning was a shell script running a java process. So basically when calling app.kill() it was killing the shell script but not the underlying java process.

Thanks for the help.

み青杉依旧 2024-12-22 15:46:23

另一种选择是调用process.exit()。不过,我不确定这对孩子有什么影响。

Another option is to call process.exit(). Though, I'm not sure what the effect is on children.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文