fix(ui): проверять данные VXLAN и гонки загрузки

This commit is contained in:
Denozordec committed 2026-09-30 09:47:51 +07:00
1 parent e163a9ed9d
commit 14be83a869
6 files changed
+103 -13

No files matched your search

+55 -1
View File
@@ -1,7 +1,7 @@
import { test, expect, type Page } from "@playwright/test"
async function setup(page: Page, url: string, failed = 0) {
const control = { malformed: false, partial: false, failed, posts: [] as { path: string; body: unknown }[] }
const control = { payload: undefined as unknown, malformed: false, partial: false, failed, posts: [] as { path: string; body: unknown }[] }
const servers = [{ id: 1, name: "Источник", host: "192.0.2.1", type: "exit-node", enabled: true, country: "RU", site: "TEST", asn: "64512", status: "online", latency: 1, os: "7", model: "CHR", wanUplinks: [] }]
const tunnels = ["1", "2"].flatMap(serverId => ["*/2", "other"].map(id => ({ id, serverId, name: "vx-same", vni: Number(serverId) * 100 + (id === "other" ? 1 : 0), port: 0, dstPort: 8472, vtepIp: "192.0.2.1", remoteVteps: ["192.0.2.22"], l2mtu: 1500, arpProxy: false, macLearning: true, comment: "", enabled: true, status: "down" })))
servers.push({ ...servers[0], id: 2, name: "Второй сервер", host: "192.0.2.2" });
@@ -11,6 +11,7 @@ async function setup(page: Page, url: string, failed = 0) {
const request = route.request()
const path = new URL(request.url()).pathname
if (!["GET", "HEAD"].includes(request.method())) control.posts.push({ path, body: request.postDataJSON() })
if (path === "/api/vxlan" && control.payload !== undefined) return route.fulfill({ json: control.payload })
if (path === "/api/vxlan" && control.failed) return route.fulfill({ status: control.failed, json: { error: "Мониторинг недоступен" } })
if (path === "/api/vxlan" && control.malformed) return route.fulfill({ json: {} })
const json = path === "/api/auth/config" ? { required: false }
@@ -158,3 +159,56 @@ test("VXLAN: первый частичный сбой не выглядит пу
await expect(page.getByText("На опрошенных серверах нет VXLAN-интерфейсов", { exact: true })).toHaveCount(0)
await expect(page.getByLabel("Сводка VXLAN")).toContainText("—")
})
test("VXLAN: повреждённые записи не заменяют последний список", async ({ page }) => {
const control = await setup(page, "/vxlan")
const rows = page.locator("tr[data-row-id]")
await expect(rows).toHaveCount(4)
const valid = { id: "id", serverId: "1", name: "vx", vni: 1, port: 0, dstPort: 8472, vtepIp: "", remoteVteps: [], l2mtu: 1500, arpProxy: false, macLearning: true, comment: "", enabled: true, status: "up" }
for (const payload of [
{ tunnels: [{ ...valid, remoteVteps: null }] },
{ tunnels: [{ ...valid, vni: 16777216 }] },
{ tunnels: [{ ...valid, status: "unknown" }] },
{ tunnels: [valid, valid] },
{ tunnels: [], failures: [{ serverId: "1", error: null }] },
]) {
control.payload = payload
await page.getByRole("button", { name: "Обновить", exact: true }).click()
await expect(page.getByText("Ошибка загрузки: Некорректный ответ загрузки VXLAN", { exact: true })).toBeVisible()
await expect(rows).toHaveCount(4)
}
control.payload = undefined
await page.getByRole("button", { name: "Обновить", exact: true }).click()
await expect(page.getByText("Ошибка загрузки:", { exact: false })).toHaveCount(0)
})
for (const oldFails of [false, true]) {
test(`VXLAN: поздний ответ старого устройства игнорируется ${oldFails}`, async ({ page }) => {
await setup(page, "/vxlan?server=1")
await expect(page.locator("tr[data-row-id]")).toHaveCount(2)
let oldRelease: (() => void) | undefined
let newRelease: (() => void) | undefined
const oldGate = new Promise<void>(resolve => { oldRelease = resolve })
const newGate = new Promise<void>(resolve => { newRelease = resolve })
let attempts = 0
await page.route("**/api/vxlan", async route => {
attempts++
if (attempts === 1) { await oldGate; return route.fulfill(oldFails ? { status: 500, json: { error: "Поздняя ошибка тест" } } : { json: { tunnels: [] } }) }
await newGate
return route.fallback()
})
await page.getByRole("button", { name: "Обновить", exact: true }).click()
await expect.poll(() => attempts).toBe(1)
await page.getByRole("option").filter({ hasText: "Второй сервер" }).click()
await expect.poll(() => attempts).toBeGreaterThanOrEqual(2)
const response = page.waitForResponse(r => r.url().endsWith("/api/vxlan"))
oldRelease!()
await (await response).finished()
await page.waitForTimeout(100)
await expect(page.getByRole("button", { name: "Обновить", exact: true })).toBeDisabled()
await expect(page.getByText("Ошибка загрузки:", { exact: false })).toHaveCount(0)
newRelease!()
await expect(page.locator("tr[data-row-id]")).toHaveCount(2)
await expect(page).toHaveURL(/server=2/)
})
}