fix(map): ask Valhalla again for days drawn by OSRM only while the relay rested

The OSRM stand-in is kept only for a day Valhalla was asked and could not route, so a short rest or an offline session no longer keeps other days on OSRM for an hour.
This commit is contained in:
Maurice
2026-11-28 00:33:48 +01:00
parent 5c5c468489
commit bbc9c72168
2 changed files with 17 additions and 2 deletions
+2 -2
View File
@@ -317,8 +317,8 @@ async function valhallaOrOsrmDay(
const plain = (await storedRoute(keys.plain)) ?? await osrmWithLegs(waypoints, keys.coords, profile, signal)
cacheRoute(keys.plain, plain)
const drawn = withFallbackNoted(plain, avoiding)
// A day left before Valhalla answered was never refused by it.
if (standInKey && !signal?.aborted) keepStandIn(standInKey, drawn)
// A day left before Valhalla answered, or never put to it, was not refused by it.
if (standInKey && asking && !signal?.aborted) keepStandIn(standInKey, drawn)
return drawn
}
@@ -314,6 +314,21 @@ describe('the route cache keeps the engine apart', () => {
});
describe('the route cache while the relay rests', () => {
it('VDAY-CACHE-006: a day drawn by OSRM while the relay rested is asked again as soon as it is back', async () => {
let up = false;
const traffic = listen((body) => (up ? answered(body) : HttpResponse.json({ error: 'down' }, { status: 503 })));
await calculateRouteWithLegs(freshDay(2), { profile: 'driving' });
const points = freshDay(3);
expect((await calculateRouteWithLegs(points, { profile: 'driving' })).engine).toBe('osrm');
expect(traffic.relay).toHaveLength(1);
up = true;
resetValhallaTurns();
const routed = await calculateRouteWithLegs(points, { profile: 'driving' });
expect([routed.distance, routed.engine]).toEqual([4000, 'valhalla']);
expect(traffic.relay).toHaveLength(2);
});
it('VDAY-CACHE-003: a day kept from Valhalla is still found while the relay rests, as it is offline', async () => {
const points = freshDay(3);
let up = true;