mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 17:52:21 +00:00
Cancel the Tarktee sibling on a body failure and settle review notes
Each Tarktee DATEX feed now reads its body as soon as its headers arrive, so a failed or oversized body aborts the other request at once instead of waiting for its headers up to the shared 30 s deadline. Status and redirect errors name the feed again. Ontario failures log the error class and system code, never the key-bearing URL or upstream text. DATA_SOURCES.md and the camera licence field use the Open Government Licence – Ontario statement the credit shows, and a test pins that credit. The focus-release rendering test now uses main's icon renderer and its isVideoFeedCamera contract. The Tarktee cancellation tests disable the 30 s deadline and time out after 2 s, so a regression fails fast instead of passing late or hanging; a duplicated older test and an unused import are gone. This PR's notes move into changelog.d/1266-cctv-shared-fix-batch.md: the 1133 fragment described main's tracking probe and terrain check, not this branch.
This commit is contained in:
1 parent
d7db1090fd
commit
bdd92663d6
9 files changed
+325
-197
No files matched your search
+2
-2
@@ -68,7 +68,7 @@ How to read this:
|
||||
| **Caltrans (cwwp2.dot.ca.gov)** | CCTV camera catalogs + frames, California districts | Public Caltrans traffic camera data | "Caltrans — cwwp2.dot.ca.gov" (courtesy) |
|
||||
| **DelDOT (video.deldot.gov)** | CCTV camera catalog (`tmc.deldot.gov/json/videocamera.json`, cached for 15 minutes) + live HTTPS HLS video, Delaware. Keyless | Public DelDOT traffic camera streams via the [DelDOT traffic map](https://deldot.gov/map/) | "DelDOT — Delaware Department of Transportation" (courtesy) |
|
||||
| **TfL Open Data (JamCams)** | CCTV camera catalog + frames, London | [TfL Open Data terms](https://tfl.gov.uk/info-for/open-data-users/) — attribution REQUIRED | "Powered by TfL Open Data. Contains OS data © Crown copyright and database rights" |
|
||||
| **Ontario 511** | CCTV camera catalog + frames, Ontario highways including Kitchener-area routes | [Open Government Licence – Ontario](https://www.ontario.ca/page/open-government-licence-ontario) | "Ontario 511" plus Open Government Licence - Ontario |
|
||||
| **Ontario 511** | CCTV camera catalog + frames, Ontario highways including Kitchener-area routes | [Open Government Licence – Ontario](https://www.ontario.ca/page/open-government-licence-ontario) | "Ontario 511. Contains information licensed under the Open Government Licence – Ontario" |
|
||||
| **Fintraffic / Digitraffic (weathercams)** | CCTV camera catalog + frames, Finland | [CC BY 4.0](https://www.digitraffic.fi/en/terms-of-service/) — attribution REQUIRED | "Fintraffic / digitraffic.fi, license CC BY 4.0" |
|
||||
| **DriveBC** (Government of British Columbia) | CCTV camera catalog + frames, British Columbia highways | [Open Government Licence – British Columbia](https://www2.gov.bc.ca/gov/content/data/open-data/open-government-licence-bc) — attribution REQUIRED | "DriveBC. Contains information licensed under the Open Government Licence – British Columbia" |
|
||||
| **Open Calgary** (`data.calgary.ca`) | CCTV camera catalog + frames, Calgary | [Open Government Licence – City of Calgary](https://data.calgary.ca/stories/s/Open-Calgary-Terms-of-Use/u45n-7awa) — attribution REQUIRED | "Contains information licensed under the Open Government Licence – City of Calgary" |
|
||||
@@ -247,7 +247,7 @@ The optional Local ADS-B layer and the broadcast-FM receiver use radio you recei
|
||||
- **Open Vessel Photos.** When you select a vessel with a nine-digit MMSI, the browser asks `https://openvesselphotos.org/v1/mmsi/{mmsi}` directly (the API is keyless and answers cross-origin, so no key and no server proxy are involved; account credentials are never sent) for that vessel only, once per MMSI per session, with an 8-second timeout. A miss (a 404 or a vessel without photos) is remembered for the session; a failed request may be asked again after five minutes. The first photo whose image is an `https://openvesselphotos.org` URL and which names a licence is shown, at the 800 px size, in the CONTEXT panel's CONTACTS view under the vessel's name and MMSI (`src/ui/views/panels/AwarenessPanel.vue`), and nowhere else (`src/data/openVesselPhoto.js`, `src/layers/vessels/photos.js`). The image is hotlinked from the URL the API gives (never copied or re-hosted); the photographer and licence are visible text next to it ("Photo: {photographer} · {licence}", or "Photo · {licence}" when the answer names no one), and the photo and credit link to the vessel's Open Vessel Photos page with `target="_blank" rel="noopener"`. If the image fails to load, the photo and its credit are hidden.
|
||||
- **Launch Library 2.** `/api/launches` makes a server-side rolling-30-day query against the supported v2.3 detailed launch endpoint, caches successful responses for 15 minutes in memory and on disk, and serves the last successful response during a throttle or transient outage. Anonymous access is limited to 15 calls/hour; deployments can provide `LL2_API_TOKEN` for authenticated access. The Space Devs' published terms permit using and sharing the API data in any form, ask users not to forward it without adding value, disclaim complete accuracy, and encourage—but do not require—attribution. This app keeps a courtesy credit. Payload and stage/recovery records are shown only when supplied. Failed launches expose their source status and never receive fallback orbit geometry or a live/estimated marker. LL2 supplies launch context and event timing, not continuous ascent telemetry or live orbital state.
|
||||
- **TfL JamCams.** The camera list comes from the keyless `api.tfl.gov.uk` endpoint (an optional `TFL_APP_KEY` raises its rate limit); frames come from TfL's public S3 bucket. The "Powered by TfL Open Data" attribution is required by TfL's terms and is registered in the Data attribution popover.
|
||||
- **Ontario 511 CCTV.** The camera list comes from the `511on.ca/api/v2/get/cameras` endpoint, which now requires a free developer key (`ONTARIO_511_API_KEY`: sign up at 511on.ca/my511/register, then request it while logged in at 511on.ca/developers/doc; throttled to 10 calls a minute). Without the key the pack is skipped. Frames are server-registered still images under `511on.ca/map/Cctv/`. The source is live-fetched at runtime and attributed under the Open Government Licence - Ontario. Access is governed by Ontario 511's Developer's Access Agreement (511on.ca/developers/resources): the data stays under the Open Government Licence - Ontario unless otherwise specified; key requests are reviewed case by case and ask for the intended use and any third parties that will receive the data; attribution by link to 511on.ca is encouraged, and the Ontario 511 logo may not be altered or used to imply endorsement (this app links and shows no logo); and the data is provided "as is", a disclaimer distributors should pass on, which the credit does.
|
||||
- **Ontario 511 CCTV.** The camera list comes from the `511on.ca/api/v2/get/cameras` endpoint, which now requires a free developer key (`ONTARIO_511_API_KEY`: sign up at 511on.ca/my511/register, then request it while logged in at 511on.ca/developers/doc; throttled to 10 calls a minute). Without the key the pack is skipped. Frames are server-registered still images under `511on.ca/map/Cctv/`. The source is live-fetched at runtime and attributed under the Open Government Licence – Ontario. Access is governed by Ontario 511's Developer's Access Agreement (511on.ca/developers/resources): the data stays under the Open Government Licence – Ontario unless otherwise specified; key requests are reviewed case by case and ask for the intended use and any third parties that will receive the data; attribution by link to 511on.ca is encouraged, and the Ontario 511 logo may not be altered or used to imply endorsement (this app links and shows no logo); and the data is provided "as is", a disclaimer distributors should pass on, which the credit does.
|
||||
- **DelDOT live video cameras.** The keyless `tmc.deldot.gov/json/videocamera.json` catalog supplies active cameras and official `https://video.deldot.gov/live/…/playlist.m3u8` links. The local server transiently buffers bounded MPEG-TS segments in memory and deletes them on session release or idle expiry. No recordings are retained. `CCTV_DELDOT_ENABLED=0` disables the pack. Public availability is not a blanket redistribution license; deployment beyond personal local viewing needs confirmation of applicable DelDOT terms.
|
||||
- **Fintraffic weathercams.** The camera list is one keyless GeoJSON request to `tie.digitraffic.fi/api/weathercam/v1/stations` (809 stations / 2,275 presets), sent with the `Digitraffic-User: gods-eye-view` header the service asks clients to identify themselves with and with gzip; frames are stills on `weathercam.digitraffic.fi`, refreshed on each station's 600 s collection interval, which is also the client's ambient-still refresh cadence for this pack (the active camera keeps the usual 10-second refresh). One preset (a fixed camera view) is one camera; stations not `GATHERING` and presets not `inCollection` are dropped. Attribution is required by the CC BY 4.0 licence and is registered in the Data attribution popover. `CCTV_FINTRAFFIC_ENABLED=0` is the kill switch.
|
||||
- **DriveBC highway cameras.** The camera list comes from the keyless `https://www.drivebc.ca/api/webcams/` endpoint served by the DriveBC.ca site ([bcgov/DriveBC.ca](https://github.com/bcgov/DriveBC.ca)); frames come from `https://www.drivebc.ca/images/<id>.jpg`, built from the numeric camera id. DataBC's [DriveBC HighwayCams](https://catalogue.data.gov.bc.ca/dataset/bc-highwaycams) catalogue entry publishes the same cameras under the Open Government Licence – British Columbia, but its CSV still lists the retired `images.drivebc.ca` frame URLs, which now return a placeholder. The licence's attribution statement is required and is registered in the Data attribution popover. By default the 250 cameras nearest Vancouver and Victoria load; `CCTV_DRIVEBC_MAX_SOURCES` changes the cap and `CCTV_DRIVEBC_ENABLED=0` turns the pack off. Some cameras in the feed are supplied by partners (TransLink, the City of Vancouver, the City of Surrey, Parks Canada / Alberta Motor Association and others); the feed's per-camera credit is carried onto the camera record and shown beside the provider in the CCTV panel.
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
- Make CCTV QA ground-sampling checks respect the active terrain regime and
|
||||
frame the actual calibration gizmo for the drag regression, preserving the
|
||||
photoreal completion floor and all drag invariants.
|
||||
- Measure the tracking arrival regression on the first visible frame within
|
||||
250 ms, accounting for the 80 ms fleet cadence while rejecting a stale
|
||||
first-visible orientation instead of retrying until it is correct.
|
||||
@@ -0,0 +1,11 @@
|
||||
- Refuse Ontario 511 catalog redirects and keep the key-bearing request URL
|
||||
and upstream error text out of failure logs, which now name only the error
|
||||
class and system code. Credit Ontario 511 with the Open Government
|
||||
Licence – Ontario attribution statement (asturksever, #1266).
|
||||
- Abort the other Tarktee (Estonia) DATEX request as soon as one fails, before
|
||||
its headers or while its body is read, instead of waiting out the shared
|
||||
30 s deadline; a response that arrives after the failure is released too
|
||||
(asturksever, #1266).
|
||||
- Frame the calibration gizmo before the CCTV QA drag regression drags it;
|
||||
default autofocus could leave the arrow shorter than the 10 px grab
|
||||
threshold (asturksever, #1266).
|
||||
+8
-10
@@ -7540,16 +7540,14 @@ silently demoting every later lookup for the session.
|
||||
empty keeps the old catalog and is retried after another 15 minutes, not on the next
|
||||
request. Estonia's Tarktee DATEX feeds, which answer in 2 to 16.6 s, get 30 s
|
||||
(`TARKTEE_FETCH_TIMEOUT_MS`) where other packs get 15 s.
|
||||
Ontario catalog requests refuse redirects and log only a fixed diagnostic for
|
||||
transport/JSON failures, so reflected request URLs or keys cannot reach logs.
|
||||
Tarktee owns both XML requests with one 30-second deadline and shared abort;
|
||||
a failed header or body read cancels its sibling, including a response arriving
|
||||
after cleanup.
|
||||
Both Tarktee XML catalogs refuse redirects and have a 4 MiB per-document
|
||||
limit, enforced against declared length and streamed bytes. A rejected fetch,
|
||||
unsuccessful response, or body-read failure releases both available response
|
||||
bodies; read failures also cancel an active sibling reader. Cameras sharing
|
||||
an image number are deduplicated before the Tarktee pack cap is applied.
|
||||
Ontario catalog requests refuse redirects and log only the error class and
|
||||
system code for transport/JSON failures, never the request URL or key.
|
||||
Both Tarktee XML catalogs share that 30 s deadline, refuse redirects and
|
||||
have a 4 MiB per-document limit, enforced against declared length and
|
||||
streamed bytes. A failed request, unsuccessful response or body read aborts
|
||||
the other feed at once and releases every response body, including one that
|
||||
arrives after the failure. Cameras sharing an image number are deduplicated
|
||||
before the Tarktee pack cap is applied.
|
||||
- **CCTV v3 UX — viewshed + calibration gizmo** (built 2026-07-05 and field
|
||||
validated 2026-07-21): the COVERAGE toggle is a
|
||||
tri-state cycle `OFF → ON → VIEWSHED`; viewshed mode renders each visible camera's frustum
|
||||
|
||||
@@ -561,6 +561,22 @@ export function _resetOntarioKeyWarningForTest() {
|
||||
ontarioKeyMissingLogged = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* What failed in an Ontario download, without upstream text: the error class,
|
||||
* plus the system code (`ENOTFOUND`) or a refused redirect when there is one.
|
||||
* @param {unknown} error
|
||||
* @returns {string}
|
||||
*/
|
||||
function ontarioFailureKind(error) {
|
||||
const name = /^[A-Za-z]{1,40}$/.test(error?.name) ? error.name : 'Error';
|
||||
if (error?.cause?.message === 'unexpected redirect')
|
||||
return `${name}, redirect refused`;
|
||||
const code = error?.cause?.code;
|
||||
return typeof code === 'string' && /^[A-Z][A-Z0-9_]{1,40}$/.test(code)
|
||||
? `${name} ${code}`
|
||||
: name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch Ontario 511 CCTV cameras. The camera list comes from the 511 API,
|
||||
* which now requires a free developer key (511on.ca/developers/doc, "Requires a
|
||||
@@ -659,7 +675,7 @@ export async function loadOntarioSourcesFromOpenData(
|
||||
url: view.url,
|
||||
snapshotUrl: view.url,
|
||||
sourceKind: 'ontario-511-open-data',
|
||||
license: 'Open Government Licence - Ontario',
|
||||
license: 'Open Government Licence – Ontario',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -677,11 +693,11 @@ export async function loadOntarioSourcesFromOpenData(
|
||||
`[CCTV] Loaded Ontario 511 camera sources: ${unique.length} enabled (using nearest ${prioritized.length})`,
|
||||
);
|
||||
return prioritized;
|
||||
} catch {
|
||||
// Transport and JSON errors may reflect the credential-bearing request.
|
||||
// Do not log upstream exception text, response bodies or URLs.
|
||||
} catch (error) {
|
||||
// Transport and JSON errors may reflect the credential-bearing request,
|
||||
// so only the error class and a system code are logged, never the text.
|
||||
console.warn(
|
||||
'[CCTV] Ontario 511 camera download error (network or invalid response)',
|
||||
`[CCTV] Ontario 511 camera download error (${ontarioFailureKind(error)})`,
|
||||
);
|
||||
return [];
|
||||
}
|
||||
@@ -1280,49 +1296,46 @@ export function parseTarkteeDatexImages(xml) {
|
||||
* @returns {Promise<Array<object>>} Normalized camera source objects.
|
||||
*/
|
||||
export async function loadTarkteeSourcesFromDatex() {
|
||||
// Own both transports before either can reject. A response that arrives
|
||||
// after cleanup must also be discarded instead of escaping Promise.all.
|
||||
const abort = new AbortController();
|
||||
// One deadline for both feeds. Whichever read fails first aborts the other,
|
||||
// so a stalled sibling is not waited on until the deadline.
|
||||
const sibling = new AbortController();
|
||||
const signal = AbortSignal.any([
|
||||
abort.signal,
|
||||
sibling.signal,
|
||||
AbortSignal.timeout(TARKTEE_FETCH_TIMEOUT_MS),
|
||||
]);
|
||||
const responses = [];
|
||||
const discardBoth = async () => {
|
||||
abort.abort();
|
||||
await Promise.allSettled(
|
||||
responses.map((response) => response.body?.cancel()),
|
||||
);
|
||||
return [];
|
||||
};
|
||||
const fetchXml = async (url) => {
|
||||
const response = await fetch(url, {
|
||||
headers: { Accept: 'application/xml,text/xml,*/*' },
|
||||
redirect: 'manual',
|
||||
signal,
|
||||
});
|
||||
if (signal.aborted) {
|
||||
await Promise.allSettled([response.body?.cancel()]);
|
||||
const readXml = async (url, feed) => {
|
||||
let response;
|
||||
try {
|
||||
response = await fetch(url, {
|
||||
headers: { Accept: 'application/xml,text/xml,*/*' },
|
||||
redirect: 'manual',
|
||||
signal,
|
||||
});
|
||||
signal.throwIfAborted();
|
||||
}
|
||||
responses.push(response);
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
response.status >= 300 && response.status < 400
|
||||
? 'catalog redirected; redirects are not followed'
|
||||
: `catalog HTTP ${response.status}`,
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
response.status >= 300 && response.status < 400
|
||||
? `${feed} catalog redirected; redirects are not followed`
|
||||
: `${feed} download failed: ${response.status}`,
|
||||
);
|
||||
}
|
||||
return await readResponseTextCapped(
|
||||
response,
|
||||
TARKTEE_MAX_CATALOG_BYTES,
|
||||
signal,
|
||||
);
|
||||
} catch (error) {
|
||||
// The join needs both feeds: stop the other one now, and release this
|
||||
// body, including a response that arrived after the other failed.
|
||||
sibling.abort();
|
||||
await response?.body?.cancel().catch(() => {});
|
||||
throw error;
|
||||
}
|
||||
return response;
|
||||
};
|
||||
try {
|
||||
const [locResp, imgResp] = await Promise.all([
|
||||
fetchXml(TARKTEE_LOCATIONS_URL),
|
||||
fetchXml(TARKTEE_IMAGES_URL),
|
||||
]);
|
||||
const [locXml, imgXml] = await Promise.all([
|
||||
readResponseTextCapped(locResp, TARKTEE_MAX_CATALOG_BYTES, signal),
|
||||
readResponseTextCapped(imgResp, TARKTEE_MAX_CATALOG_BYTES, signal),
|
||||
readXml(TARKTEE_LOCATIONS_URL, 'locations'),
|
||||
readXml(TARKTEE_IMAGES_URL, 'images'),
|
||||
]);
|
||||
const locations = parseTarkteeDatexLocations(locXml);
|
||||
const images = parseTarkteeDatexImages(imgXml);
|
||||
@@ -1384,7 +1397,6 @@ export async function loadTarkteeSourcesFromDatex() {
|
||||
);
|
||||
return prioritized;
|
||||
} catch (error) {
|
||||
await discardBoth();
|
||||
console.warn(
|
||||
'[CCTV] Tarktee DATEX download error:',
|
||||
error?.message || error,
|
||||
|
||||
+101
-113
@@ -4,7 +4,6 @@ import {
|
||||
TARKTEE_IMAGES_URL,
|
||||
TARKTEE_LOCATIONS_URL,
|
||||
TARKTEE_MAX_CATALOG_BYTES,
|
||||
TARKTEE_FETCH_TIMEOUT_MS,
|
||||
} from '../../server/providers/cctv/constants.js';
|
||||
import {
|
||||
loadTallinnSourcesFromCatalog,
|
||||
@@ -13,6 +12,14 @@ import {
|
||||
parseTarkteeDatexLocations,
|
||||
} from '../../server/providers/cctv/sources.js';
|
||||
|
||||
/**
|
||||
* Disarm the 30 s deadline, so a loader that only stops at that deadline
|
||||
* fails at the test timeout instead of passing late.
|
||||
*/
|
||||
function withoutDeadline(t) {
|
||||
t.mock.method(AbortSignal, 'timeout', () => new AbortController().signal);
|
||||
}
|
||||
|
||||
/** Silence the loaders' progress and failure logging. */
|
||||
function quiet(t) {
|
||||
t.mock.method(console, 'log', () => {});
|
||||
@@ -192,48 +199,6 @@ test('Tarktee loader refuses a redirect and cancels both response bodies', async
|
||||
assert.equal(cancelled.images, true, 'sibling 200 body is also cancelled');
|
||||
});
|
||||
|
||||
test('Tarktee loader cancels fulfilled bodies when either fetch rejects', async (t) => {
|
||||
for (const failedUrl of [TARKTEE_LOCATIONS_URL, TARKTEE_IMAGES_URL]) {
|
||||
for (const delayedSibling of [false, true]) {
|
||||
await t.test(
|
||||
`${failedUrl}, delayed sibling: ${delayedSibling}`,
|
||||
async (t) => {
|
||||
quiet(t);
|
||||
let cancelled = false;
|
||||
const response = new Response(
|
||||
new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue(new TextEncoder().encode('<xml/>'));
|
||||
},
|
||||
cancel() {
|
||||
cancelled = true;
|
||||
},
|
||||
}),
|
||||
);
|
||||
t.mock.method(globalThis, 'fetch', async (url) => {
|
||||
if (String(url) === failedUrl) throw new TypeError('fetch failed');
|
||||
if (delayedSibling) await new Promise(setImmediate);
|
||||
return response;
|
||||
});
|
||||
|
||||
try {
|
||||
assert.deepEqual(await loadTarkteeSourcesFromDatex(), []);
|
||||
// An aborted mock transport may still deliver its queued response.
|
||||
if (delayedSibling) await new Promise(setImmediate);
|
||||
assert.equal(
|
||||
cancelled,
|
||||
true,
|
||||
'fulfilled sibling body is cancelled',
|
||||
);
|
||||
} finally {
|
||||
await response.body.cancel();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('Tarktee loader cancels the sibling body when one feed fails or overflows the byte cap', async (t) => {
|
||||
quiet(t);
|
||||
let siblingCancelled = false;
|
||||
@@ -292,63 +257,81 @@ test('Tarktee loader cancels the sibling body when one feed fails or overflows t
|
||||
|
||||
for (const failingUrl of [TARKTEE_LOCATIONS_URL, TARKTEE_IMAGES_URL]) {
|
||||
for (const lateSibling of [false, true]) {
|
||||
test(`Tarktee cancels a ${lateSibling ? 'late' : 'received'} sibling when ${failingUrl} rejects before headers`, async (t) => {
|
||||
test(
|
||||
`Tarktee cancels a ${lateSibling ? 'late' : 'received'} sibling when ${failingUrl} rejects before headers`,
|
||||
{ timeout: 2000 },
|
||||
async (t) => {
|
||||
quiet(t);
|
||||
withoutDeadline(t);
|
||||
let cancelled = false;
|
||||
let siblingSignal;
|
||||
let release;
|
||||
const gate = new Promise((resolve) => {
|
||||
release = resolve;
|
||||
});
|
||||
t.mock.method(globalThis, 'fetch', async (url, init) => {
|
||||
if (String(url) === failingUrl)
|
||||
throw new Error('headers unavailable');
|
||||
siblingSignal = init.signal;
|
||||
// A late transport answers once the sibling is aborted, or on release.
|
||||
if (lateSibling)
|
||||
await Promise.race([
|
||||
gate,
|
||||
new Promise((resolve) =>
|
||||
init.signal.addEventListener('abort', resolve, { once: true }),
|
||||
),
|
||||
]);
|
||||
return new Response(
|
||||
new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue(new TextEncoder().encode('<xml/>'));
|
||||
},
|
||||
cancel() {
|
||||
cancelled = true;
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
assert.deepEqual(await loadTarkteeSourcesFromDatex(), []);
|
||||
// Also exercise a response arriving after abort, as a queued transport
|
||||
// completion can race the rejection owner even when fetch honors abort.
|
||||
if (lateSibling) {
|
||||
release();
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
}
|
||||
assert.equal(cancelled, true, 'every obtained body must be cancelled');
|
||||
assert.equal(
|
||||
siblingSignal.aborted,
|
||||
true,
|
||||
'a pending transport is aborted immediately',
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
test(
|
||||
`Tarktee aborts a pending sibling when ${failingUrl} rejects`,
|
||||
{ timeout: 2000 },
|
||||
async (t) => {
|
||||
quiet(t);
|
||||
let cancelled = false;
|
||||
let siblingSignal;
|
||||
let release;
|
||||
const gate = new Promise((resolve) => {
|
||||
release = resolve;
|
||||
});
|
||||
withoutDeadline(t);
|
||||
let aborted = false;
|
||||
t.mock.method(globalThis, 'fetch', async (url, init) => {
|
||||
if (String(url) === failingUrl) throw new Error('headers unavailable');
|
||||
siblingSignal = init.signal;
|
||||
if (lateSibling) await gate;
|
||||
return new Response(
|
||||
new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue(new TextEncoder().encode('<xml/>'));
|
||||
return new Promise((resolve, reject) => {
|
||||
init.signal.addEventListener(
|
||||
'abort',
|
||||
() => {
|
||||
aborted = true;
|
||||
reject(init.signal.reason);
|
||||
},
|
||||
cancel() {
|
||||
cancelled = true;
|
||||
},
|
||||
}),
|
||||
);
|
||||
{ once: true },
|
||||
);
|
||||
});
|
||||
});
|
||||
assert.deepEqual(await loadTarkteeSourcesFromDatex(), []);
|
||||
// Also exercise a response arriving after abort, as a queued transport
|
||||
// completion can race the rejection owner even when fetch honors abort.
|
||||
if (lateSibling) {
|
||||
release();
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
}
|
||||
assert.equal(cancelled, true, 'every obtained body must be cancelled');
|
||||
assert.equal(
|
||||
siblingSignal.aborted,
|
||||
true,
|
||||
'a pending transport is aborted immediately',
|
||||
);
|
||||
});
|
||||
}
|
||||
test(`Tarktee aborts a pending sibling when ${failingUrl} rejects`, async (t) => {
|
||||
quiet(t);
|
||||
let aborted = false;
|
||||
t.mock.method(globalThis, 'fetch', async (url, init) => {
|
||||
if (String(url) === failingUrl) throw new Error('headers unavailable');
|
||||
return new Promise((resolve, reject) => {
|
||||
init.signal.addEventListener(
|
||||
'abort',
|
||||
() => {
|
||||
aborted = true;
|
||||
reject(init.signal.reason);
|
||||
},
|
||||
{ once: true },
|
||||
);
|
||||
});
|
||||
});
|
||||
assert.deepEqual(await loadTarkteeSourcesFromDatex(), []);
|
||||
assert.equal(aborted, true, 'do not wait for the 30-second deadline');
|
||||
});
|
||||
assert.equal(aborted, true, 'do not wait for the 30-second deadline');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
test('Tarktee cancels both lengthless streams when one exceeds the byte cap', async (t) => {
|
||||
@@ -379,23 +362,28 @@ test('Tarktee cancels both lengthless streams when one exceeds the byte cap', as
|
||||
);
|
||||
});
|
||||
|
||||
test('Tarktee aborts pending headers as soon as its sibling returns an HTTP error', async (t) => {
|
||||
quiet(t);
|
||||
let aborted = false;
|
||||
t.mock.method(globalThis, 'fetch', async (url, init) => {
|
||||
if (String(url) === TARKTEE_LOCATIONS_URL)
|
||||
return new Response('unavailable', { status: 503 });
|
||||
return new Promise((resolve, reject) => {
|
||||
init.signal.addEventListener(
|
||||
'abort',
|
||||
() => {
|
||||
aborted = true;
|
||||
reject(init.signal.reason);
|
||||
},
|
||||
{ once: true },
|
||||
);
|
||||
test(
|
||||
'Tarktee aborts pending headers as soon as its sibling returns an HTTP error',
|
||||
{ timeout: 2000 },
|
||||
async (t) => {
|
||||
quiet(t);
|
||||
withoutDeadline(t);
|
||||
let aborted = false;
|
||||
t.mock.method(globalThis, 'fetch', async (url, init) => {
|
||||
if (String(url) === TARKTEE_LOCATIONS_URL)
|
||||
return new Response('unavailable', { status: 503 });
|
||||
return new Promise((resolve, reject) => {
|
||||
init.signal.addEventListener(
|
||||
'abort',
|
||||
() => {
|
||||
aborted = true;
|
||||
reject(init.signal.reason);
|
||||
},
|
||||
{ once: true },
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
assert.deepEqual(await loadTarkteeSourcesFromDatex(), []);
|
||||
assert.equal(aborted, true);
|
||||
});
|
||||
assert.deepEqual(await loadTarkteeSourcesFromDatex(), []);
|
||||
assert.equal(aborted, true);
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,92 @@
|
||||
// A body-phase failure of one Tarktee DATEX feed must abort the sibling that is
|
||||
// still waiting for headers instead of leaving it until the 30 s deadline.
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import http from 'node:http';
|
||||
import {
|
||||
TARKTEE_IMAGES_URL,
|
||||
TARKTEE_LOCATIONS_URL,
|
||||
TARKTEE_MAX_CATALOG_BYTES,
|
||||
} from '../../server/providers/cctv/constants.js';
|
||||
import { loadTarkteeSourcesFromDatex } from '../../server/providers/cctv/sources.js';
|
||||
|
||||
/** The sibling sends its headers this late; the loader must not wait for it. */
|
||||
const SIBLING_HEADER_DELAY_MS = 2000;
|
||||
/** Generous bound for "at once" on a loaded CI machine. */
|
||||
const FAIL_FAST_MS = 1000;
|
||||
|
||||
function startServer(handlers) {
|
||||
const server = http.createServer((req, res) => handlers[req.url](req, res));
|
||||
return new Promise((resolve) => {
|
||||
server.listen(0, '127.0.0.1', () => resolve(server));
|
||||
});
|
||||
}
|
||||
|
||||
/** Send the two DATEX URLs to the local server through the real fetch. */
|
||||
function routeFetchTo(t, port) {
|
||||
const realFetch = globalThis.fetch;
|
||||
t.mock.method(globalThis, 'fetch', (url, init) => {
|
||||
const path =
|
||||
String(url) === TARKTEE_LOCATIONS_URL
|
||||
? '/loc'
|
||||
: String(url) === TARKTEE_IMAGES_URL
|
||||
? '/img'
|
||||
: null;
|
||||
assert.ok(path, `unexpected url ${url}`);
|
||||
return realFetch(`http://127.0.0.1:${port}${path}`, init);
|
||||
});
|
||||
}
|
||||
|
||||
const slowHeaders = (req, res) => {
|
||||
const timer = setTimeout(() => {
|
||||
res.writeHead(200, { 'content-type': 'application/xml' });
|
||||
res.end('<d2LogicalModel/>');
|
||||
}, SIBLING_HEADER_DELAY_MS);
|
||||
res.on('close', () => clearTimeout(timer));
|
||||
};
|
||||
|
||||
const failingBodies = {
|
||||
'declares a body over the byte cap': (req, res) => {
|
||||
res.writeHead(200, {
|
||||
'content-type': 'application/xml',
|
||||
'content-length': String(TARKTEE_MAX_CATALOG_BYTES + 1),
|
||||
});
|
||||
res.write('<d2LogicalModel>');
|
||||
},
|
||||
'resets the connection mid-body': (req, res) => {
|
||||
res.writeHead(200, { 'content-type': 'application/xml' });
|
||||
res.write('<d2LogicalModel><payloadPublication>');
|
||||
setTimeout(() => res.socket.destroy(), 20);
|
||||
},
|
||||
};
|
||||
|
||||
for (const [label, failingFeed] of Object.entries(failingBodies)) {
|
||||
for (const [failing, pending] of [
|
||||
['/loc', '/img'],
|
||||
['/img', '/loc'],
|
||||
]) {
|
||||
test(`Tarktee aborts ${pending} pending headers when ${failing} ${label}`, { timeout: 10_000 }, async (t) => {
|
||||
t.mock.method(console, 'log', () => {});
|
||||
t.mock.method(console, 'warn', () => {});
|
||||
const server = await startServer({
|
||||
[failing]: failingFeed,
|
||||
[pending]: slowHeaders,
|
||||
});
|
||||
t.after(() => {
|
||||
server.closeAllConnections();
|
||||
server.close();
|
||||
});
|
||||
routeFetchTo(t, server.address().port);
|
||||
|
||||
const started = Date.now();
|
||||
const cameras = await loadTarkteeSourcesFromDatex();
|
||||
const elapsed = Date.now() - started;
|
||||
|
||||
assert.deepEqual(cameras, []);
|
||||
assert.ok(
|
||||
elapsed < FAIL_FAST_MS,
|
||||
`loader waited ${elapsed} ms for the sibling's headers instead of aborting it`,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -173,6 +173,18 @@ test('the NYC camera credit carries NYC DOT’s requested disclaimer', () => {
|
||||
assert.match(credit.html, /observe posted signage/);
|
||||
});
|
||||
|
||||
test('the Ontario 511 camera credit carries the licence attribution statement', () => {
|
||||
const credit = DATA_CREDITS.find((entry) => entry.key === 'ontario-511-cctv');
|
||||
assert.ok(credit, 'Ontario 511 camera frames must be credited');
|
||||
assert.ok(
|
||||
credit.html.includes(
|
||||
'Contains information licensed under the <a href="https://www.ontario.ca/page/open-government-licence-ontario"',
|
||||
),
|
||||
);
|
||||
assert.match(credit.html, />Open Government Licence – Ontario<\/a>/);
|
||||
assert.match(credit.html, /Provided as is, without warranty/);
|
||||
});
|
||||
|
||||
test("the Houston camera credit names TranStar's terms and the permission they require", () => {
|
||||
const credit = DATA_CREDITS.find((entry) => entry.key === 'houston-cctv');
|
||||
assert.ok(credit, 'Houston TranStar camera frames must be credited');
|
||||
|
||||
@@ -378,14 +378,22 @@ test('a pose with no perspective field of view is projected by the renderer', ()
|
||||
});
|
||||
|
||||
test('focus release restores video hue and alpha after the style throttle', () => {
|
||||
const viewer = {};
|
||||
const camera = fakeCameraPort({
|
||||
pose: { position: { x: 6378137 + 1000, y: 0, z: 0 } },
|
||||
});
|
||||
const { unbind } = bindFakeDraw(viewer, {
|
||||
camera: camera.port,
|
||||
query: { project: () => ({ x: 10, y: 20 }) },
|
||||
});
|
||||
let target = {};
|
||||
const records = ['mp4', 'webm'].map((feedType) => ({
|
||||
camera: { id: feedType, feedType },
|
||||
billboard: { show: true, color: LIVE_CAMERA_COLOR },
|
||||
position: { x: 6378137, y: 0, z: 0 },
|
||||
}));
|
||||
const state = {
|
||||
_enabled: true,
|
||||
_viewer: { scene: {}, camera: {} },
|
||||
_viewer: viewer,
|
||||
_records: records,
|
||||
_activeCameraId: null,
|
||||
_activeFocusStyleCount: 0,
|
||||
@@ -402,30 +410,43 @@ test('focus release restores video hue and alpha after the style throttle', () =
|
||||
}),
|
||||
focusAlphaNeedsWrite: (before, after) => before !== after,
|
||||
};
|
||||
const { refreshCctvFocusStyles } = createRendering({
|
||||
state,
|
||||
services: { focus },
|
||||
parts: { model: { isVideoFeedType } },
|
||||
source: {},
|
||||
});
|
||||
const { createCameraIcons, addCameraIcon, refreshCctvFocusStyles } =
|
||||
createRendering({
|
||||
state,
|
||||
services: { focus },
|
||||
parts: {
|
||||
model: {
|
||||
isVideoFeedCamera: (camera) => isVideoFeedType(camera.feedType),
|
||||
},
|
||||
},
|
||||
source: {},
|
||||
});
|
||||
try {
|
||||
createCameraIcons(viewer);
|
||||
for (const record of records) addCameraIcon(record);
|
||||
const icons = state._icons;
|
||||
|
||||
refreshCctvFocusStyles(1000);
|
||||
for (const record of records) {
|
||||
assertFadedFrom(
|
||||
record.billboard.color,
|
||||
LIVE_CAMERA_COLOR,
|
||||
record.camera.id,
|
||||
);
|
||||
refreshCctvFocusStyles(1000);
|
||||
for (const record of records) {
|
||||
assertKeepsColor(
|
||||
icons,
|
||||
record.camera.id,
|
||||
LIVE_CAMERA_COLOR,
|
||||
record.camera.id,
|
||||
);
|
||||
}
|
||||
target = null;
|
||||
refreshCctvFocusStyles(1050);
|
||||
for (const record of records) {
|
||||
assert.equal(icons.focus(record.camera.id), FOCUS_FACTOR, 'throttled');
|
||||
}
|
||||
refreshCctvFocusStyles(1100);
|
||||
for (const record of records) {
|
||||
assert.deepEqual(icons.item(record.camera.id).color, LIVE_CAMERA_COLOR);
|
||||
assert.equal(icons.focus(record.camera.id), 1);
|
||||
}
|
||||
assert.equal(state._activeFocusStyleCount, 0);
|
||||
} finally {
|
||||
unbind();
|
||||
}
|
||||
const dimmed = records.map((record) => record.billboard.color);
|
||||
target = null;
|
||||
refreshCctvFocusStyles(1050);
|
||||
for (let i = 0; i < records.length; i += 1) {
|
||||
assert.equal(records[i].billboard.color, dimmed[i]);
|
||||
}
|
||||
refreshCctvFocusStyles(1100);
|
||||
for (const record of records) {
|
||||
assert.deepEqual(record.billboard.color, LIVE_CAMERA_COLOR);
|
||||
}
|
||||
assert.equal(state._activeFocusStyleCount, 0);
|
||||
});
|
||||
Reference in new issue
Block a user