a much more robust qunit daemonizer

This commit is contained in:
Sam 2013-07-30 14:15:20 +10:00
parent 7e5c7f5987
commit 9749001b54
1 changed files with 17 additions and 1 deletions

View File

@ -3,12 +3,27 @@ desc "Runs the qunit test suite"
task "qunit:test" => :environment do task "qunit:test" => :environment do
require "rack" require "rack"
require "socket"
unless %x{which phantomjs > /dev/null 2>&1} unless %x{which phantomjs > /dev/null 2>&1}
abort "PhantomJS is not installed. Download from http://phantomjs.org" abort "PhantomJS is not installed. Download from http://phantomjs.org"
end end
# ensure we have this port available
def port_available? port
server = TCPServer.open port
server.close
true
rescue Errno::EADDRINUSE
false
end
port = ENV['TEST_SERVER_PORT'] || 60099 port = ENV['TEST_SERVER_PORT'] || 60099
while !port_available? port
port += 1
end
unless pid = fork unless pid = fork
Rack::Server.start(:config => "config.ru", Rack::Server.start(:config => "config.ru",
:AccessLog => [], :AccessLog => [],
@ -42,7 +57,8 @@ task "qunit:test" => :environment do
success &&= $?.success? success &&= $?.success?
ensure ensure
Process.kill "HUP", pid # was having issues with HUP
Process.kill "KILL", pid
end end
if success if success