1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

allow running two integration tests in parallel

This commit is contained in:
Konstantin Haase 2011-10-31 15:58:04 -07:00
parent 862fe21a30
commit d9ec3c6960

View file

@ -8,6 +8,13 @@ class IntegrationTest < Test::Unit::TestCase
File.expand_path('../integration/app.rb', __FILE__) File.expand_path('../integration/app.rb', __FILE__)
end end
def port
min = 49152
max = 65535
mod = max - min
(Process.pid % mod) + min
end
def command def command
cmd = [] cmd = []
if RbConfig.respond_to? :ruby if RbConfig.respond_to? :ruby
@ -17,27 +24,31 @@ class IntegrationTest < Test::Unit::TestCase
cmd << File.expand_path(file, dir).inspect cmd << File.expand_path(file, dir).inspect
end end
cmd << "-I" << File.expand_path('../../lib', __FILE__).inspect cmd << "-I" << File.expand_path('../../lib', __FILE__).inspect
cmd << app_file.inspect cmd << app_file.inspect << '-p' << port << '2>&1'
cmd << "2>&1"
cmd.join(" ") cmd.join(" ")
end end
def with_server def with_server
pipe = IO.popen(command) pipe = IO.popen(command)
error = nil
Timeout.timeout(10) do Timeout.timeout(10) do
begin begin
yield yield
rescue Errno::ECONNREFUSED rescue Errno::ECONNREFUSED => e
error = e
sleep 0.1 sleep 0.1
retry retry
end end
end end
Process.kill("TERM", pipe.pid) rescue Timeout::Error => e
raise error || e
ensure
Process.kill("TERM", pipe.pid) if pipe
end end
it 'starts a top level application' do it 'starts a top level application' do
with_server do with_server do
assert_equal open('http://localhost:4567/app_file').read, app_file assert_equal open("http://127.0.0.1:#{port}/app_file").read, app_file
end end
end end
end end