fix(ui): использовать серверное время и не подменять отсутствующий Ping

This commit is contained in:
Denozordec committed 2026-10-07 17:52:33 +07:00
1 parent 7f18fcb6db
commit 30cc99c68e
9 files changed
+60 -11

No files matched your search

+2 -2
View File
@@ -6,7 +6,7 @@ import { createSpeedTestRoute } from "./speed-test.js"
import { SpeedProbeEndpointsChanged, SpeedProbeContextChanged } from "../services/speed-run-persistence.js"
const commands: SpeedTestCommand[] = [], failures: Array<SpeedTestCommand & { message: string }> = []
let lookups = 0, missing = false, problem: Error | null = null
const result = (c: SpeedTestCommand) => ({ runId: c.runId ?? "ad-hoc", srcInterface: c.srcInterface || null, dstInterface: c.dstInterface || null, address: "192.0.2.2", srcAddress: "192.0.2.1", dstAddress: "192.0.2.2", srcInterfaceAddress: null, dstInterfaceAddress: null, protocol: c.protocol, direction: c.direction, durationSec: c.durationSec, txAvgMbps: null, rxAvgMbps: 0, txSeries: [], rxSeries: [0], raw: [{ status: "done testing" }], afterBtPing: { rttMs: null, lossPct: null, error: null } })
const result = (c: SpeedTestCommand) => ({ createdAt: "2026-10-07T00:00:00Z", runId: c.runId ?? "ad-hoc", srcInterface: c.srcInterface || null, dstInterface: c.dstInterface || null, address: "192.0.2.2", srcAddress: "192.0.2.1", dstAddress: "192.0.2.2", srcInterfaceAddress: null, dstInterfaceAddress: null, protocol: c.protocol, direction: c.direction, durationSec: c.durationSec, txAvgMbps: null, rxAvgMbps: 0, txSeries: [], rxSeries: [0], raw: [{ status: "done testing" }], afterBtPing: { rttMs: null, lossPct: null, error: null } })
const deps = {
serverExists: async (_id: number) => { lookups++; return !missing },
run: async (c: SpeedTestCommand) => { commands.push(c); if (problem) throw problem; return result(c) },
@@ -19,7 +19,7 @@ const bad = [null, [], {}, { ...base, srcServerId: "1junk" }, { ...base, srcServ
for (const body of bad) assert.equal((await send(body)).statusCode, 400, JSON.stringify(body))
assert.equal(lookups, 0); assert.equal(commands.length, 0); assert.equal(failures.length, 0)
assert.equal(speedTestCommandSchema.safeParse({ ...base, durationSec: Infinity }).success, false)
const first = await send(base); assert.equal(first.statusCode, 200); assert.equal(first.json().result.txAvgMbps, null); assert.equal(first.json().result.rxAvgMbps, 0)
const first = await send(base); assert.equal(first.statusCode, 200); assert.equal(first.json().result.txAvgMbps, null); assert.equal(first.json().result.rxAvgMbps, 0); assert.equal(first.json().result.createdAt, "2026-10-07T00:00:00Z")
assert.deepEqual(commands[0], { ...base, srcInterface: "", dstInterface: "", protocol: "tcp", direction: "both", durationSec: 10 })
const explicit = await send({ srcServerId: "1", dstServerId: "2", runId: " run-2 ", probeId: " probe ", srcInterface: " ether1 ", protocol: "udp", direction: "receive", durationSec: "3", lastTxAvgMbps: 999 })
assert.equal(explicit.statusCode, 200); assert.equal(commands[1].runId, "run-2"); assert.equal(commands[1].probeId, "probe"); assert.equal(commands[1].srcInterface, "ether1"); assert.equal(commands[1].protocol, "udp"); assert.equal(commands[1].direction, "receive"); assert.equal(commands[1].durationSec, 3); assert.equal("lastTxAvgMbps" in commands[1], false)
@@ -49,6 +49,7 @@ export interface SpeedTestRunParams {
}
export interface SpeedTestRunResult {
createdAt: string
runId: string
srcInterface: string | null
dstInterface: string | null
@@ -186,6 +187,7 @@ export async function executeBandwidthSpeedTestInner(params: SpeedTestRunParams)
})
return {
createdAt: pingNow,
runId,
srcInterface: srcInterface || null,
dstInterface: dstInterface || null,