Skip to content

test(host): SIGUSR1 重新读取的测试按任意顺序等待 reloaded 与行状态 - #578

Merged
eric8810 merged 3 commits into
mainfrom
fix/sigusr1-reload-test-order
Oct 22, 2026
Merged

eric8810 merged 3 commits into
mainfrom
fix/sigusr1-reload-test-order

Conversation

@eric8810

Copy link
Copy Markdown
Contributor

修 `sigusr1::sigusr1_reloads_and_the_host_runs_on` 的偶发失败(#553、#561 的 CI)。

原因

不是读到写了一半的文件。日志里的 `reload rejected: …EOF while parsing an object at line 1 column 1` 是测试自己第一步写入的 `{`,本来就该被拒绝。真正卡住的是第二步:

```
"plugin node-row cleanup started",
"node-row: removed",
"rutis-host: reloaded …/rutis.json (1 row changed)",
```

状态行由 `status::follow` 在自己的任务里每 200 ms 打印一次,与 `reload` 打印的 `rutis-host: reloaded` 没有先后约定(指南只说“行的状态变化照常由状态行打印”)。测试按顺序读行:等 `reloaded` 时把先到的 `node-row: removed` 读掉了,之后再等 `node-row: removed` 直到超时。

产品侧:SIGUSR1 是用户写完后主动发的,`--watch-config` 已经在内容连续 500 ms 不变后才读(`reload::SETTLE`,指南有写),截断后再写的编辑器不会被读到中间状态。所以不改产品。

改动

  • `tests/common/process.rs` 加 `Host::wait_lines`:等到给出的几行都出现,不论顺序。
  • `sigusr1_reloads_and_the_host_runs_on` 用它等 `reloaded` 和 `node-row: removed`;Node 行的清理加 1 s 延迟,让 `removed` 必然先于 `reloaded` 打印。改之前这个测试每次都失败,输出与 CI 的一样;改之后通过。
  • `a_watched_configuration_reloads_when_it_changes` 有同样的等待(`reloaded` 之后等 `office: running`),一并改为任意顺序。

测试:`cargo test -p rutis-host --test reload`,`cargo clippy -p rutis-host --tests`。

… order

The state lines are printed every 200 ms by their own task, apart from
what a reload prints, so a removed row's 'removed' can come before
'rutis-host: reloaded'. sigusr1_reloads_and_the_host_runs_on read lines
in order, consumed 'node-row: removed' while waiting for the reload and
then waited for it until the guard. The rejected '{' write was the
test's own broken step, not a half-written file.

The Node row's cleanup now takes 1 s, which makes that order certain:
the test failed every time before the change. The watched-config test
had the same wait.
@eric8810 eric8810 added this to the 0.15 milestone Oct 22, 2026
@eric8810
eric8810 merged commit 5d21a7b into main Oct 22, 2026
26 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