Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : KA Maps Engine8 * File : sdk/web/tests/e2e/soak.spec.ts9 * Module : sdk10 * Repository : https://git.spboucher.ai/ka-maps-engine11 * Created : 2026-12-0112 * Last Modified : 2026-12-0113 *14 * Author : Simon-Pierre Boucher15 * Position : Professor of Finance16 * Institution : Université du Québec en Outaouais (UQO)17 * Organization : SP Boucher18 * Website : https://spboucher.ai19 * Git : https://git.spboucher.ai20 *21 * Preferred Contact: support@spboucher.ai22 * Development : dev@spboucher.ai23 * Support : support@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Endurance mémoire (@soak) : plusieurs minutes de mouvements de caméra scriptés — vols entre trois43// régions, zooms, bascules 2D/3D, changements de thème, couches ajoutées et retirées — puis44// vérification que le tas JavaScript et la mémoire du moteur plafonnent.45//46// Les budgets mémoire du moteur sont abaissés (KA_SOAK_BUDGET_MB, 96 Mo de tuiles et 16 Mo de sources par47// défaut ; `0` garde ceux du moteur : 384 Mo et 64 Mo) pour que le régime établi soit atteint pendant48// l'essai : avec les budgets d'origine, la mémoire monte encore légitimement après 8 minutes (les caches49// ne sont pas pleins) et l'essai ne peut pas distinguer un cache qui se remplit d'une fuite.50//51// KA_SOAK=1 npx playwright test (3 minutes par navigateur)52// KA_SOAK=1 KA_SOAK_MINUTES=6 npx playwright test --project=chromium-webgpu53import { expect, test } from '@playwright/test';54import { mkdirSync, writeFileSync } from 'node:fs';55import { openDemo, settle } from './helpers.js';5657const MINUTES = Number(process.env.KA_SOAK_MINUTES ?? 3);58const BUDGET_MB = Number(process.env.KA_SOAK_BUDGET_MB ?? 96);5960test(`@soak mémoire : ${MINUTES} min de mouvements, le tas JS et la mémoire wasm plafonnent`, async ({ page }, testInfo) => {61 test.setTimeout((MINUTES + 3) * 60_000);62 const problems = await openDemo(page, testInfo, { layers: 'markers', reduced: 0 });63 await settle(page);64 if (BUDGET_MB > 0) await page.evaluate((mb) => window.kaMap!.setMemoryBudget({ tiles: mb * 1048576, sources: (mb / 6) * 1048576 }), BUDGET_MB);6566 // Scénario : une étape toutes les 2,5 s.67 await page.evaluate(() => {68 const m = window.kaMap!;69 const places: [number, number, number][] = [70 [-73.5674, 45.5019, 14.5],71 [-73.62, 45.53, 13],72 [-71.208, 46.8139, 14.5],73 [-71.25, 46.83, 12],74 [-71.9, 48.5, 11],75 [-72.2, 48.4, 9],76 [-73.75, 45.57, 15.5],77 [-73.55, 45.51, 16.5],78 ];79 const themes = ['signature', 'midnight', 'minimal', 'terrain', 'financial', 'blueprint', 'city3d'];80 const brands = [null, 'louka', 'immoka', 'vraiprix', 'valoplex'] as const;81 let step = 0;82 (window as any).__soakSteps = 0;83 (window as any).__soak = setInterval(() => {84 if (m.isDestroyed) return;85 step++;86 (window as any).__soakSteps = step;87 const p = places[step % places.length];88 try {89 if (step % 4 === 0) m.jumpTo({ center: [p[0], p[1]], zoom: p[2] });90 else m.flyTo({ center: [p[0], p[1]], zoom: p[2], bearing: (step * 37) % 360, pitch: step % 3 === 0 ? 55 : 0 }, { duration: 2200 });91 if (step % 6 === 0) m.setMode(step % 12 === 0 ? '3d' : '2d');92 if (step % 9 === 0) void m.setTheme(themes[(step / 9) % themes.length]);93 if (step % 11 === 0) m.setBrand(brands[(step / 11) % brands.length]);94 if (step % 5 === 0) {95 const name = window.kaDemo.layerNames[(step / 5) % window.kaDemo.layerNames.length];96 window.kaDemo.setLayer(name, !m.hasLayer(name));97 }98 } catch (e) {99 (window as any).__soakError = String(e);100 }101 }, 2500);102 });103104 const samples: { t: number; wasmMb: number; liveMb: number; jsHeapMb: number | null; gpuMb: number; tiles: number; evicted: number; steps: number }[] = [];105 const t0 = Date.now();106 while (Date.now() - t0 < MINUTES * 60_000) {107 await page.waitForTimeout(5000);108 const s = await page.evaluate(() => {109 (window as any).gc?.();110 const st = window.kaMap!.getStats();111 const p = window.kaMap!.getPerf();112 return { wasm: st.wasmMemoryBytes, live: st.wasmLiveBytes, heap: st.jsHeapBytes, gpu: p.memory, tiles: p.tiles, evicted: p.tilesEvicted ?? 0, steps: (window as any).__soakSteps as number, err: (window as any).__soakError as string | undefined };113 });114 expect(s.err).toBeUndefined();115 samples.push({ t: Math.round((Date.now() - t0) / 1000), wasmMb: +(s.wasm / 1048576).toFixed(1), liveMb: +(s.live / 1048576).toFixed(1), jsHeapMb: s.heap ? +(s.heap / 1048576).toFixed(1) : null, gpuMb: +(s.gpu / 1048576).toFixed(1), tiles: s.tiles, evicted: s.evicted, steps: s.steps });116 }117 await page.evaluate(() => clearInterval((window as any).__soak));118 await page.evaluate(() => window.kaMap!.stop());119120 // Pente de la mémoire wasm sur le dernier tiers (Mo par minute) : ce qui distingue un plateau d'une fuite lente.121 const lastThird = samples.slice(Math.floor((samples.length * 2) / 3));122 const slope = lastThird.length > 1 ? ((lastThird[lastThird.length - 1].wasmMb - lastThird[0].wasmMb) * 60) / (lastThird[lastThird.length - 1].t - lastThird[0].t) : 0;123 const median = (a: number, b: number) => {124 const v = samples.slice(a, b).map((s) => s.liveMb).sort((x, y) => x - y);125 return v.length ? v[Math.floor(v.length / 2)] : 0;126 };127 const third = Math.floor(samples.length / 3);128 const seg = (a: number, b: number, k: 'wasmMb' | 'liveMb' | 'jsHeapMb' | 'gpuMb') => Math.max(...samples.slice(a, b).map((s) => (s[k] ?? 0) as number));129 const summary = {130 project: testInfo.project.name,131 minutes: MINUTES,132 steps: samples[samples.length - 1].steps,133 wasm: { first: samples[0].wasmMb, midMax: seg(third, 2 * third, 'wasmMb'), lastMax: seg(2 * third, samples.length, 'wasmMb'), lastThirdSlopeMbPerMin: +slope.toFixed(2) },134 // Octets vivants du moteur : maximum par tiers (la mesure d'une fuite ; la mémoire linéaire, elle, ne redescend jamais).135 budgetMb: BUDGET_MB,136 wasmLive: {137 firstMax: seg(0, third, 'liveMb'),138 midMax: seg(third, 2 * third, 'liveMb'),139 lastMax: seg(2 * third, samples.length, 'liveMb'),140 firstMedian: median(0, third),141 midMedian: median(third, 2 * third),142 lastMedian: median(2 * third, samples.length),143 last: samples[samples.length - 1].liveMb,144 },145 jsHeap: samples[0].jsHeapMb === null ? null : { first: samples[0].jsHeapMb, midMax: seg(third, 2 * third, 'jsHeapMb'), lastMax: seg(2 * third, samples.length, 'jsHeapMb') },146 gpuEstimate: { midMax: seg(third, 2 * third, 'gpuMb'), lastMax: seg(2 * third, samples.length, 'gpuMb') },147 tilesEvicted: samples[samples.length - 1].evicted,148 samples,149 };150 mkdirSync('test-results/soak', { recursive: true });151 writeFileSync(`test-results/soak/${testInfo.project.name}.json`, JSON.stringify(summary, null, 2));152 console.log(`SOAK ${JSON.stringify({ ...summary, samples: undefined })}`);153154 // La carte vit encore et dessine.155 expect(await page.evaluate(() => window.kaMap!.getPerf().tiles)).toBeGreaterThan(0);156 expect(problems.errors.filter((e) => /pageerror|panique|RuntimeError|unreachable/i.test(e))).toEqual([]);157 // Plateau des octets vivants du moteur : la médiane du dernier tiers ne dépasse pas celle du tiers médian de plus158 // de 10 % (la médiane ignore les pics passagers d'un chargement). La mémoire linéaire, qui ne rétrécit jamais,159 // est relevée et publiée avec une marge plus large (20 %).160 expect(summary.wasmLive.lastMedian).toBeLessThanOrEqual(summary.wasmLive.midMedian * 1.1 + 2);161 expect(summary.wasm.lastMax).toBeLessThanOrEqual(summary.wasm.midMax * 1.2 + 1);162 if (summary.jsHeap) expect(summary.jsHeap.lastMax).toBeLessThanOrEqual(summary.jsHeap.midMax * 1.25 + 4);163 expect(summary.gpuEstimate.lastMax).toBeLessThanOrEqual(summary.gpuEstimate.midMax * 1.25 + 16);164});165