Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement NodeJS based server replicating osrm-routed #6411

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
53f2da5
Implement NodeJS based server fully replicating osrm-routed
SiarheiFedartsou Oct 23, 2022
251ffe4
Implement NodeJS based server fully replicating osrm-routed
SiarheiFedartsou Oct 23, 2022
768c331
Implement NodeJS based server fully replicating osrm-routed
SiarheiFedartsou Oct 23, 2022
dd04760
Implement NodeJS based server fully replicating osrm-routed
SiarheiFedartsou Oct 23, 2022
8273e8b
Implement NodeJS based server fully replicating osrm-routed
SiarheiFedartsou Oct 23, 2022
61810b9
Implement NodeJS based server fully replicating osrm-routed
SiarheiFedartsou Oct 23, 2022
3f0ded6
Implement NodeJS based server fully replicating osrm-routed
SiarheiFedartsou Oct 23, 2022
9c7d75d
Implement NodeJS based server fully replicating osrm-routed
SiarheiFedartsou Oct 23, 2022
1047cc1
Implement NodeJS based server fully replicating osrm-routed
SiarheiFedartsou Oct 23, 2022
242c074
Implement NodeJS based server fully replicating osrm-routed
SiarheiFedartsou Oct 23, 2022
4fd4c3b
Implement NodeJS based server fully replicating osrm-routed
SiarheiFedartsou Oct 23, 2022
71a638a
Implement NodeJS based server fully replicating osrm-routed
SiarheiFedartsou Oct 23, 2022
6dfb7d4
Implement NodeJS based server fully replicating osrm-routed
SiarheiFedartsou Oct 23, 2022
41ff79a
Implement NodeJS based server fully replicating osrm-routed
SiarheiFedartsou Oct 23, 2022
8e3fa70
Implement NodeJS based server fully replicating osrm-routed
SiarheiFedartsou Oct 25, 2022
40805f7
Implement NodeJS based server fully replicating osrm-routed
SiarheiFedartsou Oct 25, 2022
4dfae26
add cluster
SiarheiFedartsou Oct 26, 2022
ddde7e1
Implement NodeJS based server fully replicating osrm-routed
SiarheiFedartsou Oct 29, 2022
38e4b0b
Implement NodeJS based server fully replicating osrm-routed
SiarheiFedartsou Oct 29, 2022
2016d46
Merge branch 'master' into sf-osrm-routed
SiarheiFedartsou Aug 22, 2023
3e68237
Fix CI
SiarheiFedartsou Aug 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions .github/workflows/osrm-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,29 @@ jobs:
npm run docs && ./scripts/error_on_dirty.sh
npm audit --production

routed-js:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 14
- name: Enable Node.js cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Compile routed-js
run: |
pushd routed-js
npm ci
npx tsc
popd
./scripts/error_on_dirty.sh

docker-image:
needs: format-taginfo-docs
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -264,7 +287,7 @@ jobs:
CXXFLAGS: "-m32 -msse2 -mfpmath=sse"
TARGET_ARCH: i686
ENABLE_CONAN: ON

- name: gcc-8-release
continue-on-error: false
node: 16
Expand Down Expand Up @@ -512,6 +535,9 @@ jobs:
cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE}
make --jobs=${JOBS}
popd
- name: Install osrm-routed-js dependencies
if: ${{ matrix.node != 12 && matrix.ENABLE_APPLE_SILICON != 'ON' && matrix.TARGET_ARCH != 'i686' }}
run: cd routed-js && npm ci && npm link && osrm-routed-js --version
- name: Run all tests
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY != 'ON' && matrix.ENABLE_APPLE_SILICON != 'ON' }}
run: |
Expand Down Expand Up @@ -622,6 +648,6 @@ jobs:

