WIP: race conditions and stalling server

This commit is contained in:
Lauren Budorick 2016-03-27 20:55:12 -07:00 committed by Patrick Niklaus
parent 3135bb34b3
commit 4d2be0b44c
6 changed files with 38 additions and 28 deletions

View File

@ -47,12 +47,12 @@ module.exports = function () {
if (headers.has('route')) {
if (json.matchings.length != 1) throw new Error('*** Checking route only supported for matchings with one subtrace');
route = this.wayList(json.matchings[0].instructions);
route = this.wayList(json.matchings[0]);
}
if (headers.has('duration')) {
if (json.matchings.length != 1) throw new Error('*** Checking duration only supported for matchings with one subtrace');
duration = json.matchings[0].route_summary.total_time;
duration = json.matchings[0].duration;
}
}

View File

@ -66,13 +66,13 @@ module.exports = function () {
r.query = this.query;
r.json = JSON.parse(body);
r.status = r.json.status === 200 ? 'x' : null;
r.status = res.statusCode === 200 ? 'x' : null;
if (r.status) {
r.route = this.wayList(r.json.route_instructions);
r.route = this.wayList(r.json.routes[0]);
if (r.route === util.format('w%d', i)) {
r.time = r.json.route_summary.total_time;
r.distance = r.json.route_summary.total_distance;
r.time = r.json.routes[0].duration;
r.distance = r.json.routes[0].distance;
r.speed = r.time > 0 ? parseInt(3.6 * r.distance / r.time) : null;
} else {
r.status = null;
@ -96,15 +96,23 @@ module.exports = function () {
});
result.bothw = {};
['status', 'time', 'distance', 'speed'].forEach((key) => {
var sq = d3.queue();
var parseRes = (key, scb) => {
if (result.forw[key] === result.backw[key]) {
result.bothw[key] = result.forw[key];
} else {
result.bothw[key] = 'diff';
}
scb();
}
['status', 'time', 'distance', 'speed'].forEach((key) => {
sq.defer(parseRes, key);
});
cb(null, result);
sq.awaitAll(() => { cb(null, result); });
});
};
};

View File

@ -94,13 +94,13 @@ module.exports = function () {
q.awaitAll(callback);
};
var ensureDecimal = (i) => {
this.ensureDecimal = (i) => {
if (parseInt(i) === i) return i.toFixed(1);
else return i;
};
this.tableCoordToLonLat = (ci, ri) => {
return [this.origin[0] + ci * this.zoom, this.origin[1] - ri * this.zoom].map(ensureDecimal);
return [this.origin[0] + ci * this.zoom, this.origin[1] - ri * this.zoom].map(this.ensureDecimal);
};
this.addOSMNode = (name, lon, lat, id) => {

View File

@ -1,6 +1,7 @@
'use strict';
var util = require('util');
var path = require('path');
var fs = require('fs');
var OSRMError = class extends Error {
@ -23,8 +24,8 @@ var OSRMError = class extends Error {
});
}
logTail (path, n, callback) {
var expanded = path.resolve(this.TEST_FOLDER, path);
logTail (logPath, n, callback) {
var expanded = path.resolve(this.TEST_FOLDER, logPath);
fs.exists(expanded, (exists) => {
if (exists) {
fs.readFile(expanded, (err, data) => {

View File

@ -34,7 +34,7 @@ module.exports = function () {
};
var encodeWaypoints = (waypoints) => {
return waypoints.map(w => [w.lon, w.lat].join(','));
return waypoints.map(w => [w.lon, w.lat].map(this.ensureDecimal).join(','));
};
this.requestRoute = (waypoints, bearings, userParams, callback) => {
@ -43,7 +43,7 @@ module.exports = function () {
var defaults = {
output: 'json',
steps: 'true',
alternative: 'false'
alternatives: 'false'
},
params = this.overwriteParams(defaults, userParams),
encodedWaypoints = encodeWaypoints(waypoints);
@ -108,18 +108,19 @@ module.exports = function () {
return this.requestPath('match', params, callback);
};
this.extractInstructionList = (instructions, index, postfix) => {
this.extractInstructionList = (instructions, keyFinder, postfix) => {
postfix = postfix || null;
if (instructions) {
return instructions.filter(r => r[0].toString() !== this.DESTINATION_REACHED.toString())
.map(r => r[index])
.map(r => (isNaN(parseInt(r)) && (!r || r == '')) ? '""' : '' + r + (postfix || ''))
return Array.prototype.concat.apply([],
instructions.legs.map(l => l.steps))
.filter(s => s.maneuver.type !== 'arrive')
.map(keyFinder)
.join(',');
}
};
this.wayList = (instructions) => {
return this.extractInstructionList(instructions, 1);
return this.extractInstructionList(instructions, s => s.name);
};
this.compassList = (instructions) => {

View File

@ -39,13 +39,13 @@ module.exports = function () {
var hasRoute = json.status === 200;
if (hasRoute) {
instructions = this.wayList(json.route_instructions);
bearings = this.bearingList(json.route_instructions);
compasses = this.compassList(json.route_instructions);
turns = this.turnList(json.route_instructions);
modes = this.modeList(json.route_instructions);
times = this.timeList(json.route_instructions);
distances = this.distanceList(json.route_instructions);
instructions = this.wayList(json.routes[0]);
bearings = this.bearingList(json.routes[0]);
compasses = this.compassList(json.routes[0]);
turns = this.turnList(json.routes[0]);
modes = this.modeList(json.routes[0]);
times = this.timeList(json.routes[0]);
distances = this.distanceList(json.routes[0]);
}
if (headers.has('status')) {
@ -81,8 +81,8 @@ module.exports = function () {
this.wayList(json.alternative_instructions[0]) : '';
}
var distance = hasRoute && json.route_summary.total_distance,
time = hasRoute && json.route_summary.total_time;
var distance = hasRoute && json.routes[0].distance,
time = hasRoute && json.routes[0].duration;
if (headers.has('distance')) {
if (row.distance.length) {