(query_options, filters, callback)
| 13 | |
| 14 | // Execute HTTP query against OSRM server and measure response times |
| 15 | const run_query = (query_options, filters, callback) => { |
| 16 | let tic = () => 0.; |
| 17 | http.request(query_options, (res) => { |
| 18 | let body = ''; |
| 19 | const ttfb = tic(); |
| 20 | |
| 21 | res.setEncoding('utf8'); |
| 22 | res.on('data', (chunk) => { |
| 23 | body += chunk; |
| 24 | }); |
| 25 | res.on('end', () => { |
| 26 | const elapsed = tic(); |
| 27 | const json = JSON.parse(body); |
| 28 | Promise.all(filters.map(filter => JSONPath({path: filter, json: json}))) |
| 29 | .then(values => callback(query_options.path, res.statusCode, ttfb, elapsed, values)); |
| 30 | }); |
| 31 | }).on('socket', (/*res*/) => { |
| 32 | tic = ((toc) => { return () => { const t = process.hrtime(toc); return t[0] * 1000 + t[1] / 1000000; }; })(process.hrtime()); |
| 33 | }).on('error', (res) => { |
| 34 | callback(query_options.path, res.code); |
| 35 | }).end(); |
| 36 | }; |
| 37 | |
| 38 | // Generate random coordinate points within a polygon boundary for route testing |
| 39 | function generate_points(polygon, number, coordinates_number, max_distance) { |
no test coverage detected