Harden traffic history worker lifecycle and query performance
Build and Deploy Gateway / build-and-push (push) Successful in 37s
Build and Deploy Gateway / deploy (push) Successful in 19s

This commit is contained in:
2026-09-19 09:58:54 +03:00
parent 74c5b66482
commit 4c58384056
14 changed files with 509 additions and 89 deletions
+42
View File
@@ -1,6 +1,7 @@
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import test from 'node:test';
import { parse } from '@babel/parser';
const index = readFileSync(new URL('../../index.html', import.meta.url), 'utf8');
const main = readFileSync(new URL('../../src/web/main.tsx', import.meta.url), 'utf8');
@@ -23,3 +24,44 @@ test('App remains the exported composition component without bootstrap side effe
assert.match(app, /<ClientOverviewPage/);
assert.match(app, /<StaleBanner/);
});
test('state polling waits for completion and stops after cleanup', async (t) => {
const compiled = readFileSync(new URL('../../.test-dist/src/web/App.js', import.meta.url), 'utf8');
const component = parse(compiled, { sourceType: 'module' }).program.body
.find((node) => node.declaration?.id?.name === 'App').declaration;
const effect = component.body.body.map((node) => node.expression)
.filter((node) => node?.callee?.name === 'useEffect')
.map((node) => node.arguments[0])
.find((node) => compiled.slice(node.start, node.end).includes('loadState('));
// Execute the shipped effect with a deferred request; no DOM or copied polling loop.
const setup = new Function('loadState', `return (${compiled.slice(effect.start, effect.end)})`);
t.mock.timers.enable({ apis: ['setTimeout', 'setInterval'] });
let calls = 0;
let finish;
const start = setup(() => {
calls++;
return new Promise((resolve) => { finish = resolve; });
});
const cleanup = start();
assert.equal(calls, 1);
t.mock.timers.tick(40_000);
assert.equal(calls, 1);
finish();
await Promise.resolve();
t.mock.timers.tick(4_999);
assert.equal(calls, 1);
t.mock.timers.tick(1);
assert.equal(calls, 2);
cleanup();
finish();
await Promise.resolve();
t.mock.timers.tick(40_000);
assert.equal(calls, 2);
const cleanupScheduled = start();
finish();
await Promise.resolve();
cleanupScheduled();
t.mock.timers.tick(40_000);
assert.equal(calls, 3);
});