Be smarter about picking a server port, so multiple instances could run on the same box
This commit is contained in:
parent
ae610eca0d
commit
8b7ecc3f5c
@ -1,6 +1,14 @@
|
|||||||
|
require 'socket'
|
||||||
require 'erb'
|
require 'erb'
|
||||||
|
|
||||||
module Jasmine
|
module Jasmine
|
||||||
|
def self.find_unused_port
|
||||||
|
socket = TCPserver.open(0)
|
||||||
|
port = socket.addr[1]
|
||||||
|
socket.close
|
||||||
|
port
|
||||||
|
end
|
||||||
|
|
||||||
class RunAdapter
|
class RunAdapter
|
||||||
def initialize(spec_files)
|
def initialize(spec_files)
|
||||||
p "spec_files: #{spec_files}"
|
p "spec_files: #{spec_files}"
|
||||||
@ -20,7 +28,7 @@ module Jasmine
|
|||||||
end
|
end
|
||||||
|
|
||||||
class SimpleServer
|
class SimpleServer
|
||||||
def self.start(spec_dir, mappings)
|
def self.start(port, spec_dir, mappings)
|
||||||
require "thin"
|
require "thin"
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
@ -32,7 +40,8 @@ module Jasmine
|
|||||||
|
|
||||||
app = Rack::URLMap.new(config)
|
app = Rack::URLMap.new(config)
|
||||||
|
|
||||||
Thin::Server.start('0.0.0.0', 8080, app)
|
server_port = Jasmine::find_unused_port
|
||||||
|
Thin::Server.start('0.0.0.0', port, app)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -54,7 +63,7 @@ module Jasmine
|
|||||||
|
|
||||||
def run()
|
def run()
|
||||||
@driver.start
|
@driver.start
|
||||||
@driver.open(@http_address)
|
@driver.open("/run.html")
|
||||||
|
|
||||||
until tests_have_finished? do
|
until tests_have_finished? do
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
@ -77,21 +86,24 @@ module Jasmine
|
|||||||
selenium_pid = nil
|
selenium_pid = nil
|
||||||
jasmine_server_pid = nil
|
jasmine_server_pid = nil
|
||||||
begin
|
begin
|
||||||
|
jasmine_server_port = Jasmine::find_unused_port
|
||||||
|
selenium_server_port = Jasmine::find_unused_port
|
||||||
|
|
||||||
selenium_pid = fork do
|
selenium_pid = fork do
|
||||||
exec "java -jar #{@selenium_jar_path}"
|
exec "java -jar #{@selenium_jar_path} -port #{selenium_server_port}"
|
||||||
end
|
end
|
||||||
puts "selenium started. pid is #{selenium_pid}"
|
puts "selenium started. pid is #{selenium_pid}"
|
||||||
|
|
||||||
jasmine_server_pid = fork do
|
jasmine_server_pid = fork do
|
||||||
Jasmine::SimpleServer.start(@spec_files, @dir_mappings)
|
Jasmine::SimpleServer.start(jasmine_server_port, @spec_files, @dir_mappings)
|
||||||
end
|
end
|
||||||
puts "jasmine server started. pid is #{jasmine_server_pid}"
|
puts "jasmine server started. pid is #{jasmine_server_pid}"
|
||||||
|
|
||||||
wait_for_listener(4444, "selenium server")
|
wait_for_listener(selenium_server_port, "selenium server")
|
||||||
wait_for_listener(8080, "jasmine server")
|
wait_for_listener(jasmine_server_port, "jasmine server")
|
||||||
|
|
||||||
puts "servers are listening on their ports -- running the test script..."
|
puts "servers are listening on their ports -- running the test script..."
|
||||||
tests_passed = Jasmine::SimpleClient.new("localhost", 4444, "*firefox", "http://localhost:8080/run.html").run
|
tests_passed = Jasmine::SimpleClient.new("localhost", selenium_server_port, "*firefox", "http://localhost:#{jasmine_server_port}/").run
|
||||||
ensure
|
ensure
|
||||||
puts "shutting down the servers..."
|
puts "shutting down the servers..."
|
||||||
Process.kill 15, selenium_pid if selenium_pid
|
Process.kill 15, selenium_pid if selenium_pid
|
||||||
|
Loading…
Reference in New Issue
Block a user