improve cuke process management, support OSRM_PORT
This commit is contained in:
parent
29344f55ae
commit
ae106a3a90
@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
When /^I preprocess data$/ do
|
When /^I preprocess data$/ do
|
||||||
begin
|
begin
|
||||||
osrm_kill
|
|
||||||
reprocess
|
reprocess
|
||||||
rescue OSRMError => e
|
rescue OSRMError => e
|
||||||
@process_error = e
|
@process_error = e
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
When /^I request \/(.*)$/ do |path|
|
When /^I request \/(.*)$/ do |path|
|
||||||
osrm_kill
|
|
||||||
reprocess
|
reprocess
|
||||||
OSRMLauncher.new do
|
OSRMLauncher.new do
|
||||||
@response = request_path path
|
@response = request_path path
|
||||||
|
@ -134,7 +134,6 @@ Then /^"([^"]*)" should be returned$/ do |route|
|
|||||||
end
|
end
|
||||||
|
|
||||||
Then /^routability should be$/ do |table|
|
Then /^routability should be$/ do |table|
|
||||||
osrm_kill
|
|
||||||
build_ways_from_table table
|
build_ways_from_table table
|
||||||
reprocess
|
reprocess
|
||||||
actual = []
|
actual = []
|
||||||
@ -176,7 +175,6 @@ Then /^routability should be$/ do |table|
|
|||||||
end
|
end
|
||||||
|
|
||||||
When /^I route I should get$/ do |table|
|
When /^I route I should get$/ do |table|
|
||||||
osrm_kill
|
|
||||||
reprocess
|
reprocess
|
||||||
actual = []
|
actual = []
|
||||||
OSRMLauncher.new do
|
OSRMLauncher.new do
|
||||||
@ -265,3 +263,11 @@ When /^I route I should get$/ do |table|
|
|||||||
end
|
end
|
||||||
table.routing_diff! actual
|
table.routing_diff! actual
|
||||||
end
|
end
|
||||||
|
|
||||||
|
When /^I route (\d+) times I should get$/ do |n,table|
|
||||||
|
ok = true
|
||||||
|
n.to_i.times do
|
||||||
|
ok = false unless step "I route I should get", table
|
||||||
|
end
|
||||||
|
ok
|
||||||
|
end
|
34
features/stress/launch.feature
Normal file
34
features/stress/launch.feature
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
@stress @launch
|
||||||
|
Feature: Launching and shutting down
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given the speedprofile "testbot"
|
||||||
|
|
||||||
|
Scenario: Repeated launch and shutdown
|
||||||
|
Given a grid size of 10000 meters
|
||||||
|
Given the node map
|
||||||
|
| h | a | b |
|
||||||
|
| g | x | c |
|
||||||
|
| f | e | d |
|
||||||
|
|
||||||
|
And the ways
|
||||||
|
| nodes | highway |
|
||||||
|
| xa | primary |
|
||||||
|
| xb | primary |
|
||||||
|
| xc | primary |
|
||||||
|
| xd | primary |
|
||||||
|
| xe | primary |
|
||||||
|
| xf | primary |
|
||||||
|
| xg | primary |
|
||||||
|
| xh | primary |
|
||||||
|
|
||||||
|
When I route 100 times I should get
|
||||||
|
| from | to | route |
|
||||||
|
| x | a | xa |
|
||||||
|
| x | b | xb |
|
||||||
|
| x | c | xc |
|
||||||
|
| x | d | xd |
|
||||||
|
| x | e | xe |
|
||||||
|
| x | f | xf |
|
||||||
|
| x | g | xg |
|
||||||
|
| x | h | xh |
|
@ -15,7 +15,7 @@ def write_server_ini
|
|||||||
s=<<-EOF
|
s=<<-EOF
|
||||||
Threads = 1
|
Threads = 1
|
||||||
IP = 0.0.0.0
|
IP = 0.0.0.0
|
||||||
Port = 5000
|
Port = #{OSRM_PORT}
|
||||||
|
|
||||||
hsgrData=#{@osm_file}.osrm.hsgr
|
hsgrData=#{@osm_file}.osrm.hsgr
|
||||||
nodesData=#{@osm_file}.osrm.nodes
|
nodesData=#{@osm_file}.osrm.nodes
|
||||||
|
@ -1 +1,11 @@
|
|||||||
require 'rspec/expectations'
|
require 'rspec/expectations'
|
||||||
|
|
||||||
|
DEFAULT_PORT = 5000
|
||||||
|
|
||||||
|
if ENV["OSRM_PORT"]
|
||||||
|
OSRM_PORT = ENV["OSRM_PORT"].to_i
|
||||||
|
puts "Port set to #{OSRM_PORT}"
|
||||||
|
else
|
||||||
|
OSRM_PORT = DEFAULT_PORT
|
||||||
|
puts "Using default port #{OSRM_PORT}"
|
||||||
|
end
|
@ -1,3 +1,6 @@
|
|||||||
|
|
||||||
|
STRESS_TIMEOUT = 300
|
||||||
|
|
||||||
Before do |scenario|
|
Before do |scenario|
|
||||||
@scenario_title = scenario.title
|
@scenario_title = scenario.title
|
||||||
@scenario_time = Time.now.strftime("%Y-%m-%dT%H:%m:%SZ")
|
@scenario_time = Time.now.strftime("%Y-%m-%dT%H:%m:%SZ")
|
||||||
@ -7,12 +10,11 @@ Before do |scenario|
|
|||||||
set_grid_size DEFAULT_GRID_SIZE
|
set_grid_size DEFAULT_GRID_SIZE
|
||||||
end
|
end
|
||||||
|
|
||||||
Around('@routing') do |scenario, block|
|
Around('@stress') do |scenario, block|
|
||||||
Timeout.timeout(10) do
|
Timeout.timeout(STRESS_TIMEOUT) do
|
||||||
block.call
|
block.call
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
After do
|
After do
|
||||||
osrm_kill
|
|
||||||
end
|
end
|
||||||
|
@ -1,71 +1,83 @@
|
|||||||
require 'socket'
|
require 'socket'
|
||||||
require 'sys/proctable'
|
require 'sys/proctable'
|
||||||
|
|
||||||
|
LAUNCH_TIMEOUT = 5
|
||||||
|
SHUTDOWN_TIMEOUT = 5
|
||||||
|
|
||||||
class OSRMLauncher
|
class OSRMLauncher
|
||||||
def initialize &block
|
def initialize &block
|
||||||
Dir.chdir TEST_FOLDER do
|
Dir.chdir TEST_FOLDER do
|
||||||
osrm_up
|
begin
|
||||||
yield
|
begin
|
||||||
osrm_down
|
Timeout.timeout(LAUNCH_TIMEOUT) do
|
||||||
end
|
osrm_up
|
||||||
end
|
wait_for_connection
|
||||||
end
|
end
|
||||||
|
rescue Timeout::Error
|
||||||
def each_process name, &block
|
raise "*** Launching osrm-routed timed out."
|
||||||
Sys::ProcTable.ps do |process|
|
end
|
||||||
if process.comm.strip == name.strip
|
yield
|
||||||
yield process.pid.to_i, process.state.strip
|
ensure
|
||||||
|
begin
|
||||||
|
Timeout.timeout(SHUTDOWN_TIMEOUT) do
|
||||||
|
osrm_down
|
||||||
|
end
|
||||||
|
rescue Timeout::Error
|
||||||
|
raise "*** Shutting down osrm-routed timed out."
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def osrm_up?
|
def osrm_up?
|
||||||
find_pid('osrm-routed') != nil
|
if @pipe
|
||||||
end
|
begin
|
||||||
|
Process.getpgid @pipe.pid
|
||||||
def find_pid name
|
true
|
||||||
each_process(name) { |pid,state| return pid.to_i }
|
rescue Errno::ESRCH
|
||||||
return nil
|
false
|
||||||
|
end
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def osrm_up
|
def osrm_up
|
||||||
return if osrm_up?
|
return if osrm_up?
|
||||||
pipe = IO.popen('../osrm-routed 1>>osrm-routed.log 2>>osrm-routed.log')
|
#exec avoids popen running osrm-routed inside a shell
|
||||||
timeout = 5
|
#if the cmd is run inside a shell, popen returns the pid for the shell, and if we try to kill it,
|
||||||
(timeout*10).times do
|
#the child process is orphaned, and we can't terminate it.
|
||||||
|
@pipe = IO.popen('exec ../osrm-routed 1>>osrm-routed.log 2>>osrm-routed.log')
|
||||||
|
end
|
||||||
|
|
||||||
|
def osrm_down
|
||||||
|
if @pipe
|
||||||
|
Process.kill 'TERM', @pipe.pid
|
||||||
|
wait_for_shutdown
|
||||||
|
@pipe = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def kill
|
||||||
|
if @pipe
|
||||||
|
Process.kill 'KILL', @pipe.pid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def wait_for_connection
|
||||||
|
while true
|
||||||
begin
|
begin
|
||||||
socket = TCPSocket.new('localhost', 5000)
|
socket = TCPSocket.new('localhost', OSRM_PORT)
|
||||||
socket.puts 'ping'
|
return
|
||||||
rescue Errno::ECONNREFUSED
|
rescue Errno::ECONNREFUSED
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sleep 0.1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def osrm_down
|
def wait_for_shutdown
|
||||||
each_process('osrm-routed') { |pid,state| Process.kill 'TERM', pid }
|
while osrm_up?
|
||||||
each_process('osrm-prepare') { |pid,state| Process.kill 'TERM', pid }
|
|
||||||
each_process('osrm-extract') { |pid,state| Process.kill 'TERM', pid }
|
|
||||||
wait_for_shutdown 'osrm-routed'
|
|
||||||
wait_for_shutdown 'osrm-prepare'
|
|
||||||
wait_for_shutdown 'osrm-extract'
|
|
||||||
end
|
|
||||||
|
|
||||||
def osrm_kill
|
|
||||||
each_process('osrm-routed') { |pid,state| Process.kill 'KILL', pid }
|
|
||||||
each_process('osrm-prepare') { |pid,state| Process.kill 'KILL', pid }
|
|
||||||
each_process('osrm-extract') { |pid,state| Process.kill 'KILL', pid }
|
|
||||||
wait_for_shutdown 'osrm-routed'
|
|
||||||
wait_for_shutdown 'osrm-prepare'
|
|
||||||
wait_for_shutdown 'osrm-extract'
|
|
||||||
end
|
|
||||||
|
|
||||||
def wait_for_shutdown name
|
|
||||||
timeout = 10
|
|
||||||
(timeout*10).times do
|
|
||||||
return if find_pid(name) == nil
|
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
end
|
end
|
||||||
raise "*** Could not terminate #{name}."
|
|
||||||
end
|
end
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
require 'net/http'
|
require 'net/http'
|
||||||
|
|
||||||
HOST = 'http://localhost:5000'
|
HOST = "http://localhost:#{OSRM_PORT}"
|
||||||
|
REQUEST_TIMEOUT = 1
|
||||||
|
|
||||||
def request_path path
|
def request_path path
|
||||||
@query = path
|
@query = path
|
||||||
log path
|
log path
|
||||||
uri = URI.parse "#{HOST}/#{path}"
|
uri = URI.parse "#{HOST}/#{path}"
|
||||||
Net::HTTP.get_response uri
|
Timeout.timeout(REQUEST_TIMEOUT) do
|
||||||
|
Net::HTTP.get_response uri
|
||||||
|
end
|
||||||
rescue Errno::ECONNREFUSED => e
|
rescue Errno::ECONNREFUSED => e
|
||||||
raise "*** osrm-routed is not running."
|
raise "*** osrm-routed is not running."
|
||||||
rescue Timeout::Error
|
rescue Timeout::Error
|
||||||
|
Loading…
Reference in New Issue
Block a user