v2.8.1 修复测试日志重复:并发数表头只在切换并发档时打印一次;日志条数计数修正;轮询加防重叠锁

This commit is contained in:
2026-09-15 13:28:37 +08:00
parent ccfd7eb689
commit 9e457cd22e
2 changed files with 10 additions and 2 deletions
+6 -1
View File
@@ -19,6 +19,7 @@ const STATUS_LABEL = {
let currentTestId = null; // 正在跑的测试 id
let pollTimer = null;
let lastLogId = 0;
let polling = false; // 防止轮询请求重叠:上一请求未返回前不再发,避免同批日志被追加两次
let consoleLogs = []; // 当前测试已加载日志 [{id,level,msg,rel}]
// 上下文长度:chips 列表 + 启用集合(默认 512/2048/4096/8192/16384/32768/65536/131072
@@ -326,6 +327,7 @@ function appendLogs(logs) {
html += `<div class="ln ${esc(l.level)}"><span class="ts">[${l.rel.toFixed(3)}s]</span> ${esc(l.msg)}</div>`;
}
box.insertAdjacentHTML("beforeend", html);
consoleLogs.push(...logs); // 记录已加载日志,修正“日志条数”一直显示 0 条的问题
$("#log-count").textContent = `${consoleLogs.length}`;
if (atBottom) box.scrollTop = box.scrollHeight;
}
@@ -386,7 +388,8 @@ function startTest() {
}
async function pollLogs() {
if (currentTestId == null) return;
if (currentTestId == null || polling) return;
polling = true;
try {
const d = await api(`/api/tests/${currentTestId}/logs?after=${lastLogId}`);
if (d.logs && d.logs.length) {
@@ -399,6 +402,8 @@ async function pollLogs() {
}
} catch (e) {
/* 网络抖动忽略 */
} finally {
polling = false;
}
}