ci-complete:
runs-on: ubuntu-22.04
needs: [build-test-publish, docker-image, windows-release-node]
needs: [build-test-publish, docker-image, routed-js, windows-release-node]
steps:
- run: echo "CI complete"
4 changes: 3 additions & 1 deletion cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ module.exports = {
ch: '--strict --tags ~@stress --tags ~@todo --tags ~@mld -f progress --require features/support --require features/step_definitions',
todo: '--strict --tags @todo --require features/support --require features/step_definitions',
all: '--strict --require features/support --require features/step_definitions',
mld: '--strict --tags ~@stress --tags ~@todo --tags ~@ch --require features/support --require features/step_definitions -f progress'
mld: '--strict --tags ~@stress --tags ~@todo --tags ~@ch --require features/support --require features/step_definitions -f progress',
verify_routed_js: '--strict --tags ~@skip_on_routed_js --tags ~@stress --tags ~@todo --tags ~@mld-only -f progress --require features/support --require features/step_definitions',
mld_routed_js: '--strict --tags ~@skip_on_routed_js --tags ~@stress --tags ~@todo --tags ~@ch --require features/support --require features/step_definitions -f progress',
};
23 changes: 14 additions & 9 deletions features/lib/osrm_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,16 @@ class OSRMLoader {
this.loader = {shutdown: (cb) => cb() };
}
if (this.method === 'datastore') {
this.loader.shutdown((err) => {
if (err) return callback(err);
this.loader = this.sharedLoader;
this.sharedLoader.load(inputFile, callback);
});
// shutdown only if we are switching from another loader type
if (this.loader !== this.sharedLoader) {
this.loader.shutdown((err) => {
if (err) return callback(err);
this.loader = this.sharedLoader;
this.sharedLoader.load(inputFile, callback);
});
} else {
this.sharedLoader.load(inputFile, callback);
}
} else if (this.method === 'directly') {
this.loader.shutdown((err) => {
if (err) return callback(err);
Expand All @@ -201,12 +206,12 @@ class OSRMLoader {
});
} else if (this.method === 'mmap') {
this.loader.shutdown((err) => {
if (err) return callback(err);
this.loader = this.mmapLoader;
this.mmapLoader.load(inputFile, callback);
if (err) return callback(err);
this.loader = this.mmapLoader;
this.mmapLoader.load(inputFile, callback);
});
} else {
callback(new Error('*** Unknown load method ' + method));
callback(new Error('*** Unknown load method ' + this.method));
}
}

Expand Down
4 changes: 4 additions & 0 deletions features/options/routed/help.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Feature: osrm-routed command line options: help
Background:
Given the profile "testbot"

@skip_on_routed_js
Scenario: osrm-routed - Help should be shown when no options are passed
When I run "osrm-routed"
Then stderr should be empty
Expand All @@ -25,6 +26,7 @@ Feature: osrm-routed command line options: help
And stdout should contain "--default-radius"
And it should exit successfully

@skip_on_routed_js
Scenario: osrm-routed - Help, short
When I run "osrm-routed -h"
Then stderr should be empty
Expand All @@ -46,6 +48,8 @@ Feature: osrm-routed command line options: help
And stdout should contain "--default-radius"
And it should exit successfully


@skip_on_routed_js
Scenario: osrm-routed - Help, long
When I run "osrm-routed --help"
Then stderr should be empty
Expand Down
2 changes: 2 additions & 0 deletions features/options/routed/invalid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ Feature: osrm-routed command line options: invalid options
Background:
Given the profile "testbot"

@skip_on_routed_js
Scenario: osrm-routed - Non-existing option
When I try to run "osrm-routed --fly-me-to-the-moon"
Then stdout should be empty
And stderr should contain "unrecognised"
And stderr should contain "fly-me-to-the-moon"
And it should exit with an error

@skip_on_routed_js
Scenario: osrm-routed - Missing file
When I try to run "osrm-routed over-the-rainbow.osrm"
Then stderr should contain "over-the-rainbow.osrm"
Expand Down
5 changes: 5 additions & 0 deletions features/step_definitions/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ module.exports = function () {
callback();
});

this.Then(/^HTTP code should be (\d+)$/, (code, callback) => {
assert(this.response.statusCode, parseInt(code));
callback();
});

