fix(ui): сохранять BGP-сессии при частичных отказах
This commit is contained in:
1 parent
85e701960e
commit
7046808429
8 files changed
+181
-119
No files matched your search
@@ -0,0 +1,72 @@
|
||||
import { test, expect } from "@playwright/test"
|
||||
const server = (id: number) => ({ id, name: "Роутер " + id, host: "192.0.2." + id, enabled: true, country: "RU", status: null })
|
||||
const session = (serverId: number, name = "Сессия " + serverId) => ({ id: "*1", serverId, serverName: "Роутер " + serverId, serverSite: "", serverCountry: "RU", name, peerIp: "192.0.2." + serverId, remoteAs: 64513, localAs: 64512, localId: "192.0.2.100", remoteId: "192.0.2." + serverId, state: "Established", type: "eBGP", uptime: "1h", holdTime: 90, keepalive: 30, prefixesRx: 12, prefixesTx: 2, inputMessages: 20, outputMessages: 10, capabilities: [], lastError: null })
|
||||
const full = { sessions: [session(1), session(2)], failures: [] }
|
||||
for (const broken of ["http", "payload", "duplicate", "conflict", "duplicate-failure", "foreign", "inventory"]) {
|
||||
test('BGP: неизвестное начало, кэш и восстановление ' + broken, async ({ page }) => {
|
||||
let phase = 0
|
||||
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/servers") return r.fulfill({ json: phase === 2 && broken === "inventory" ? [server(1), server(1)] : [server(1), server(2)] })
|
||||
if (path === "/api/bgp/catalog") {
|
||||
if (phase === 0 || phase === 2 && broken === "http") return r.fulfill({ status: 503, json: { error: "BGP недоступен тест" } })
|
||||
const failure = { serverId: 2, serverName: "Роутер 2", error: "Таймаут тест" }
|
||||
const json = phase !== 2 ? full : broken === "payload" ? { sessions: [{}], failures: [] }
|
||||
: broken === "duplicate" ? { sessions: [session(1), session(1)], failures: [] }
|
||||
: broken === "conflict" ? { ...full, failures: [failure] }
|
||||
: broken === "duplicate-failure" ? { sessions: [], failures: [failure, failure] }
|
||||
: broken === "foreign" ? { sessions: [session(3)], failures: [] } : full
|
||||
return r.fulfill({ json })
|
||||
}
|
||||
return r.fulfill({ json: path === "/api/auth/config" ? { required: false } : {} })
|
||||
})
|
||||
await page.goto("/bgp")
|
||||
const alert = page.getByRole("alert").filter({ hasText: "Не удалось загрузить BGP" })
|
||||
await expect(alert).toContainText("Данные пока неизвестны")
|
||||
await expect(page.getByText("Нет BGP-сессий", { exact: true })).toHaveCount(0)
|
||||
await expect(page.getByLabel("Сводка BGP", { exact: true })).toContainText("неизвестно")
|
||||
phase = 1
|
||||
await alert.getByRole("button", { name: "Повторить загрузку BGP" }).click()
|
||||
const rows = page.locator("tr[data-row-id]")
|
||||
await expect(rows).toHaveCount(2)
|
||||
await expect(page.getByRole("option").filter({ hasText: "Роутер 1" })).toContainText("Статус неизвестен")
|
||||
phase = 2
|
||||
await page.getByRole("button", { name: "Обновить", exact: true }).click()
|
||||
await expect(alert).toContainText("Показаны последние полученные данные")
|
||||
await expect(rows).toHaveCount(2)
|
||||
await expect(rows.filter({ hasText: "Неизвестно" })).toHaveCount(2)
|
||||
await page.getByRole("button", { name: "Аналитика", exact: true }).click()
|
||||
await expect(page.getByRole("status").filter({ hasText: "Аналитика неизвестна" })).toBeVisible()
|
||||
phase = 3
|
||||
await alert.getByRole("button", { name: "Повторить загрузку BGP" }).click()
|
||||
await expect(alert).toHaveCount(0)
|
||||
await page.getByRole("button", { name: "Сессии", exact: true }).click()
|
||||
await expect(rows.filter({ hasText: "Неизвестно" })).toHaveCount(0)
|
||||
})
|
||||
}
|
||||
test("BGP: частичный отказ сохраняет устройство, пустой успешный опрос очищает", async ({ page }) => {
|
||||
let phase = 0
|
||||
await page.route("**/health", r => r.fulfill({ json: { ok: true } }))
|
||||
await page.route("**/api/**", r => {
|
||||
const path = new URL(r.request().url()).pathname
|
||||
return r.fulfill({ json: path === "/api/servers" ? [server(1), server(2)] : path === "/api/bgp/catalog" ? phase === 0 ? full : { sessions: [session(1, "Обновлённая сессия")], failures: phase === 1 ? [{ serverId: 2, serverName: "Роутер 2", error: "Таймаут тест" }] : [] } : path === "/api/auth/config" ? { required: false } : {} })
|
||||
})
|
||||
await page.goto("/bgp")
|
||||
const rows = page.locator("tr[data-row-id]")
|
||||
await expect(rows).toHaveCount(2)
|
||||
phase = 1
|
||||
await page.getByRole("button", { name: "Обновить", exact: true }).click()
|
||||
const alert = page.getByRole("alert").filter({ hasText: "Не удалось опросить часть роутеров BGP" })
|
||||
await expect(alert).toContainText("Роутер 2: Таймаут тест")
|
||||
await expect(rows.filter({ hasText: "Сессия 2" })).toContainText("Неизвестно")
|
||||
await expect(rows.filter({ hasText: "Обновлённая сессия" })).toContainText("Established")
|
||||
await page.getByRole("option").filter({ hasText: "Роутер 1" }).click()
|
||||
await expect(page.getByLabel("Сводка BGP", { exact: true })).not.toContainText("неизвестно")
|
||||
await page.getByRole("option").filter({ hasText: "Роутер 2" }).click()
|
||||
await expect(page.getByLabel("Сводка BGP", { exact: true })).toContainText("неизвестно")
|
||||
phase = 2
|
||||
await alert.getByRole("button", { name: "Повторить загрузку BGP" }).click()
|
||||
await expect(rows).toHaveCount(0)
|
||||
await expect(page.getByText("Нет BGP-сессий", { exact: true })).toBeVisible()
|
||||
})
|
||||
@@ -23,9 +23,9 @@ async function setup(page: Page, path: string, empty = false) {
|
||||
await page.route("**/api/**", route => {
|
||||
const path = new URL(route.request().url()).pathname
|
||||
const json = path === "/api/ospf/all" ? (empty ? { instances: [], interfaces: [], neighbors: [], routes: [], bfdSessions: [] } : ospf)
|
||||
: path === "/api/bgp/sessions" ? (empty ? [] : bgp)
|
||||
: path === "/api/bgp/catalog" ? { sessions: empty ? [] : bgp, failures: [] }
|
||||
: path === "/api/auth/config" ? { required: false }
|
||||
: path === "/api/servers" ? [] : {}
|
||||
: path === "/api/servers" ? [{ id: 1, name: "Тестовый роутер", host: "192.0.2.100", country: "RU", enabled: true, status: null }] : {}
|
||||
return route.fulfill({ json })
|
||||
})
|
||||
await page.goto(path)
|
||||
|
||||
Reference in new issue
Block a user