Skip to content

Commit

Permalink
add test for process error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Tin committed Sep 28, 2012
1 parent 4c02542 commit 334f02d
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Expand Up @@ -3,4 +3,5 @@ source "http://rubygems.org"
gem "cucumber"
gem "rake"
gem "osmlib-base"
gem "sys-proctable"
gem "sys-proctable"
gem "rspec-expectations"
3 changes: 3 additions & 0 deletions Gemfile.lock
Expand Up @@ -14,6 +14,8 @@ GEM
json (1.6.5)
osmlib-base (0.1.4)
rake (0.9.2.2)
rspec-expectations (2.11.3)
diff-lcs (~> 1.1.3)
sys-proctable (0.9.1)
term-ansicolor (1.0.7)

Expand All @@ -24,4 +26,5 @@ DEPENDENCIES
cucumber
osmlib-base
rake
rspec-expectations
sys-proctable
21 changes: 16 additions & 5 deletions features/bad.feature
Expand Up @@ -3,14 +3,25 @@ Feature: Handle bad data in a graceful manner

Scenario: Empty dataset
Given the node map
| a | b |
| |

Given the ways
| nodes |

When I route I should get
| from | to | route |
| a | b | |
When I preprocess data
Then preparing should return code 255

Scenario: Only dead-end oneways
Given the node map
| a | b | c |

Given the ways
| nodes | oneway |
| ab | yes |
| cb | yes |

When I preprocess data
Then preparing should return code 255

Scenario: Start/end point at the same location
Given the node map
Expand All @@ -29,7 +40,7 @@ Feature: Handle bad data in a graceful manner
| 2 | 2 | |

@poles
Scenario: No routing close to the north/south pole
Scenario: Routing close to the north/south pole
Mercator is undefined close to the poles.
All nodes and request with latitude to close to either of the poles should therefore be ignored.

Expand Down
15 changes: 15 additions & 0 deletions features/step_definitions/errors.rb
@@ -0,0 +1,15 @@

When /^I preprocess data$/ do
begin
osrm_kill
reprocess
rescue OSRMError => e
@process_error = e
end
end

Then /^preparing should return code (\d+)$/ do |code|
@process_error.class.should == OSRMError
@process_error.process.should == 'osrm-prepare'
@process_error.code.to_i.should == code.to_i
end
5 changes: 2 additions & 3 deletions features/support/data.rb
Expand Up @@ -176,7 +176,7 @@ def reprocess
log "== Extracting #{@osm_file}.osm...", :preprocess
unless system "../osrm-extract #{@osm_file}.osm.pbf 1>>#{PREPROCESS_LOG_FILE} 2>>#{PREPROCESS_LOG_FILE}"
log "*** Exited with code #{$?.exitstatus}.", :preprocess
raise "*** osrm-extract exited with code #{$?.exitstatus}. The file preprocess.log might contain more info."
raise OSRMError.new 'osrm-extract', $?.exitstatus, "*** osrm-extract exited with code #{$?.exitstatus}. The file preprocess.log might contain more info."
end
log '', :preprocess
end
Expand All @@ -185,12 +185,11 @@ def reprocess
log "== Preparing #{@osm_file}.osm...", :preprocess
unless system "../osrm-prepare #{@osm_file}.osrm #{@osm_file}.osrm.restrictions 1>>#{PREPROCESS_LOG_FILE} 2>>#{PREPROCESS_LOG_FILE}"
log "*** Exited with code #{$?.exitstatus}.", :preprocess
raise "*** osrm-prepare exited with code #{$?.exitstatus}. The file preprocess.log might contain more info."
raise OSRMError.new 'osrm-prepare', $?.exitstatus, "*** osrm-prepare exited with code #{$?.exitstatus}. The file preprocess.log might contain more info."
end
log '', :preprocess
end
log_preprocess_done
write_server_ini
end
end

1 change: 1 addition & 0 deletions features/support/env.rb
@@ -0,0 +1 @@
require 'rspec/expectations'
10 changes: 10 additions & 0 deletions features/support/exceptions.rb
@@ -0,0 +1,10 @@

class OSRMError < StandardError
attr_accessor :process, :code, :msg

def initialize process, code, msg
@process = process
@code = code
@msg = msg
end
end

0 comments on commit 334f02d

Please sign in to comment.