Skip to content

fix(macOS): 根治测试同步阻塞导致的 CI 超时 - #284

Merged
1lck merged 7 commits into
previewfrom
codex/fix-macos-test-blocking-waits
Aug 28, 2026
Merged

fix(macOS): 根治测试同步阻塞导致的 CI 超时#284
1lck merged 7 commits into
previewfrom
codex/fix-macos-test-blocking-waits

Conversation

@xiaoyumuxi

@xiaoyumuxi xiaoyumuxi commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

问题

macOS 测试与进程适配层存在多种会放大为 CI 卡死的同步边界:

  • 同步协议测试替身通过无限 semaphore 等待,并由 Task.detached 承载,可能占满 Swift cooperative executor。
  • Git fixture 使用同步进程等待;失败或取消时可能留下子进程。
  • macOS 同步进程 runner 超时后只发送 SIGTERM,随后仍可能无限等待忽略信号的子进程。
  • 大标准输入可能在子进程不读取时阻塞;超时关闭管道还可能触发 SIGPIPE,直接终止测试进程。
  • 主进程退出后,继承输出管道的后代进程可能使 EOF 永远不到达。

修改内容

测试同步与任务调度

  • 将受阻塞替身覆盖的同步协议调用转移到 GCD worker,保留原有取消和 stale-result 检查,不修改业务状态机。
  • 新增带截止时间的一次性 TestGate,相关测试通过 defer 保证释放。
  • Search 索引同步端口改由 GCD worker 执行,两个测试 gate 改为 5 秒有界等待。

macOS 进程生命周期

  • Git fixture 改用异步 TestProcess,支持启动前取消、5 秒超时、SIGTERM 后升级 SIGKILL,continuation 只恢复一次。
  • TestProcessMacProcessRunner 使用异步持续排空输出与有界 EOF 收尾,不再同步读取到 EOF。
  • MacProcessRunner 的 stdin 写入移到 GCD worker,使主线程仍能执行超时;超时后有界等待并强制终止。
  • MacProcessRunnerMacRawProcessSessionMacStreamingProcess 对输入管道启用 F_SETNOSIGPIPE,把管道关闭转为普通写入错误。
  • Raw/Streaming session 在 stdin 写入前启动超时,并在 SIGTERM 无效后升级为 SIGKILL;手动停止也安排有界强制终止。
  • macOS 运行时探测增加 5 秒超时,更新安装工具调用统一使用 120 秒有界 runner。

CI 隔离

  • GitStatusObservationTests 拆到独立 Swift 测试进程,隔离文件监听与 Git 子进程生命周期。

静态审计

macos/Sourcesmacos/Tests 中已无:

  • waitUntilExit()
  • 无参数 .wait()
  • readDataToEndOfFile()

剩余 semaphore、condition 和轮询均有明确的 200ms–5s 截止时间。新增补修全部位于 macos/

验证

  • 相关聚焦回归:37/37 通过。
  • macOS 进程抗阻塞测试:3/3 通过,覆盖忽略 SIGTERM、1 MiB 未消费 stdin、SIGPIPE 防护与强制终止。
  • macOS CI 主测试:528/528 通过。
  • macOS 数据库独立测试:48/48 通过。
  • Git 状态观察独立测试:13/13 通过,约 14.8 秒。
  • ./scripts/verify-service-boundaries.sh 通过。
  • git diff --check 通过。

本 PR 仅修复 macOS,不修改 Windows/Rust,不修改 #269/#270,也不改写现有 Git 历史。

@xiaoyumuxi
xiaoyumuxi requested a review from 1lck as a code owner August 27, 2026 10:32
@xiaoyumuxi

Copy link
Copy Markdown
Collaborator Author

@lithe review

@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Lithe Review

结论: ✅ 未发现明确问题(LGTM)
依据: 未关联 Issue · a3a8cb3 ← f1b5ad1 · head: f1b5ad1

验证

  • 检查了完整 12 文件 diff,并聚焦追踪生产调用方、测试协调原语、Git fixture 进程生命周期及 macOS CI 接入
  • 已提供的 CI:Database、Windows、Rust Core/Swift bridge 等相关 gate 成功;Swift tests 与 Release package verification 仍在进行
  • 本次审查未运行测试

@xiaoyumuxi

Copy link
Copy Markdown
Collaborator Author

@lithe review

@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Lithe Review

结论: ❓ 审查未完成

审查状态:cancelled
请查看本次 Actions 日志与诊断附件后重新召唤。

@1lck

1lck commented Aug 27, 2026

Copy link
Copy Markdown
Owner

ci也合到preview 我晚上合main

@xiaoyumuxi
xiaoyumuxi changed the base branch from main to preview August 27, 2026 12:14
@xiaoyumuxi

Copy link
Copy Markdown
Collaborator Author

ci也合到preview 我晚上合main

codex 给我自动推到 preview 了,我本来没打算推 main 的

Comment thread macos/Sources/Lithe/Platform/MacOS/Process/MacProcessRunner.swift Outdated
Comment thread macos/Tests/LitheTests/TestProcess.swift
Comment thread macos/Sources/Lithe/Platform/MacOS/Process/MacProcessRunner.swift
@1lck
1lck merged commit 68bdf6d into preview Aug 28, 2026
4 checks passed
@xiaoyumuxi
xiaoyumuxi deleted the codex/fix-macos-test-blocking-waits branch August 30, 2026 03:15
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.

2 participants