test both datastore and direct data load

This commit is contained in:
Emil Tin
2014-10-14 15:35:14 +02:00
parent 76fb0cb965
commit 71b967d243
11 changed files with 214 additions and 80 deletions
+1
View File
@@ -11,6 +11,7 @@ class Location
end
end
def set_input_format format
raise '*** Input format must be eiter "osm" or "pbf"' unless ['pbf','osm'].include? format.to_s
@input_format = format.to_s
+14 -4
View File
@@ -1,8 +1,8 @@
require 'rspec/expectations'
DEFAULT_PORT = 5000
DEFAULT_TIMEOUT = 2
ROOT_FOLDER = Dir.pwd
OSM_USER = 'osrm'
OSM_GENERATOR = 'osrm-test'
@@ -19,6 +19,14 @@ DEFAULT_INPUT_FORMAT = 'osm'
DEFAULT_ORIGIN = [1,1]
LAUNCH_TIMEOUT = 1
SHUTDOWN_TIMEOUT = 10
DEFAULT_LOAD_METHOD = 'datastore'
OSRM_ROUTED_LOG_FILE = 'osrm-routed.log'
if ENV['OS']==/Windows.*/ then
TERMSIGNAL='TERM'
else
TERMSIGNAL=9
end
def log_time_and_run cmd
@@ -31,8 +39,6 @@ def log_time cmd
end
puts "Ruby version #{RUBY_VERSION}"
unless RUBY_VERSION.to_f >= 1.9
raise "*** Please upgrade to Ruby 1.9.x to run the OSRM cucumber tests"
@@ -58,6 +64,7 @@ unless File.exists? TEST_FOLDER
raise "*** Test folder #{TEST_FOLDER} doesn't exist."
end
if ENV['OS']=~/Windows.*/ then
EXE='.exe'
QQ='"'
@@ -67,9 +74,12 @@ else
end
AfterConfiguration do |config|
if OSRMLoader::OSRMBaseLoader.new.osrm_up?
raise "*** osrm-routed is already running."
end
clear_log_files
end
at_exit do
OSRMLoader.shutdown
OSRMLoader::OSRMBaseLoader.new.shutdown
end
+4
View File
@@ -1,7 +1,9 @@
STRESS_TIMEOUT = 300
Before do |scenario|
# feature name
case scenario
when Cucumber::Ast::Scenario
@@ -18,6 +20,7 @@ Before do |scenario|
@scenario_title = scenario.scenario_outline.name
end
@load_method = DEFAULT_LOAD_METHOD
@query_params = {}
@scenario_time = Time.now.strftime("%Y-%m-%dT%H:%m:%SZ")
reset_data
@@ -25,6 +28,7 @@ Before do |scenario|
@has_logged_scenario_info = false
set_grid_size DEFAULT_GRID_SIZE
set_origin DEFAULT_ORIGIN
end
Around('@stress') do |scenario, block|
+111 -71
View File
@@ -1,96 +1,136 @@
require 'socket'
require 'open3'
if ENV['OS']==/Windows.*/ then
TERMSIGNAL='TERM'
else
TERMSIGNAL=9
end
OSRM_ROUTED_LOG_FILE = 'osrm-routed.log'
# Only one isntance of osrm-routed is ever launched, to avoid collisions.
# The default is to keep osrm-routed running and load data with datastore.
# however, osrm-routed it shut down and relaunched for each scenario thats
# loads data directly.
class OSRMLoader
@@pid = nil
def self.load input_file, &block
@input_file = input_file
Dir.chdir TEST_FOLDER do
self.load_data
self.launch unless @@pid
yield
end
end
def self.load_data
run_bin "osrm-datastore", @input_file
end
def self.launch
Timeout.timeout(LAUNCH_TIMEOUT) do
self.osrm_up
self.wait_for_connection
end
rescue Timeout::Error
raise RoutedError.new "Launching osrm-routed timed out."
end
class OSRMBaseLoader
@@pid = nil
def self.shutdown
Timeout.timeout(SHUTDOWN_TIMEOUT) do
self.osrm_down
def launch
Timeout.timeout(LAUNCH_TIMEOUT) do
osrm_up
wait_for_connection
end
rescue Timeout::Error
raise RoutedError.new "Launching osrm-routed timed out."
end
rescue Timeout::Error
self.kill
raise RoutedError.new "Shutting down osrm-routed timed out."
end
def self.osrm_up?
def shutdown
Timeout.timeout(SHUTDOWN_TIMEOUT) do
osrm_down
end
rescue Timeout::Error
kill
raise RoutedError.new "Shutting down osrm-routed timed out."
end
def osrm_up?
if @@pid
begin
if Process.waitpid(@@pid, Process::WNOHANG) then
false
else
true
begin
if Process.waitpid(@@pid, Process::WNOHANG) then
false
else
true
end
rescue Errno::ESRCH, Errno::ECHILD
false
end
rescue Errno::ESRCH, Errno::ECHILD
false
end
end
end
def self.osrm_up
return if self.osrm_up?
@@pid = Process.spawn("#{BIN_PATH}/osrm-routed --sharedmemory=1 --port #{OSRM_PORT}",:out=>OSRM_ROUTED_LOG_FILE, :err=>OSRM_ROUTED_LOG_FILE)
Process.detach(@@pid) # avoid zombie processes
end
def self.osrm_down
if @@pid
Process.kill TERMSIGNAL, @@pid
self.wait_for_shutdown
def osrm_down
if @@pid
Process.kill TERMSIGNAL, @@pid
wait_for_shutdown
@@pid = nil
end
end
end
def self.kill
if @@pid
Process.kill 'KILL', @@pid
def kill
if @@pid
Process.kill 'KILL', @@pid
end
end
end
def self.wait_for_connection
while true
begin
socket = TCPSocket.new('127.0.0.1', OSRM_PORT)
return
rescue Errno::ECONNREFUSED
def wait_for_connection
while true
begin
socket = TCPSocket.new('127.0.0.1', OSRM_PORT)
return
rescue Errno::ECONNREFUSED
sleep 0.1
end
end
end
def wait_for_shutdown
while osrm_up?
sleep 0.1
end
end
end
def self.wait_for_shutdown
while self.osrm_up?
sleep 0.1
# looading data directly when lauching osrm-routed:
# under this scheme, osmr-routed is launched and shutdown for each scenario,
# and osrm-datastore is not used
class OSRMDirectLoader < OSRMBaseLoader
def load world, input_file, &block
@world = world
@input_file = input_file
Dir.chdir TEST_FOLDER do
shutdown
launch
yield
shutdown
end
end
def osrm_up
return if osrm_up?
@@pid = Process.spawn("#{BIN_PATH}/osrm-routed #{@input_file} --port #{OSRM_PORT}",:out=>OSRM_ROUTED_LOG_FILE, :err=>OSRM_ROUTED_LOG_FILE)
Process.detach(@@pid) # avoid zombie processes
end
end
# looading data with osrm-datastore:
# under this scheme, osmr-routed is launched once and kept running for all scenarios,
# and osrm-datastore is used to load data for each scenario
class OSRMDatastoreLoader < OSRMBaseLoader
def load world, input_file, &block
@world = world
@input_file = input_file
Dir.chdir TEST_FOLDER do
load_data
launch unless @@pid
yield
end
end
def load_data
run_bin "osrm-datastore", @input_file
end
def osrm_up
return if osrm_up?
@@pid = Process.spawn("#{BIN_PATH}/osrm-routed --sharedmemory=1 --port #{OSRM_PORT}",:out=>OSRM_ROUTED_LOG_FILE, :err=>OSRM_ROUTED_LOG_FILE)
Process.detach(@@pid) # avoid zombie processes
end
end
def self.load world, input_file, &block
method = world.instance_variable_get "@load_method"
if method == 'datastore'
OSRMDatastoreLoader.new.load world, input_file, &block
elsif method == 'directly'
OSRMDirectLoader.new.load world, input_file, &block
else
raise "*** Unknown load method '#{method}'"
end
end
end