this.Then(/^status message should be "(.*?)"$/, (message, callback) => {
try {
this.json = JSON.parse(this.response.body);
Expand Down
4 changes: 3 additions & 1 deletion features/support/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module.exports = function () {
this.setDefaultTimeout(this.TIMEOUT);
this.ROOT_PATH = process.cwd();

this.USE_ROUTED_JS = process.env.OSRM_USE_ROUTED_JS || false;

this.TEST_PATH = path.resolve(this.ROOT_PATH, 'test');
this.CACHE_PATH = path.resolve(this.TEST_PATH, 'cache');
this.LOGS_PATH = path.resolve(this.TEST_PATH, 'logs');
Expand All @@ -41,7 +43,7 @@ module.exports = function () {

this.OSRM_PORT = process.env.OSRM_PORT && parseInt(process.env.OSRM_PORT) || 5000;
this.OSRM_IP = process.env.OSRM_IP || '127.0.0.1';
this.OSRM_CONNECTION_RETRIES = process.env.OSRM_CONNECTION_RETRIES && parseInt(process.env.OSRM_CONNECTION_RETRIES) || 10;
this.OSRM_CONNECTION_RETRIES = process.env.OSRM_CONNECTION_RETRIES && parseInt(process.env.OSRM_CONNECTION_RETRIES) || 100;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to change it since new server has higher startup time than our existing osrm-routed.

this.OSRM_CONNECTION_EXP_BACKOFF_COEF = process.env.OSRM_CONNECTION_EXP_BACKOFF_COEF && parseFloat(process.env.OSRM_CONNECTION_EXP_BACKOFF_COEF) || 1.0;

this.HOST = `http://${this.OSRM_IP}:${this.OSRM_PORT}`;
Expand Down
4 changes: 4 additions & 0 deletions features/support/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ module.exports = function () {

this.runBin = (bin, options, env, callback) => {
let cmd = path.resolve(util.format('%s/%s%s', this.BIN_PATH, bin, this.EXE));
if (this.USE_ROUTED_JS && bin === 'osrm-routed') {
cmd = 'osrm-routed-js';
}
let opts = options.split(' ').filter((x) => { return x && x.length > 0; });

let log = fs.createWriteStream(this.scenarioLogFile, {'flags': 'a'});
log.write(util.format('*** running %s %s\n', cmd, options));
// we need to set a large maxbuffer here because we have long running processes like osrm-routed
Expand Down
2 changes: 1 addition & 1 deletion features/testbot/annotations.feature
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@ Feature: Annotations

When I route I should get
| from | to | route | a:speed | a:distance | a:duration | a:nodes |
| a | c | abc,abc | 10:10 | 249.9876189:299.962882 | 25:30 | 1:2:3 |
| a | c | abc,abc | 10:10 | 249.9876189:299.962882 +- 1e-7 | 25:30 | 1:2:3 |
4 changes: 2 additions & 2 deletions features/testbot/exclude.feature
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ Feature: Testbot - Exclude flags
| a | c | |
| a | f | |
| f | d | fg,gd,gd |

@skip_on_routed_js
Scenario: Testbot - exclude with unsupported exclude combination
Given the query options
| exclude | TwoWords2 |

When I route I should get
| from | to | status | message |
| a | d | 400 | Exclude flag combination is not supported. |

@skip_on_routed_js
Scenario: Testbot - exclude with invalid exclude class name
Given the query options
| exclude | foo |
Expand Down
1 change: 1 addition & 0 deletions features/testbot/load.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Feature: Ways of loading data
Then stderr should be empty
And it should exit successfully

@skip_on_routed_js
Scenario: osrm-datastore - Fail if no shared memory blocks are loaded
When I run "osrm-datastore --spring-clean" with input "Y"
And I try to run "osrm-routed --shared-memory=1"
Expand Down
4 changes: 3 additions & 1 deletion features/testbot/matching.feature
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ Feature: Basic Map Matching
| trace | timestamps | code |
| abcd | 0 1 62 63 | NoMatch |

@skip_on_routed_js
Scenario: Testbot - Map matching invalid waypoints
Given the node map
"""
Expand All @@ -580,6 +581,7 @@ Feature: Basic Map Matching
| trace | code |
| abcd | InvalidOptions |

@skip_on_routed_js
Scenario: Matching fail with waypoints param missing start/end
Given the node map
"""
Expand Down Expand Up @@ -788,7 +790,7 @@ Feature: Basic Map Matching
| 1234 | 1.000135,1,1.000225,1,1.000404,1,1.000449,1 | 1:2:0.4 | 1:2:0.4 | 3.4 |
| 4321 | 1.000449,1,1.000404,1,1.000225,1,1.000135,1 | 0.4:2:1 | 0.4:2:1 | 3.4 |

@match @testbot
@match @testbot @skip_on_routed_js
Scenario: Regression test - add source phantom properly (two phantoms on one edge)
Given the profile "testbot"
Given a grid size of 10 meters
Expand Down
5 changes: 3 additions & 2 deletions features/testbot/snap_intersection.feature
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,8 @@ Feature: Snapping at intersections
| a,f,k | ac,cf,cf,fj,kj,kj | 132.8s | 132.8 |
| k,f | ik,fi,fi | 54.3s | 54.3 |
| f,a | ef,ae,ae | 66.6s | 66.6 |
| k,f,a | kj,fj,fj,ef,ae,ae | 141.4s | 141.4 |
| k,f,a | kj,fj,fj,ef,ae,ae | 141.4s +- 1e-7 | 141.4 +- 1e-7 |


When I request a travel time matrix I should get
| | a | f | k |
Expand Down Expand Up @@ -626,4 +627,4 @@ Feature: Snapping at intersections
| a,f,k | ad,df,df,fj,kj,kj | 105.6s | 105.6 |
| k,f | ik,fi,fi | 54.3s | 54.3 |
| f,a | ef,ae,ae | 66.6s | 66.6 |
| k,f,a | ik,fi,fi,ef,ae,ae | 120.9s | 120.9 |
| k,f,a | ik,fi,fi,ef,ae,ae | 120.9s +- 1e-7 | 120.9 +- 1e-7 |
3 changes: 2 additions & 1 deletion features/testbot/status.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Feature: Status messages
| from | to | route | status | message |
| a | b | ab,ab | 200 | |
| b | a | ab,ab | 200 | |

@skip_on_routed_js
Scenario: No route found
Given the node map
"""
Expand All @@ -39,6 +39,7 @@ Feature: Status messages
| a | c | | 400 | Impossible route between points |
| b | d | | 400 | Impossible route between points |

@skip_on_routed_js
Scenario: Malformed requests
Given the node locations
| node | lat | lon |
Expand Down
10 changes: 6 additions & 4 deletions features/testbot/trip.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Feature: Basic trip planning
Background:
Given the profile "testbot"
Given a grid size of 10 meters


@skip_on_routed_js
Scenario: Testbot - Trip: Invalid options (like was in test suite for a long time)
Given the node map
"""
Expand Down Expand Up @@ -222,7 +223,7 @@ Feature: Basic trip planning
| waypoints | trips | roundtrip | durations |
| a,b,c,d,e,f,g,h,i,j,k,l | lkjihgfedcbal | true | 22 |
| a,b,c,d,e,f,g,h,i,j,k,l | cbakjihgfedl | false | 19 |

@skip_on_routed_js
Scenario: Testbot - Trip: Unroutable roundtrip with waypoints (less than 10)
Given the node map
"""
Expand All @@ -240,7 +241,7 @@ Feature: Basic trip planning
| waypoints | status | message |
| a,b,c,d | NoTrips | No trip visiting all destinations possible. |


@skip_on_routed_js
Scenario: Testbot - Trip: Unroutable roundtrip with waypoints (more than 10)
Given the node map
"""
Expand Down Expand Up @@ -278,6 +279,7 @@ Feature: Basic trip planning
| a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p | NoTrips | No trip visiting all destinations possible. |

# Test TFSE
@skip_on_routed_js
Scenario: Testbot - Trip: TFSE with errors
Given the node map
"""
Expand Down Expand Up @@ -371,7 +373,7 @@ Feature: Basic trip planning
| waypoints | source | destination | roundtrip | trips |
| a,b,d,e,c | first | last | true | abedca |


@skip_on_routed_js
Scenario: Testbot - Trip: midway points in isolated roads should return no trips
Given the node map
"""
Expand Down
10 changes: 5 additions & 5 deletions features/testbot/weight.feature
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ Feature: Weight tests
| abc |

When I route I should get
| waypoints | route | distances | weights | times | a:distance | a:duration | a:weight | a:speed |
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be caused by the fact that our JSON renderer truncates numbers to have maximum 10 digits after dot

size_t decimalpos = std::find(buffer.begin(), buffer.end(), '.') - buffer.begin();

| s,t | abc,abc | 20m,0m | 2,0 | 2s,0s | 20.03462663 | 2 | 2 | 10 |
| t,s | abc,abc | 20m,0m | 2,0 | 2s,0s | 20.03462663 | 2 | 2 | 10 |
| s,e | abc,abc | 40m,0m | 3.9,0 | 3.9s,0s | 29.94063646:10.01731331 | 3:0.9 | 3:0.9 | 10:11.1 |
| e,s | abc,abc | 40m,0m | 3.9,0 | 3.9s,0s | 10.01731331:29.94063646 | 0.9:3 | 0.9:3 | 11.1:10 |
| waypoints | route | distances | weights | times | a:distance | a:duration | a:weight | a:speed |
| s,t | abc,abc | 20m,0m | 2,0 | 2s,0s | 20.03462663 +- 1e-7 | 2 | 2 | 10 |
| t,s | abc,abc | 20m,0m | 2,0 | 2s,0s | 20.03462663 +- 1e-7 | 2 | 2 | 10 |
| s,e | abc,abc | 40m,0m | 3.9,0 | 3.9s,0s | 29.94063646:10.01731331 +- 1e-7 | 3:0.9 | 3:0.9 | 10:11.1 |
| e,s | abc,abc | 40m,0m | 3.9,0 | 3.9s,0s | 10.01731331:29.94063646 +- 1e-7 | 0.9:3 | 0.9:3 | 11.1:10 |


Scenario: Step weights -- way_function: fail if no weight or weight_per_meter property
Expand Down
14 changes: 14 additions & 0 deletions features/tile/tile.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Feature: Tile service
Background:
Given the profile "testbot"
Scenario: Smoke test
Given the origin 52.5212,13.3919
Given the node map
"""
a b
"""
And the ways
| nodes |
| ab |
When I request /tile/v1/testbot/tile(8800,5373,14).mvt
Then HTTP code should be 200
1 change: 0 additions & 1 deletion include/nodejs/node_osrm_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ inline void ParseResult(const osrm::Status &result_status, osrm::json::Object &r
throw std::logic_error(code_iter->second.get<osrm::json::String>().value.c_str());
}

result.values.erase(code_iter);
const auto message_iter = result.values.find("message");
if (message_iter != end_iter)
{
Expand Down
8 changes: 8 additions & 0 deletions routed-js/Format.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";
Copy link
Member Author

@SiarheiFedartsou SiarheiFedartsou Oct 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for reviewers: all routed-js/*.js files are generated by TypeScript compiler, so there are no a lot of sense to review it.

Object.defineProperty(exports, "__esModule", { value: true });
exports.Format = void 0;
var Format;
(function (Format) {
Format["Json"] = "json";
Format["Flatbuffers"] = "flatbuffers";
})(Format = exports.Format || (exports.Format = {}));
4 changes: 4 additions & 0 deletions routed-js/Format.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum Format {
Json = 'json',
Flatbuffers = 'flatbuffers'
}
Loading
Loading