mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 02:32:18 +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
@@ -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`,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user