Skip to content

测试:拿住 copy helper 的句柄再读退出码(修 CI 上常挂的诊断测试) - #88

Merged
qiyinxi merged 1 commit into
ModAVD:mainfrom
qiyinxi:fix/crash-helper-test-exitcode
Nov 6, 2026
Merged

qiyinxi merged 1 commit into
ModAVD:mainfrom
qiyinxi:fix/crash-helper-test-exitcode

Conversation

@qiyinxi

@qiyinxi qiyinxi commented Nov 6, 2026

Copy link
Copy Markdown
Member

internal/emu 的 TestDiagnosticCrashHelperSurvivesShortLauncher 在 CI 的 Windows checks 上经常挂,报 copy helper exit = 0/false。#87 的 CI 连跑三次,三次都挂在它上面。本机原样跑 10 次挂 5 次。这是测试本身的问题,产品代码没有错。

原因:win.Process.ExitCode 的注释写明,进程退出以后,只有还有句柄开着,退出码才留得住。这个测试里的 copy helper 是从进程表里找出来的,测试自己没有开它的句柄。helper.Wait 返回时,它临时开的那个句柄也关了。没有别的进程替它开着句柄时(比如干净的 CI 机器),读退出码就拿到 0/false。本机有时能过,是因为碰巧有别的进程开着这个句柄。

改法:找到 helper、确认它活着以后,测试自己用 OpenProcess(SYNCHRONIZE | PROCESS_QUERY_INFORMATION)开一个句柄,测完再关。这样退出码一定读得到,后面的断言一条没改。

测试

  • 改之前:本机连跑 10 次,挂 5 次。改之后:连跑 10 次,全过。
  • go test ./internal/emu/ 全过;windows、darwin/arm64、linux/amd64 的 go vet ./internal/emu/ 都过;gofmt -l 没有输出;scripts/privacy.py 0 失败。

另外 TestCollectBootDiagTotal(按 200 ms 计时的那条)在 CI 上也偶尔挂一次,原因不同,这个 PR 没碰它。

Refs ModAVD/ModAVD#97

TestDiagnosticCrashHelperSurvivesShortLauncher 的 helper 是从进程表里找到的,测试自己不开它的句柄;没有别的进程开着句柄时,它退出以后退出码就读不到(copy helper exit = 0/false),CI 上经常挂,本机 10 次挂 5 次。找到 helper 以后先开一个句柄,测完再关。

Refs ModAVD/ModAVD#97
@qiyinxi
qiyinxi merged commit 62addfd into ModAVD:main Nov 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant