From 199517abaa880dc5473a24bb318d60f8fa18c8e7 Mon Sep 17 00:00:00 2001 From: "Wilhelm Bierbaum wilhelm@twitter.com" Date: Mon, 8 Mar 2010 11:05:58 -0800 Subject: [PATCH] When the SELENIUM_SERVER_PORT environment variable is set, it will be used and a RC server will not be started --- lib/jasmine/config.rb | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/lib/jasmine/config.rb b/lib/jasmine/config.rb index 87db4e5..0f2bc5a 100644 --- a/lib/jasmine/config.rb +++ b/lib/jasmine/config.rb @@ -27,29 +27,40 @@ module Jasmine stop_servers end - def start_servers + def start_jasmine_server @jasmine_server_port = Jasmine::find_unused_port - @selenium_server_port = Jasmine::find_unused_port - server = Jasmine::Server.new(@jasmine_server_port, self) - - @selenium_pid = fork do - Process.setpgrp - exec "java -jar #{@selenium_jar_path} -port #{@selenium_server_port} > /dev/null 2>&1" - end - puts "selenium started. pid is #{@selenium_pid}" - @jasmine_server_pid = fork do Process.setpgrp server.start exit! 0 end puts "jasmine server started. pid is #{@jasmine_server_pid}" - - Jasmine::wait_for_listener(@selenium_server_port, "selenium server") Jasmine::wait_for_listener(@jasmine_server_port, "jasmine server") end + def external_selenium_server_port + ENV['SELENIUM_SERVER_PORT'] && ENV['SELENIUM_SERVER_PORT'].to_i > 0 ? ENV['SELENIUM_SERVER_PORT'].to_i : nil + end + + def start_selenium_server + @selenium_server_port = external_selenium_server_port + if @selenium_server_port.nil? + @selenium_server_port = Jasmine::find_unused_port + @selenium_pid = fork do + Process.setpgrp + exec "java -jar #{@selenium_jar_path} -port #{@selenium_server_port} > /dev/null 2>&1" + end + puts "selenium started. pid is #{@selenium_pid}" + end + Jasmine::wait_for_listener(@selenium_server_port, "selenium server") + end + + def start_servers + start_jasmine_server + start_selenium_server + end + def stop_servers puts "shutting down the servers..." Jasmine::kill_process_group(@selenium_pid) if @selenium_pid