Skip to content

A spy satellite simulator in your browser, except the data is real. Live open source spatial intelligence on a photorealistic 3D globe.

test: qualify Transit visibility and city feed ownership

Saide4955f351ff8
diff --git a/changelog.d/1282-polling-issue-fix.md b/changelog.d/1282-polling-issue-fix.md
index 82f9a0fba..c7b0dec0a 100644
--- a/changelog.d/1282-polling-issue-fix.md
+++ b/changelog.d/1282-polling-issue-fix.md
@@ -1 +1,3 @@
- Pause periodic network updates in hidden tabs (asturksever, #1282).
+- Report and guard browser visibility during Transit QA so hidden-page polling pauses cannot masquerade as playback regressions (asturksever, #1282).
+- Require each live city to supply its own feed vehicles in Transit QA; retained vehicles cannot qualify another city (asturksever, #1282).
diff --git a/scripts/qa-transit-browser.mjs b/scripts/qa-transit-browser.mjs
index eb7b59985..23925c743 100644
--- a/scripts/qa-transit-browser.mjs
+++ b/scripts/qa-transit-browser.mjs
@@ -47,6 +47,7 @@ export async function reportTransitVisibility(page, label) {
const layer = app.dataManager.layers.get('transit').module;
const state = layer._transitStateForTest();
return {
+ pageVisibility: document.visibilityState,
total: state._vehicles.size,
visible: state._visible.size,
moving: state._moving.size,
@@ -59,6 +60,10 @@ export async function reportTransitVisibility(page, label) {
};
});
console.log(` ${label}: ${JSON.stringify(result)}`);
+ if (result.pageVisibility !== 'visible')
+ throw new Error(
+ `${label}: Transit QA requires a visible page; hidden pages deliberately pause polling`,
+ );
if (result.renderLoop === false || result.renderErrors.length)
throw new Error(
`${label}: Cesium render loop stopped or raised an error: ${JSON.stringify(result.renderErrors)}`,
diff --git a/scripts/qa-transit-controls.mjs b/scripts/qa-transit-controls.mjs
index b76e14706..70ed1503c 100644
--- a/scripts/qa-transit-controls.mjs
+++ b/scripts/qa-transit-controls.mjs
@@ -1,6 +1,7 @@
const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
export const BOSTON = {
id: 'boston',
+ feedId: 'mbta',
label: 'Boston (MBTA)',
lat: 42.3554,
lon: -71.0605,
@@ -11,6 +12,7 @@ const LIVE_CITIES = [
BOSTON,
{
id: 'austin',
+ feedId: 'capmetro-austin',
label: 'Austin (CapMetro)',
lat: 30.2672,
lon: -97.7431,
@@ -19,6 +21,7 @@ const LIVE_CITIES = [
},
{
id: 'minneapolis',
+ feedId: 'metrotransit-msp',
label: 'Minneapolis (Metro Transit)',
lat: 44.9778,
lon: -93.265,
@@ -27,6 +30,7 @@ const LIVE_CITIES = [
},
{
id: 'helsinki',
+ feedId: 'hsl-helsinki',
label: 'Helsinki (HSL)',
lat: 60.1699,
lon: 24.9384,
@@ -35,6 +39,7 @@ const LIVE_CITIES = [
},
{
id: 'oslo',
+ feedId: 'entur-norway',
label: 'Oslo (Entur)',
lat: 59.9139,
lon: 10.7522,
diff --git a/scripts/qa-transit.mjs b/scripts/qa-transit.mjs
index 7d83d77a4..fb0c66098 100644
--- a/scripts/qa-transit.mjs
+++ b/scripts/qa-transit.mjs
@@ -266,6 +266,7 @@ const browser = await puppeteer.launch({
executablePath: chromeExecutablePath(),
args: [
'--no-sandbox',
+ '--disable-backgrounding-occluded-windows',
'--disable-background-timer-throttling',
'--disable-renderer-backgrounding',
'--window-size=1920,1080',
@@ -391,22 +392,42 @@ try {
orientation: { heading: 0, pitch: (-40 * Math.PI) / 180, roll: 0 },
});
}, city);
- await page.waitForFunction(
- () =>
- (window.__godsEyeView.dataManager.layers
- .get('transit')
- .module.getStats().count || 0) > 0,
- { timeout: 90_000 },
- );
+ const arrived = await page
+ .waitForFunction(
+ (feedId) =>
+ [
+ ...window.__godsEyeView.dataManager.layers
+ .get('transit')
+ .module._transitStateForTest()
+ ._vehicles.keys(),
+ ].some((key) => key.startsWith(`${feedId}:`)),
+ { timeout: 90_000 },
+ city.feedId,
+ )
+ .then(
+ () => true,
+ () => false,
+ );
+ if (!arrived) {
+ check(
+ `${city.label}: live feed arrived`,
+ false,
+ `No vehicles from ${city.feedId}; retained vehicles from other cities cannot qualify this view`,
+ { unexercised: true },
+ );
+ continue;
+ }
await wait(9_000);
- const fleet = await page.evaluate(() => {
+ const fleet = await page.evaluate((feedId) => {
const layer =
window.__godsEyeView.dataManager.layers.get('transit').module;
return {
- count: layer._transitStateForTest()._vehicles.size,
+ count: [...layer._transitStateForTest()._vehicles.keys()].filter(
+ (key) => key.startsWith(`${feedId}:`),
+ ).length,
stats: layer.getStats(),
};
- });
+ }, city.feedId);
check(
`${city.label}: vehicles are rendered`,
fleet.count >= 20,
@@ -428,6 +449,7 @@ try {
.module._transitStateForTest();
let best = null;
for (const entry of state._vehicles.values()) {
+ if (!entry.key.startsWith(`${c.feedId}:`)) continue;
const d = Math.hypot(entry.to.lat - c.lat, entry.to.lon - c.lon);
if (!best || d < best.d)
best = { d, lat: entry.to.lat, lon: entry.to.lon, key: entry.key };
diff --git a/src/tooling/transitQa.test.mjs b/src/tooling/transitQa.test.mjs
index 51e4d5c44..634538c2a 100644
--- a/src/tooling/transitQa.test.mjs
+++ b/src/tooling/transitQa.test.mjs
@@ -1,6 +1,7 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
+import { getTransitFeed } from '../data/transitFeeds.js';
import {
chooseLiveCities,
selectStyle,
@@ -101,6 +102,18 @@ test('live visual cities follow local operating hours in summer and winter', ()
const cities = chooseLiveCities(now);
assert.ok(cities.length >= 1);
for (const city of cities) {
+ const feed = getTransitFeed(city.feedId);
+ assert.ok(feed, `${city.id} has a registered feed`);
+ const distanceKm =
+ 111.32 *
+ Math.hypot(
+ feed.center.lat - city.lat,
+ (feed.center.lon - city.lon) * Math.cos((city.lat * Math.PI) / 180),
+ );
+ assert.ok(
+ distanceKm < feed.loadRadiusKm,
+ `${city.id} is inside its feed's admission region`,
+ );
const local = Number(
new Intl.DateTimeFormat('en', {
timeZone: city.zone,