mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 00:02:25 +00:00
fix(news): answer within the browser's wait on a first read
A country's first World News API read, or Liveuamap's, could take up to 20 s while the browser waits 15, so the panel showed the browser's own "signal timed out". A read with nothing to serve yet is now waited for at most 12 s, as GDELT's already was: past that the section answers unavailable while the read goes on, and the next refresh is served from it. A client timeout reads "News feed unavailable".
This commit is contained in:
1 parent
525543d08a
commit
c6ae4c44d7
6 files changed
+87
-25
No files matched your search
@@ -1082,3 +1082,35 @@ test("a country's own news keeps World News API's category and no severity, what
|
||||
assert.equal(read('King visits Amman', 'politics').category, 'political');
|
||||
assert.equal(read('Parliament session opens', null).category, 'other');
|
||||
});
|
||||
|
||||
test('a first read slower than the browser waits answers unavailable, and the next ask is served from it', async () => {
|
||||
const fake = upstream();
|
||||
let release;
|
||||
const held = new Promise((resolve) => {
|
||||
release = resolve;
|
||||
});
|
||||
const news = createKeyedNews({
|
||||
env: () => ({ WORLDNEWSAPI_KEY: 'wna-key' }),
|
||||
fetchImpl: async (url, init) => {
|
||||
if (new URL(url).host === 'api.worldnewsapi.com') await held;
|
||||
return fake.fetchImpl(url, init);
|
||||
},
|
||||
now: () => NOW,
|
||||
log: () => {},
|
||||
later: () => {},
|
||||
firstAnswerMs: 20,
|
||||
});
|
||||
const local = () =>
|
||||
news.answer('/feed', new URLSearchParams('hotspot=all&at=31.95,35.93'));
|
||||
assert.deepEqual(await local(), UPSTREAM_ERROR);
|
||||
// The read went on, and is not asked again.
|
||||
release();
|
||||
await new Promise((resolve) => setTimeout(resolve, 5));
|
||||
const served = await local();
|
||||
assert.equal(served.status, 200);
|
||||
assert.deepEqual(
|
||||
served.body.reports.map((r) => r.id),
|
||||
['wna-9001', 'wna-9002'],
|
||||
);
|
||||
assert.equal(count(fake.calls, 'api.worldnewsapi.com'), 1);
|
||||
});
|
||||
Reference in new issue
Block a user