Skip to content

Commit

Permalink
Add data_version field to responses of all plugins. (#5387)
Browse files Browse the repository at this point in the history
  • Loading branch information
gardster authored Aug 22, 2022
1 parent 972a848 commit 928867c
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/osrm-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,9 @@ jobs:
uses: actions/cache@v2
with:
path: ${{github.workspace}}/test/cache
key: v2-test-${{ matrix.name }}-${{ github.sha }}
key: v3-test-${{ matrix.name }}-${{ github.sha }}
restore-keys: |
v2-test-${{ matrix.name }}-
v3-test-${{ matrix.name }}-
- name: Prepare environment
run: |
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased
- Changes from 5.26.0
- API:
- CHANGED: Add `data_version` field to responses of all services. [#5387](https://github.com/Project-OSRM/osrm-backend/pull/5387)
- FIXED: Use Boost.Beast to parse HTTP request. [#6294](https://github.com/Project-OSRM/osrm-backend/pull/6294)
- FIXED: Fix inefficient osrm-routed connection handling [#6113](https://github.com/Project-OSRM/osrm-backend/pull/6113)
- Misc:
Expand Down
52 changes: 52 additions & 0 deletions features/nearest/pick.feature
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,31 @@ Feature: Locating Nearest node on a Way - pick closest way
| 3 | u |
| 4 | w |

Scenario: Nearest - inside a oneway triangle
Given the node map
"""
c
y z
0 1
2 3 4
a x u w b
"""

And the ways
| nodes | oneway |
| ab | yes |
| bc | yes |
| ca | yes |

When I request nearest I should get
| in | out |
| 0 | y |
| 1 | z |
| 2 | x |
| 3 | u |
| 4 | w |

Scenario: Nearest - High lat/lon
Given the node locations
| node | lat | lon |
Expand All @@ -78,3 +103,30 @@ Feature: Locating Nearest node on a Way - pick closest way
| x | a |
| y | b |
| z | c |

Scenario: Nearest - data version
Given the node map
"""
c
y z
0 1
2 3 4
a x u w b
"""

And the ways
| nodes |
| ab |
| bc |
| ca |

And the extract extra arguments "--data_version cucumber_data_version"

When I request nearest I should get
| in | out | data_version |
| 0 | y | cucumber_data_version |
| 1 | z | cucumber_data_version |
| 2 | x | cucumber_data_version |
| 3 | u | cucumber_data_version |
| 4 | w | cucumber_data_version |
4 changes: 4 additions & 0 deletions features/step_definitions/matching.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ module.exports = function () {
got.duration = duration.toString();
}

if (headers.has('data_version')) {
got.data_version = json.data_version || '';
}

// if header matches 'a:*', parse out the values for *
// and return in that header
headers.forEach((k) => {
Expand Down
6 changes: 6 additions & 0 deletions features/step_definitions/nearest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = function () {
this.reprocessAndLoadData((e) => {
if (e) return callback(e);
var testRow = (row, ri, cb) => {

var inNode = this.findNodeByName(row.in);
if (!inNode) throw new Error(util.format('*** unknown in-node "%s"', row.in));

Expand All @@ -17,6 +18,7 @@ module.exports = function () {
this.requestNearest(inNode, this.queryParams, (err, response) => {
if (err) return cb(err);
var coord;
var headers = new Set(table.raw()[0]);

if (response.statusCode === 200 && response.body.length) {
var json = JSON.parse(response.body);
Expand All @@ -25,6 +27,10 @@ module.exports = function () {

var got = { in: row.in, out: row.out };

if (headers.has('data_version')) {
got.data_version = json.data_version || '';
}

Object.keys(row).forEach((key) => {
if (key === 'out') {
if (this.FuzzyMatch.matchLocation(coord, outNode)) {
Expand Down
4 changes: 4 additions & 0 deletions features/step_definitions/trip.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ module.exports = function () {
got.message = json.message;
}

if (headers.has('data_version')) {
got.data_version = json.data_version || '';
}

if (headers.has('geometry')) {
if (this.queryParams['geometries'] === 'polyline') {
got.geometry = polyline.decode(json.trips[0].geometry).toString();
Expand Down
3 changes: 2 additions & 1 deletion features/testbot/distance_matrix.feature
Original file line number Diff line number Diff line change
Expand Up @@ -726,4 +726,5 @@ Feature: Basic Distance Matrix
| | 1 | 2 | 3 |
| 1 | 0 | 1000.1 | 1400.1 |
| 2 | 1000.1 | 0 | 400 |
| 3 | 1400.1 | 400 | 0 |
| 3 | 1400.1 | 400 | 0 |

26 changes: 23 additions & 3 deletions features/testbot/matching.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,27 @@ Feature: Basic Map Matching
| abcd | no |

When I match I should get
| trace | timestamps | matchings |
| ab1d | 0 1 2 3 | ad |
| trace | timestamps | matchings | data_version |
| ab1d | 0 1 2 3 | ad | |

Scenario: Data_version test on matching
Given a grid size of 100 meters
Given the node map
"""
a b c d
1
"""

And the extract extra arguments "--data_version cucumber_data_version"

And the ways
| nodes | oneway |
| abcd | no |

When I match I should get
| trace | timestamps | matchings | data_version |
| ab1d | 0 1 2 3 | ad | cucumber_data_version |

Scenario: Testbot - Map matching with trace splitting
Given the node map
Expand Down Expand Up @@ -792,4 +811,5 @@ Feature: Basic Map Matching
When I match I should get
| trace | geometry | a:distance | a:duration | a:weight | duration |
| 2345 | 1.00018,1,1.000314,1 | 14.914666 | 1.4 | 1.4 | 1.4 |
| 4321 | 1.00027,1,1.000135,1 | 15.02597 | 1.5 | 1.5 | 1.5 |
| 4321 | 1.00027,1,1.000135,1 | 15.02597 | 1.5 | 1.5 | 1.5 |

32 changes: 26 additions & 6 deletions features/testbot/snap.feature
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,31 @@ Feature: Snap start/end point to the nearest way
| adb |

When I route I should get
| from | to | route |
| 1 | b | adb,adb |
| 2 | b | adb,adb |
| 6 | b | aub,aub |
| 7 | b | aub,aub |
| from | to | route | data_version |
| 1 | b | adb,adb | |
| 2 | b | adb,adb | |
| 6 | b | aub,aub | |
| 7 | b | aub,aub | |

Scenario: Data_version check on nearest
Given the node map
"""
4 5 6 7
3 a u
2
1 d b
"""

And the extract extra arguments "--data_version cucumber_data_version"

And the ways
| nodes |
| aub |
| adb |

When I route I should get
| from | to | route | data_version |
| 1 | b | adb,adb | cucumber_data_version |

Scenario: Snap to edge right under start/end point
Given the node map
Expand Down Expand Up @@ -182,4 +202,4 @@ Feature: Snap start/end point to the nearest way
| x | m | xe,xe |
| x | n | xf,xf |
| x | o | xg,xg |
| x | p | xh,xh |
| x | p | xh,xh |
48 changes: 43 additions & 5 deletions features/testbot/trip.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ Feature: Basic trip planning
Given the profile "testbot"
Given a grid size of 10 meters

Scenario: Testbot - Trip: Invalid options (like was in test suite for a long time)
Given the node map
"""
a b
c d
"""

And the ways
| nodes |
| ab |
| bc |
| cb |
| da |

When I plan a trip I should get
| waypoints | trips | code |
| a | | InvalidOptions |

Scenario: Testbot - Trip: Roundtrip between same waypoint
Given the node map
"""
Expand All @@ -20,8 +38,28 @@ Feature: Basic trip planning
| da |

When I plan a trip I should get
| waypoints | trips |
| a,a | aa |
| waypoints | trips | code |
| a,a | aa | Ok |

Scenario: Testbot - Trip: data version check
Given the node map
"""
a b
c d
"""

And the ways
| nodes |
| ab |
| bc |
| cb |
| da |

And the extract extra arguments "--data_version cucumber_data_version"

When I plan a trip I should get
| waypoints | trips | data_version | code |
| a,a | aa | cucumber_data_version | Ok |

Scenario: Testbot - Trip: Roundtrip with waypoints (less than 10)
Given the node map
Expand All @@ -38,9 +76,9 @@ Feature: Basic trip planning
| da |

When I plan a trip I should get
| waypoints | trips | durations |
| a,b,c,d | abcda | 7.6 |
| d,b,c,a | dbcad | 7.6 |
| waypoints | trips | durations | code |
| a,b,c,d | abcda | 7.6 | Ok |
| d,b,c,a | dbcad | 7.6 | Ok |

Scenario: Testbot - Trip: Roundtrip waypoints (more than 10)
Given the node map
Expand Down
5 changes: 5 additions & 0 deletions include/engine/api/match_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ class MatchAPI final : public RouteAPI
}
response.values["matchings"] = std::move(routes);
response.values["code"] = "Ok";
auto data_timestamp = facade.GetTimestamp();
if (!data_timestamp.empty())
{
response.values["data_version"] = data_timestamp;
}
}

protected:
Expand Down
5 changes: 5 additions & 0 deletions include/engine/api/nearest_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ class NearestAPI final : public BaseAPI
}

response.values["code"] = "Ok";
auto data_timestamp = facade.GetTimestamp();
if (!data_timestamp.empty())
{
response.values["data_version"] = data_timestamp;
}
}

const NearestParameters &parameters;
Expand Down
5 changes: 5 additions & 0 deletions include/engine/api/table_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ class TableAPI final : public BaseAPI
}

response.values["code"] = "Ok";
auto data_timestamp = facade.GetTimestamp();
if (!data_timestamp.empty())
{
response.values["data_version"] = data_timestamp;
}
}

protected:
Expand Down
5 changes: 5 additions & 0 deletions include/engine/api/trip_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ class TripAPI final : public RouteAPI
}
response.values["trips"] = std::move(routes);
response.values["code"] = "Ok";
auto data_timestamp = facade.GetTimestamp();
if (!data_timestamp.empty())
{
response.values["data_version"] = data_timestamp;
}
}

protected:
Expand Down

0 comments on commit 928867c

Please sign in to comment.