From bbc9c72168dd7707147f2a7989b7365562f408b5 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sat, 28 Nov 2026 00:33:48 +0100 Subject: [PATCH] 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. --- client/src/components/Map/RouteCalculator.ts | 4 ++-- .../src/components/Map/valhallaDayRoute.test.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/client/src/components/Map/RouteCalculator.ts b/client/src/components/Map/RouteCalculator.ts index 032dc0f32..4c35c1b6d 100644 --- a/client/src/components/Map/RouteCalculator.ts +++ b/client/src/components/Map/RouteCalculator.ts @@ -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 } diff --git a/client/src/components/Map/valhallaDayRoute.test.ts b/client/src/components/Map/valhallaDayRoute.test.ts index 5d00c44fa..c422565d2 100644 --- a/client/src/components/Map/valhallaDayRoute.test.ts +++ b/client/src/components/Map/valhallaDayRoute.test.ts @@ -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;