mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 19:04:02 +00:00
keep cancelled outline and search asks free during the Nominatim probe
Recheck the caller's signal right after the capability probe on every path, so an ask cleared while the probe is pending starts no outline or last-resort search request, whether the probe says configured, unknown or not configured.
This commit is contained in:
1 parent
f32ab5446b
commit
3824b4ebfc
4 files changed
+69
-7
No files matched your search
@@ -96,8 +96,10 @@ export function createNominatimOutlineClient({
|
||||
if (remembered.has(key)) return remembered.get(key);
|
||||
// A cancelled ask spends nothing.
|
||||
signal?.throwIfAborted();
|
||||
if (configured && (await configured()) === false) {
|
||||
signal?.throwIfAborted();
|
||||
const capability = configured ? await configured() : null;
|
||||
// The probe may have waited: an ask cancelled meanwhile still spends nothing.
|
||||
signal?.throwIfAborted();
|
||||
if (capability === false) {
|
||||
unavailable = {
|
||||
unavailable: true,
|
||||
retryable: false,
|
||||
|
||||
@@ -179,3 +179,34 @@ test('a configured server is asked as usual after one probe', async () => {
|
||||
assert.equal(calls.length, 2);
|
||||
assert.equal(probes.length, 1);
|
||||
});
|
||||
|
||||
test('an ask cancelled while the capability probe is pending spends nothing', async () => {
|
||||
for (const [label, answer] of [
|
||||
['configured', () => reply(200, { configured: true })],
|
||||
['unknown', () => reply(404, { error: 'Not Found' })],
|
||||
['unconfigured', () => reply(200, { configured: false })],
|
||||
]) {
|
||||
let release;
|
||||
const held = new Promise((resolve) => {
|
||||
release = resolve;
|
||||
});
|
||||
const { calls, lookup } = client(
|
||||
() => reply(200, { status: 'ZERO_RESULTS', outline: null }),
|
||||
{
|
||||
status: async () => {
|
||||
await held;
|
||||
return answer();
|
||||
},
|
||||
},
|
||||
);
|
||||
const controller = new AbortController();
|
||||
const pending = lookup(
|
||||
{ query: 'Paris', kind: 'city' },
|
||||
{ signal: controller.signal },
|
||||
);
|
||||
controller.abort();
|
||||
release();
|
||||
await assert.rejects(pending, { name: 'AbortError' }, label);
|
||||
assert.equal(calls.length, 0, `${label}: no outline request`);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user