Test: harden the E2E smoke script against hangs and hidden crashes
A crash inside the client-online wait was swallowed by Wait-Until's empty catch, so a dead server or client surfaced only as "no host online after 60s" once the timeout expired. Record the failure reason and report it right after the wait. LVM_GETITEMCOUNT and LVM_GETITEMSTATE used SendMessage without a timeout. A hung server UI thread - the exact regression this script exists to catch - would block the script forever instead of failing. Send with SendMessageTimeout (2s) and treat a timeout as a failure. -Build ran after settings.ini had been temporarily rewritten for busy MCP/Web ports, so a build failure left the file modified. Build before touching settings and restore unconditionally in a catch block. Verified by re-running the Search feature end to end. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
ae46b7b53b
commit
be19744898
1 file changed
+47
-14
+47
-14
@@ -61,6 +61,9 @@ public static class E2E
|
|||||||
[DllImport("user32.dll")] static extern bool IsWindowVisible(IntPtr h);
|
[DllImport("user32.dll")] static extern bool IsWindowVisible(IntPtr h);
|
||||||
[DllImport("user32.dll")] public static extern bool IsWindow(IntPtr h);
|
[DllImport("user32.dll")] public static extern bool IsWindow(IntPtr h);
|
||||||
[DllImport("user32.dll")] static extern IntPtr SendMessage(IntPtr h, uint m, IntPtr w, IntPtr l);
|
[DllImport("user32.dll")] static extern IntPtr SendMessage(IntPtr h, uint m, IntPtr w, IntPtr l);
|
||||||
|
// 带超时的 SendMessage:目标 UI 线程卡死时不能把测试脚本一起挂死(这正是要抓的回归)。
|
||||||
|
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
|
||||||
|
static extern IntPtr SendMessageTimeout(IntPtr h, uint m, IntPtr w, IntPtr l, uint flags, uint timeout, out IntPtr result);
|
||||||
[DllImport("user32.dll")] public static extern bool PostMessage(IntPtr h, uint m, IntPtr w, IntPtr l);
|
[DllImport("user32.dll")] public static extern bool PostMessage(IntPtr h, uint m, IntPtr w, IntPtr l);
|
||||||
[DllImport("user32.dll")] static extern int GetDlgCtrlID(IntPtr h);
|
[DllImport("user32.dll")] static extern int GetDlgCtrlID(IntPtr h);
|
||||||
[DllImport("user32.dll")] static extern IntPtr GetMenu(IntPtr h);
|
[DllImport("user32.dll")] static extern IntPtr GetMenu(IntPtr h);
|
||||||
@@ -146,9 +149,14 @@ public static class E2E
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>跨进程发整型消息;目标 UI 线程 2 秒无响应时返回 -1(调用方据此判失败)。</summary>
|
||||||
public static int SendInt(IntPtr h, uint msg, int w, int l)
|
public static int SendInt(IntPtr h, uint msg, int w, int l)
|
||||||
{
|
{
|
||||||
return (int)SendMessage(h, msg, (IntPtr)w, (IntPtr)l);
|
const uint SMTO_ABORTIFHUNG = 0x0002;
|
||||||
|
IntPtr result;
|
||||||
|
IntPtr ok = SendMessageTimeout(h, msg, (IntPtr)w, (IntPtr)l, SMTO_ABORTIFHUNG, 2000, out result);
|
||||||
|
if (ok == IntPtr.Zero) return -1; // 超时/目标线程不响应
|
||||||
|
return (int)result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void PostCommand(IntPtr main, int id)
|
public static void PostCommand(IntPtr main, int id)
|
||||||
@@ -204,6 +212,15 @@ if ($running.Count -gt 0) {
|
|||||||
}
|
}
|
||||||
if (-not (Test-Path $ServerExe)) { throw "找不到 Debug 服务端: $ServerExe(可加 -Build 先编译)" }
|
if (-not (Test-Path $ServerExe)) { throw "找不到 Debug 服务端: $ServerExe(可加 -Build 先编译)" }
|
||||||
if ($ExternalClient -and -not (Test-Path $ClientExe)) { throw "找不到 Debug 客户端: $ClientExe" }
|
if ($ExternalClient -and -not (Test-Path $ClientExe)) { throw "找不到 Debug 客户端: $ClientExe" }
|
||||||
|
if ($Build) {
|
||||||
|
Write-Host "==> 编译 Debug 服务端/客户端 ..." -ForegroundColor Cyan
|
||||||
|
# 每次编译后单独检查退出码:只在第二次编译后查会让"服务端编译失败、客户端成功"
|
||||||
|
# 被 $LASTEXITCODE=0 掩盖,后面用旧二进制跑出一堆假 PASS/FAIL。
|
||||||
|
& powershell -NoProfile -File (Join-Path $repo 'build.ps1') -Config Debug -Platform x64 | Out-Null
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw "Debug 服务端编译失败(退出码 $LASTEXITCODE)" }
|
||||||
|
& powershell -NoProfile -File (Join-Path $repo 'build.ps1') -Config Debug -Platform x64 -ClientOnly | Out-Null
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw "Debug 客户端编译失败(退出码 $LASTEXITCODE)" }
|
||||||
|
}
|
||||||
|
|
||||||
# 端口检查:6543 是客户端必须能连上的端口,被占用就直接失败。
|
# 端口检查:6543 是客户端必须能连上的端口,被占用就直接失败。
|
||||||
# MCP/Web 端口(settings.ini 的 McpPort/WebSvrPort)如果已被别的实例占用(例如正在跑的
|
# MCP/Web 端口(settings.ini 的 McpPort/WebSvrPort)如果已被别的实例占用(例如正在跑的
|
||||||
@@ -230,6 +247,7 @@ try { $udp = @(Get-NetUDPEndpoint -ErrorAction Stop | Select-Object -ExpandPrope
|
|||||||
if (($ports -contains 6543) -or ($udp -contains 6543)) {
|
if (($ports -contains 6543) -or ($udp -contains 6543)) {
|
||||||
throw "端口 6543 已被占用,无法启动隔离的 Debug 测试实例。"
|
throw "端口 6543 已被占用,无法启动隔离的 Debug 测试实例。"
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
if ($settingsBackup -ne $null) {
|
if ($settingsBackup -ne $null) {
|
||||||
$cfg = $settingsBackup
|
$cfg = $settingsBackup
|
||||||
if (($ports -contains 6545) -or ($udp -contains 6545)) {
|
if (($ports -contains 6545) -or ($udp -contains 6545)) {
|
||||||
@@ -244,13 +262,8 @@ if ($settingsBackup -ne $null) {
|
|||||||
[System.IO.File]::WriteAllText($settingsPath, $cfg, [System.Text.Encoding]::Default)
|
[System.IO.File]::WriteAllText($settingsPath, $cfg, [System.Text.Encoding]::Default)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch { Restore-Settings; throw }
|
||||||
|
|
||||||
if ($Build) {
|
|
||||||
Write-Host "==> 编译 Debug 服务端/客户端 ..." -ForegroundColor Cyan
|
|
||||||
& powershell -NoProfile -File (Join-Path $repo 'build.ps1') -Config Debug -Platform x64 | Out-Null
|
|
||||||
& powershell -NoProfile -File (Join-Path $repo 'build.ps1') -Config Debug -Platform x64 -ClientOnly | Out-Null
|
|
||||||
if ($LASTEXITCODE -ne 0) { throw "编译失败(退出码 $LASTEXITCODE)" }
|
|
||||||
}
|
|
||||||
|
|
||||||
$server = $null
|
$server = $null
|
||||||
$client = $null
|
$client = $null
|
||||||
@@ -298,12 +311,30 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$count = 0
|
$count = 0
|
||||||
$ok = Wait-Until {
|
# 这里不用 Wait-Until:它无法提前退出(进程死了还要空等满超时),也无法区分
|
||||||
if ($script:server.HasExited) { throw '服务端进程已退出(客户端崩溃或被安全软件拦截)' }
|
# "单次 UI 忙" 与 "持续无响应"。手写循环:
|
||||||
if ($ExternalClient -and $script:client.HasExited) { throw '外部客户端进程已退出' }
|
# · 进程一退出立刻失败;
|
||||||
$script:count = [E2E]::SendInt($script:list, $LVM_GETITEMCOUNT, 0, 0)
|
# · $uiHung 只在最近一次请求超时时为真,下一次成功即清零(粘性标志会把启动
|
||||||
return ($script:count -ge 1)
|
# 瞬间的忙误报成界面死锁)。
|
||||||
} $ClientOnlineTimeoutSec
|
$dead = $null
|
||||||
|
$uiHung = $false
|
||||||
|
$ok = $false
|
||||||
|
$deadline = (Get-Date).AddSeconds($ClientOnlineTimeoutSec)
|
||||||
|
while ((Get-Date) -lt $deadline) {
|
||||||
|
if ($server.HasExited) { $dead = '服务端进程已退出(客户端崩溃或被安全软件拦截)'; break }
|
||||||
|
if ($ExternalClient -and $client.HasExited) { $dead = '外部客户端进程已退出'; break }
|
||||||
|
$c = [E2E]::SendInt($list, $LVM_GETITEMCOUNT, 0, 0)
|
||||||
|
if ($c -lt 0) {
|
||||||
|
$uiHung = $true
|
||||||
|
} else {
|
||||||
|
$uiHung = $false
|
||||||
|
$count = $c
|
||||||
|
if ($c -ge 1) { $ok = $true; break }
|
||||||
|
}
|
||||||
|
Start-Sleep -Milliseconds 250
|
||||||
|
}
|
||||||
|
if (-not $ok -and $dead) { throw $dead }
|
||||||
|
if (-not $ok -and $uiHung) { throw '服务端 UI 线程 2 秒无响应(LVM_GETITEMCOUNT 超时),可能是界面死锁' }
|
||||||
if (-not $ok) {
|
if (-not $ok) {
|
||||||
# 内置客户端失败时通常会弹一个消息框(例如内核 DLL 未就绪),把它的文字打出来。
|
# 内置客户端失败时通常会弹一个消息框(例如内核 DLL 未就绪),把它的文字打出来。
|
||||||
$diag = @([E2E]::TopDialogs($server.Id, $main) | ForEach-Object { [E2E]::Text($_) } | Where-Object { $_ })
|
$diag = @([E2E]::TopDialogs($server.Id, $main) | ForEach-Object { [E2E]::Text($_) } | Where-Object { $_ })
|
||||||
@@ -314,7 +345,9 @@ try {
|
|||||||
# 选中第一行;列表项需要先选中,工具栏命令才会对这台主机下发。
|
# 选中第一行;列表项需要先选中,工具栏命令才会对这台主机下发。
|
||||||
[E2E]::Click($list, 40, 40)
|
[E2E]::Click($list, 40, 40)
|
||||||
$selected = Wait-Until {
|
$selected = Wait-Until {
|
||||||
return ([E2E]::SendInt($script:list, $LVM_GETITEMSTATE, 0, $LVIS_SELECTED) -ne 0)
|
$st = [E2E]::SendInt($script:list, $LVM_GETITEMSTATE, 0, $LVIS_SELECTED)
|
||||||
|
if ($st -lt 0) { return $false } # SendMessage 超时
|
||||||
|
return (($st -band $LVIS_SELECTED) -ne 0)
|
||||||
} 5
|
} 5
|
||||||
if (-not $selected) { throw "在线列表第 1 行没有被选中(点击坐标/列表布局可能变了)" }
|
if (-not $selected) { throw "在线列表第 1 行没有被选中(点击坐标/列表布局可能变了)" }
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user