mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 13:10:29 +00:00
routing: a slow route is not a down relay, and the relay takes whole days
A request to the TREK Valhalla that runs out its deadline (a long bike route) is answered 504 and no longer rests the relay for every user or a tab for ten minutes; that one day goes to OSRM. Only an unreachable host or a server error rests it. A day goes to the relay with up to twenty stops per request and no pause between pieces; a request that ends up at the public FOSSGIS Valhalla is cut to ten and paced, as before. The 1.1 s spacing of the server applies to the public hosts only, not to an admin's own OSRM or Valhalla. The relay keeps its connections open and asks for maneuvers only, which the relay contract now accepts.
This commit is contained in:
@@ -364,6 +364,7 @@ describe('valhallaRun over a whole day', () => {
|
||||
costing: 'pedestrian',
|
||||
costing_options: { pedestrian: { max_hiking_difficulty: difficulty, use_ferry: 0 } },
|
||||
directions_options: { units: 'kilometers' },
|
||||
directions_type: 'maneuvers',
|
||||
})
|
||||
})
|
||||
|
||||
@@ -469,6 +470,53 @@ describe('valhallaRun over a whole day', () => {
|
||||
expect(calls).toBe(3)
|
||||
})
|
||||
|
||||
it('VALHALLA-RUN-009: asks the relay twenty locations at a time with no pause between the pieces', async () => {
|
||||
const sizes: number[] = []
|
||||
let fossgis = 0
|
||||
server.use(
|
||||
http.post('/api/routing/valhalla/:action', async ({ request }) => {
|
||||
const body = await request.json() as { locations: unknown[] }
|
||||
sizes.push(body.locations.length)
|
||||
return HttpResponse.json(chain(body.locations.length - 1))
|
||||
}),
|
||||
http.post(FOSSGIS_VALHALLA, () => { fossgis++; return HttpResponse.json(chain(1)) }),
|
||||
)
|
||||
const started = Date.now()
|
||||
|
||||
const avoiding = await valhallaRun(stops(14), 'driving', ['toll'])
|
||||
const long = await valhallaRun(stops(25), 'driving', ['toll'])
|
||||
|
||||
expect(avoiding?.legs).toHaveLength(13)
|
||||
expect(long?.legs).toHaveLength(24)
|
||||
expect(sizes).toEqual([14, 20, 6])
|
||||
// The pause between pieces was 1.1 s; the relay and an own Valhalla are not paced.
|
||||
expect(Date.now() - started).toBeLessThan(1000)
|
||||
expect(fossgis).toBe(0)
|
||||
})
|
||||
|
||||
it('VALHALLA-RUN-010: a day cut for the relay that the relay cannot answer is cut again in tens for FOSSGIS', async () => {
|
||||
const relayed: number[] = []
|
||||
const sizes: number[] = []
|
||||
server.use(
|
||||
http.post('/api/routing/valhalla/:action', async ({ request }) => {
|
||||
relayed.push(((await request.json()) as { locations: unknown[] }).locations.length)
|
||||
return HttpResponse.json({ error: 'down' }, { status: 502 })
|
||||
}),
|
||||
http.post(FOSSGIS_VALHALLA, async ({ request }) => {
|
||||
const body = await request.json() as { locations: unknown[] }
|
||||
sizes.push(body.locations.length)
|
||||
return HttpResponse.json(chain(body.locations.length - 1))
|
||||
}),
|
||||
)
|
||||
|
||||
const run = await valhallaRun(stops(14), 'driving', ['toll'])
|
||||
|
||||
expect(run?.legs).toHaveLength(13)
|
||||
expect(relayed).toEqual([14])
|
||||
// FOSSGIS never saw the piece of fourteen it would have refused with error 150.
|
||||
expect(sizes).toEqual([10, 5])
|
||||
})
|
||||
|
||||
it('VALHALLA-RUN-005: fewer than two points is nothing to route', async () => {
|
||||
let calls = 0
|
||||
server.use(http.post(FOSSGIS_VALHALLA, () => { calls++; return HttpResponse.json(chain(1)) }))
|
||||
@@ -735,10 +783,34 @@ describe('through the TREK services (routing relay)', () => {
|
||||
expect(leg?.distance).toBeCloseTo(295700, 0)
|
||||
expect(relayed).toHaveLength(1)
|
||||
expect(relayed[0].action).toBe('route')
|
||||
expect(relayed[0].body).toMatchObject({ costing: 'auto', costing_options: { auto: { use_tolls: 0 } } })
|
||||
expect(relayed[0].body).toMatchObject({
|
||||
costing: 'auto',
|
||||
costing_options: { auto: { use_tolls: 0 } },
|
||||
directions_type: 'maneuvers',
|
||||
})
|
||||
expect(fossgis).toBe(0)
|
||||
})
|
||||
|
||||
it('VALHALLA-RELAY-009: a question the relay ran out of time on has no answer, without resting the relay or asking FOSSGIS', async () => {
|
||||
let relayCalls = 0
|
||||
let fossgis = 0
|
||||
server.use(
|
||||
http.post(RELAY, () => {
|
||||
relayCalls++
|
||||
return HttpResponse.json({ error: 'The TREK routing service took too long for this route' }, { status: 504 })
|
||||
}),
|
||||
http.post(FOSSGIS_VALHALLA, () => { fossgis++; return HttpResponse.json(answer()) }),
|
||||
)
|
||||
await expect(valhallaRouteAvoiding(HAMBURG, BERLIN, 'cycling', 'ferry')).resolves.toBeNull()
|
||||
// Asked once: the relay would only run out of time on it again.
|
||||
expect([relayCalls, fossgis]).toEqual([1, 0])
|
||||
expect(valhallaBase()).toBe(TREK_VALHALLA)
|
||||
|
||||
server.use(http.post(RELAY, () => { relayCalls++; return HttpResponse.json(answer()) }))
|
||||
await expect(valhallaRouteAvoiding(HAMBURG, BERLIN, 'driving', 'toll')).resolves.not.toBeNull()
|
||||
expect([relayCalls, fossgis]).toEqual([2, 0])
|
||||
})
|
||||
|
||||
it('VALHALLA-RELAY-002: turns to FOSSGIS without a word where the relay cannot answer, and leaves it alone a while', async () => {
|
||||
for (const status of [401, 429, 503]) {
|
||||
resetValhallaTurns()
|
||||
|
||||
Reference in New Issue
Block a user