mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 02:14:01 +00:00
test: fix flaky timing and timeout guards (#969)
Clears the timeout guards once each race settles, measures the 15,000-vehicle transit ingestion with main-thread CPU time instead of wall time, and times the region-timeout case from the boundary lookup with a 2 s ceiling, below the 3 s default budget, so an ignored budget still fails. Co-authored-by: Sameh Khamis <[email protected]>
This commit is contained in:
1 parent
4cacd4cc00
commit
504d56ba2b
4 files changed
+29
-17
No files matched your search
@@ -142,9 +142,11 @@ test('three identical-order 15000-vehicle snapshots retain paths within a bounde
|
|||||||
const rows = Array.from({ length: 15000 }, (_, i) =>
|
const rows = Array.from({ length: 15000 }, (_, i) =>
|
||||||
row(now, `vehicle-${i}`),
|
row(now, `vehicle-${i}`),
|
||||||
);
|
);
|
||||||
const start = performance.now();
|
// Main-thread CPU: excludes scheduler waits and parallel GC helper threads.
|
||||||
|
const start = process.threadCpuUsage();
|
||||||
h.ingest(feed, rows, now);
|
h.ingest(feed, rows, now);
|
||||||
times.push(performance.now() - start);
|
const usage = process.threadCpuUsage(start);
|
||||||
|
times.push((usage.user + usage.system) / 1000);
|
||||||
}
|
}
|
||||||
assert.equal(h.diagnostics().keys, 15000);
|
assert.equal(h.diagnostics().keys, 15000);
|
||||||
for (let i = 0; i < 15000; i++) {
|
for (let i = 0; i < 15000; i++) {
|
||||||
@@ -154,12 +156,12 @@ test('three identical-order 15000-vehicle snapshots retain paths within a bounde
|
|||||||
}
|
}
|
||||||
assert.ok(h.diagnostics().allocatedBytes < 16 * 1024 * 1024);
|
assert.ok(h.diagnostics().allocatedBytes < 16 * 1024 * 1024);
|
||||||
t.diagnostic(
|
t.diagnostic(
|
||||||
`15000-vehicle ingestion ms: ${times.map((n) => n.toFixed(1)).join('/')}`,
|
`15000-vehicle ingestion CPU ms: ${times.map((n) => n.toFixed(1)).join('/')}`,
|
||||||
);
|
);
|
||||||
// A ceiling that says "not quadratic", not a benchmark: 15,000 rows in
|
// CPU time measures ingestion work without counting scheduler delays on
|
||||||
// well under two seconds on a loaded laptop or a slow CI runner. The
|
// loaded runners. Keep the two-second ceiling as a guard against quadratic
|
||||||
// per-run figure above is the diagnostic to read.
|
// work, not a benchmark; the per-poll figures above show any slowdown.
|
||||||
assert.ok(Math.max(...times) < 2000, `ingestion ms: ${times}`);
|
assert.ok(Math.max(...times) < 2000, `ingestion CPU ms: ${times}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('snapshot capacity pressure preserves members not yet visited and discloses recreated history', (t) => {
|
test('snapshot capacity pressure preserves members not yet visited and discloses recreated history', (t) => {
|
||||||
|
|||||||
@@ -51,9 +51,11 @@ test('region ring: Natural Earth names resolve without a geocoder', async () =>
|
|||||||
test('region ring: a slow admin-boundary lookup returns region-timeout within the budget', async () => {
|
test('region ring: a slow admin-boundary lookup returns region-timeout within the budget', async () => {
|
||||||
let adminSignal;
|
let adminSignal;
|
||||||
let release;
|
let release;
|
||||||
|
let lookupStarted;
|
||||||
const { resolveRegionRingForQuery } = createAnnotationResolver({
|
const { resolveRegionRingForQuery } = createAnnotationResolver({
|
||||||
featureSource: featureSource({
|
featureSource: featureSource({
|
||||||
getAdministrativeAreas(_point, { signal }) {
|
getAdministrativeAreas(_point, { signal }) {
|
||||||
|
lookupStarted = Date.now();
|
||||||
adminSignal = signal;
|
adminSignal = signal;
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
release = resolve;
|
release = resolve;
|
||||||
@@ -61,7 +63,6 @@ test('region ring: a slow admin-boundary lookup returns region-timeout within th
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
const started = Date.now();
|
|
||||||
const region = await resolveRegionRingForQuery(
|
const region = await resolveRegionRingForQuery(
|
||||||
'Atlantis',
|
'Atlantis',
|
||||||
undefined,
|
undefined,
|
||||||
@@ -73,8 +74,10 @@ test('region ring: a slow admin-boundary lookup returns region-timeout within th
|
|||||||
ring: null,
|
ring: null,
|
||||||
error: 'region-timeout',
|
error: 'region-timeout',
|
||||||
});
|
});
|
||||||
|
// Timed from the boundary lookup, so the bundled pack scans before it do not
|
||||||
|
// count. Under the 3 s default budget, so an ignored budgetMs still fails.
|
||||||
assert.ok(
|
assert.ok(
|
||||||
Date.now() - started < 1000,
|
Date.now() - lookupStarted < 2_000,
|
||||||
'returns at the budget, not the lookup',
|
'returns at the budget, not the lookup',
|
||||||
);
|
);
|
||||||
// The lookup is left running so it can fill the boundary cache.
|
// The lookup is left running so it can fill the boundary cache.
|
||||||
|
|||||||
@@ -2398,10 +2398,13 @@ test('a newer absolute intent aborts a hung guard-compensation instead of starvi
|
|||||||
removeGuard();
|
removeGuard();
|
||||||
// The newest intent must be able to abort the hung compensation and run.
|
// The newest intent must be able to abort the hung compensation and run.
|
||||||
const pendingFinalOn = mgr.setEnabled('flights', true, { origin: 'user' });
|
const pendingFinalOn = mgr.setEnabled('flights', true, { origin: 'user' });
|
||||||
|
let giveUpTimer;
|
||||||
const finalOn = await Promise.race([
|
const finalOn = await Promise.race([
|
||||||
pendingFinalOn,
|
pendingFinalOn,
|
||||||
new Promise((resolve) => setTimeout(() => resolve('starved'), 2000)),
|
new Promise((resolve) => {
|
||||||
]);
|
giveUpTimer = setTimeout(() => resolve('starved'), 2000);
|
||||||
|
}),
|
||||||
|
]).finally(() => clearTimeout(giveUpTimer));
|
||||||
assert.notEqual(finalOn, 'starved', 'newest intent must not starve behind the compensation');
|
assert.notEqual(finalOn, 'starved', 'newest intent must not starve behind the compensation');
|
||||||
assert.equal(compensationAborted, true, 'the hung compensation was aborted');
|
assert.equal(compensationAborted, true, 'the hung compensation was aborted');
|
||||||
assert.equal(await pendingBlockedOn, false, 'the guard-blocked request stays unfulfilled');
|
assert.equal(await pendingBlockedOn, false, 'the guard-blocked request stays unfulfilled');
|
||||||
@@ -2451,10 +2454,13 @@ test('re-entrant setEnabled from a blocked-adoption listener supersedes the comp
|
|||||||
releaseFirstDisable();
|
releaseFirstDisable();
|
||||||
|
|
||||||
const blockedOn = await pendingBlockedOn;
|
const blockedOn = await pendingBlockedOn;
|
||||||
|
let giveUpTimer;
|
||||||
const reentrant = await Promise.race([
|
const reentrant = await Promise.race([
|
||||||
(async () => reentrantResult === null ? 'never-fired' : await reentrantResult)(),
|
(async () => reentrantResult === null ? 'never-fired' : await reentrantResult)(),
|
||||||
new Promise((resolve) => setTimeout(() => resolve('starved'), 2000)),
|
new Promise((resolve) => {
|
||||||
]);
|
giveUpTimer = setTimeout(() => resolve('starved'), 2000);
|
||||||
|
}),
|
||||||
|
]).finally(() => clearTimeout(giveUpTimer));
|
||||||
await pendingOff;
|
await pendingOff;
|
||||||
await mgr.waitForLayerSettled('flights');
|
await mgr.waitForLayerSettled('flights');
|
||||||
unsubscribe();
|
unsubscribe();
|
||||||
|
|||||||
@@ -357,10 +357,11 @@ test('WebUSB picker remains available when no authorized receiver matches', asyn
|
|||||||
|
|
||||||
/** Resolve with the promise's value, or 'timed out' after `ms`. */
|
/** Resolve with the promise's value, or 'timed out' after `ms`. */
|
||||||
function within(promise, ms = 1_000) {
|
function within(promise, ms = 1_000) {
|
||||||
return Promise.race([
|
let timer;
|
||||||
promise,
|
const timeout = new Promise((resolve) => {
|
||||||
new Promise((resolve) => setTimeout(() => resolve('timed out'), ms)),
|
timer = setTimeout(() => resolve('timed out'), ms);
|
||||||
]);
|
});
|
||||||
|
return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user