mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 17:26:24 +00:00
fix(server): tell a user over the routing allowance when to ask the relay again
The per-user 429 carried no Retry-After, so the planner left the relay alone for its full ten minutes and routed every day with OSRM meanwhile. It now answers like the installation limit does, with the minute the window takes.
This commit is contained in:
@@ -124,12 +124,12 @@ describe('RoutingRelayService.ask', () => {
|
||||
expect(safeFetchAdminConfigured).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('RELAY-006: holds every user to 60 questions a minute, each user apart', async () => {
|
||||
it('RELAY-006: holds every user to 60 questions a minute, each user apart, and says when to come back', async () => {
|
||||
vi.mocked(safeFetchAdminConfigured).mockImplementation(async () => upstream(200, '{}'));
|
||||
await oneByOne(times(60), () => relay.ask(1, 'height', { shape: [{ lat: 47, lon: 11 }] }));
|
||||
const refused = await relay.ask(1, 'route', ROUTE).catch((err: unknown) => err);
|
||||
expect(refused).toBeInstanceOf(DomainError);
|
||||
expect(refused).toMatchObject({ status: 429, message: 'Too many routing requests, try again in a minute' });
|
||||
const refused = await relay.ask(1, 'route', ROUTE);
|
||||
expect(refused).toMatchObject({ status: 429, retryAfter: '60' });
|
||||
expect(JSON.parse(refused.body.toString())).toEqual({ error: 'Too many routing requests, try again in a minute' });
|
||||
expect((await relay.ask(2, 'route', ROUTE)).status).toBe(200);
|
||||
expect(safeFetchAdminConfigured).toHaveBeenCalledTimes(61);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user