perf(test): speed up memory suites

This commit is contained in:
Peter Steinberger
2026-02-14 16:03:14 +00:00
parent a7142c6218
commit f2c56de955
5 changed files with 47 additions and 35 deletions

View File

@@ -1009,12 +1009,16 @@ describe("QmdMemoryManager", () => {
});
async function waitForCondition(check: () => boolean, timeoutMs: number): Promise<void> {
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
// Tests only need to yield the event loop a few times; real-time sleeps slow the suite down.
const maxTicks = Math.max(10, Math.min(5000, timeoutMs * 5));
for (let tick = 0; tick < maxTicks; tick += 1) {
if (check()) {
return;
}
await new Promise<void>((resolve) => setImmediate(resolve));
}
if (check()) {
return;
}
throw new Error("condition was not met in time");
}