From 9749001b547a40fe52bce8bf72d5dc42c6ad8f0a Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 30 Jul 2013 14:15:20 +1000 Subject: [PATCH] a much more robust qunit daemonizer --- lib/tasks/qunit.rake | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/tasks/qunit.rake b/lib/tasks/qunit.rake index ac4abe56079..31cbe2a2df8 100644 --- a/lib/tasks/qunit.rake +++ b/lib/tasks/qunit.rake @@ -3,12 +3,27 @@ desc "Runs the qunit test suite" task "qunit:test" => :environment do require "rack" + require "socket" unless %x{which phantomjs > /dev/null 2>&1} abort "PhantomJS is not installed. Download from http://phantomjs.org" 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 + + while !port_available? port + port += 1 + end + unless pid = fork Rack::Server.start(:config => "config.ru", :AccessLog => [], @@ -42,7 +57,8 @@ task "qunit:test" => :environment do success &&= $?.success? ensure - Process.kill "HUP", pid + # was having issues with HUP + Process.kill "KILL", pid end if success