3

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.

4

3 回答 3

2

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'
于 2011-11-14T23:29:44.140 回答
0

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.

于 2011-11-16T11:08:40.533 回答
0

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

于 2013-10-03T22:32:34.760 回答