42 lines
3.4 KiB
TypeScript
42 lines
3.4 KiB
TypeScript
import {test,expect} from "@playwright/test"
|
|
import {writeFileSync} from "node:fs"
|
|
import {optimizerServersSchema,optimizerProbesSchema} from "../../lib/route-optimizer-response"
|
|
|
|
for(const poolCount of [20,1000])test(`Оптимизатор7WAN: ранжирование ${poolCount} проб по свежести`,async({page},info)=>{
|
|
test.setTimeout(90000)
|
|
const at=Date.now()
|
|
const probes=optimizerProbesSchema.parse({probes:Array.from({length:poolCount},(_,i)=>({id:`p${i}`,srcServerId:"1",dstServerId:"2",srcInterface:"",dstInterface:"",enabled:true,lastPingRttMs:10,lastPingLossPct:0,lastTxAvgMbps:100,lastRxAvgMbps:100,lastPingAt:new Date(at-(poolCount-i)*3600000).toISOString()}))})
|
|
const common = { host: "192.0.2.1", enabled: true, status: "online", latency: 10, country: "RU", site: "TEST", model: "CHR" }
|
|
const servers = optimizerServersSchema.parse([
|
|
{ ...common, id: 1, name: "Домашний роутер", type: "home-router", wanUplinks: Array.from({ length: 7 }, (_, i) => ({ id: `wan${i+1}`, name: `WAN${i+1}`, isp: "ISP", iface: `ether${i+1}`, ip: `198.51.100.${i+1}`, maxDl: 100, maxUl: 100 })) },
|
|
...Array.from({ length: 1 }, (_, i) => ({ ...common, id: i+2, name: `Jump ${i+1}`, type: "jump-host" })),
|
|
])
|
|
|
|
|
|
let reads=0
|
|
const writes: string[] = []
|
|
await page.route("**/health", r => r.fulfill({ json: { ok: true } }))
|
|
await page.route("**/api/**", r => {
|
|
const path = new URL(r.request().url()).pathname
|
|
if(path==="/api/uptime/speed-probes")reads++
|
|
|
|
|
|
if (r.request().method() !== "GET" && !path.endsWith("/preview")) writes.push(path)
|
|
return r.fulfill({ json: path === "/api/auth/config" ? { required: false } : path === "/api/servers" ? servers : path === "/api/filters/rules" ? {rulesets:[]} : path === "/api/uptime/speed-probes" ? probes : path === "/api/ospf/catalog" ? { interfaces: [], instances: [], neighbors: [], bfdSessions: [], routes: [], failures: [] } : path.endsWith("/ospf/optimize/preview") ? { serverId: 1, serverName: "Домашний роутер", pingWeight: 60, interfacesTotal: 0, changedCount: 0, unchangedCount: 0, interfaces: [], changes: [] } : {} })
|
|
})
|
|
|
|
|
|
|
|
const started=Date.now();await page.goto("/route-optimizer?server=1&keep=1")
|
|
const table=page.getByRole("table").filter({hasText:"WAN-аплинк"}),rows=table.locator("tr[data-row-id]")
|
|
await expect(rows).toHaveCount(7)
|
|
await expect(page.getByRole("region",{name:"Матрица WAN и Jump Host"})).toContainText("Скорость — снимок пары устройств")
|
|
for(let i=0;i<7;i++)await expect(rows.nth(i).locator("time")).toHaveAttribute("datetime",probes.probes[poolCount-7+i].lastPingAt!)
|
|
const profile={poolCount,wanCount:7,probeBytes:Buffer.byteLength(JSON.stringify(probes)),rendered:await rows.count(),tableNodes:await table.locator("*").count(),readyMs:Date.now()-started}
|
|
console.log("Optimizer probes",JSON.stringify(profile));writeFileSync(info.outputPath("probes-profile.json"),JSON.stringify(profile,null,2))
|
|
const before=reads;await page.getByRole("button",{name:"Обновить",exact:true}).click();await expect.poll(()=>reads).toBeGreaterThan(before)
|
|
for(let i=0;i<7;i++)await expect(rows.nth(i).locator("time")).toHaveAttribute("datetime",probes.probes[poolCount-7+i].lastPingAt!)
|
|
await page.setViewportSize({width:320,height:1000});expect(await page.evaluate(()=>document.documentElement.scrollWidth)).toBeLessThanOrEqual(320)
|
|
expect(writes).toEqual([])
|
|
})
|