Skip to content

test: fix shared fixture cleanup and deterministic HNSW expiry - #29105

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-29039-ut-lifecycle-optimization
Sep 19, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-29039-ut-lifecycle-optimization

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #29039

What this PR does / why we need it:

Problem

  1. pkg/vectorindex/hnsw/TestHnsw used a wall-clock expiry window while the
    cache ticker could claim, remove, and destroy the entry asynchronously.
    The final map assertion could therefore observe an intermediate eviction
    state.
  2. SharedTestCluster.Run held its lifecycle mutex while executing the test
    callback. A parent callback that waited for a child test could deadlock
    with child cleanup or same-fixture re-entry, leaving the fixture,
    admission, or ports retained.
  3. An explicit terminal Close() could be deferred behind failed-test cleanup.
    Its terminal intent must survive that deferral.

Fix

  • Keep HNSW's concurrent load/search stress, but do not start the cache ticker
    in this test. Force the known resident entry expired, run HouseKeeping
    synchronously, and assert both map removal and STATUS_DESTROYED. The cache
    package continues to cover wall-clock ticker expiry.
  • Keep shared-fixture callbacks serialized with condition-backed admission,
    but release the lifecycle mutex before user callback code. Real child
    cleanup can then acquire lifecycle state; same-fixture nested Run calls
    fail promptly with an actionable diagnostic and should use the inherited
    cluster.
  • Preserve generation guards, cleanup registration ordering, incomplete-close
    ownership, exactly-once automatic failure cleanup, and terminal Close()
    intent across deferred cleanup.

No production vector-index implementation, runner count, package parallelism,
test deadline, retry, or test coverage selection is changed.

Validation

  • Focused embed lifecycle tests, including real testing.T parent/child
    cleanup, nested re-entry rejection, terminal-close deferral, panic paths,
    and incomplete-close retry: passed in normal and race builds.
  • HNSW TestHnsw: passed in normal mode (4.06s), short race mode (3
    repetitions), and full race mode (10.86s).
  • Relevant cache housekeeping/concurrency tests: passed in normal and race
    builds.
  • go vet and git diff --check: passed.
  • Incremental golangci-lint from the merge base with --whole-files:
    0 issues. Incremental molint exited successfully; its existing
    checkrecover diagnostics are outside the changed files.

The linked macOS worktree lacks its own libmo.dylib, so direct go test
temporary binaries cannot launch without the same-platform native artifacts.
The compiled test binaries were executed successfully with the existing
same-platform native libraries.

@XuPeng-SH
XuPeng-SH requested a review from fengttt as a code owner September 19, 2026 02:52
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Astra medium review on current head 90cdc30.\n\n发现 2 个 P2 测试正确性问题,未发现 P0/P1:\n\n1. [P2] 子测试 panic 可能让 failure cleanup 与父级 Run 死锁。位置:pkg/embed/testing.go:194-198,247。父 Run 持有 c.mu 并等待 t.Run 子测试;子测试 panic 时,Go testing 会先执行祖先 cleanup,finalizer 再等待同一把 c.mu,形成“父 Run 持锁等待子测试、子 cleanup 等锁”的循环,可能把 panic 变成整包 timeout,并遗留 fixture/admission/port 资源。现有 synthetic panic/parent-child 用例没有覆盖真实 testing.T 祖先 cleanup 路径。建议分离 callback 串行锁与生命周期状态锁,并用真实子测试 panic 回归验证。\n\n2. [P2] 同步 HouseKeeping 不会等待后台已取得的 eviction claim,最终断言仍有调度竞争。位置:pkg/vectorindex/hnsw/search_test.go:276-279,仲裁在 cache.go:798,删除在 806。后台 ticker 可以先将 entry 标记 evicting 后暂停;测试线程调用 HouseKeeping() 会跳过该 entry,随后立即 Load 可能仍看到它。反方向,后台已从 map 删除但尚未完成 Algo.Destroy() 时,当前断言也可能提前通过。建议停止并 join 后台清扫,或等待具体 entry 的 eviction/destruction 完成;补充后台已 claim、尚未 delete 的确定性 barrier 测试,并断言销毁恰好一次。\n\n其他 fixture generation/retry/cleanup 路径未发现确定性问题。coverage 和 CI duration 不作为本次结论门槛;本 PR 为自有 PR,提交 COMMENT。

@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Sep 19, 2026
@XuPeng-SH XuPeng-SH changed the title test: isolate failed UT fixtures and stabilize HNSW expiry test: fix shared fixture cleanup and deterministic HNSW expiry Sep 19, 2026

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Astra medium re-review on current head 209ea64.\n\n上一轮两个 P2 的具体机制已在代码层面修复,未发现本次 diff 引入的可复现 P0/P1/P2 代码缺陷:\n\n- 父级 Run/祖先 cleanup 的等待环已解除,callback 不再持有生命周期锁等待子测试;\n- HNSW 测试不再启动测试 cache ticker,search workers 完成后同步 HouseKeeping,并同时验证 map 删除和 STATUS_DESTROYED。\n\n仍有非 coverage 验证缺口:\n\n1. 真实子测试 panic 尚缺直接回归。当前 panic 用例使用 synthetic reporter;真实 parent/child 测试只覆盖成功 cleanup。建议用子进程覆盖真实 child panic、FailNow、Goexit,验证 cleanup 顺序和不发生 timeout。\n2. 新 admission 竞争缺少确定性 barrier 测试:两个独立 Run 串行进入,以及 Run 与 Close/CloseIfActive 竞争时的等待释放、terminal intent 和复用结果。\n3. HNSW 新断言证明 map 删除及 destroy completion,但未覆盖 native 销毁次数与 cancel/Reset 组合。\n\n本 PR 为自有 PR,提交 COMMENT。

@XuPeng-SH
XuPeng-SH merged commit 4bc876d into matrixorigin:main Sep 19, 2026
28 checks passed
XuPeng-SH added a commit that referenced this pull request Sep 19, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes #28902
Fixes #28901
Fixes #28896
Fixes #28894
Fixes #28892

## What this PR does / why we need it:

Close expression result-domain and coercion gaps left by #28941:

- Bound Base64 and character-slicing metadata only when provable;
preserve temporal fractional precision in conditional expressions.
- Use INT32 for current IP predicates while retaining legacy INT64
executors.
- Keep INET_NTOA numeric/string/boolean/temporal/JSON/prepared-source
conversion local to the function, including overflow-to-NULL and
preserved DML roots; do not broaden global casts.
- Fence changed persisted/remote expression contracts at MORPC v86,
including mixed TIMESTAMP/DATETIME IF/CASE, while retaining
explicit-cast and legacy negative controls.
- Cover missing character-bound, overflow, registered-executor,
temporal, invalid-input, NULL and selection contracts with small
function tests and no cluster fixture.
- Make TestHnsw idle eviction deterministic: retain concurrent real
searches, then expire the resident entry and synchronously assert both
removal and completed destruction. Cache-package tests retain ticker
coverage. This test-only fix is shared with #29105; no production cache
change.

## Validation

Retained earlier evidence: detector/protobuf round trips,
binder/persisted admission, mixed-temporal fractional execution and
serialized remote-destination protocol rejection/acceptance. The remote
test proves the protocol boundary, not live two-CN value execution.

Current CI-repair delta, macOS arm64 / Go 1.26.4, worktree-native `make
-j8 cgo` and `mo-cgo-test`:

- New/extended function tests: passed (2.053s); full function package
with coverage: passed (23.584s).
- Full HNSW package in short+coverage mode: passed (123.013s); TestHnsw
itself 0.63s.
- Exact TestHnsw short race: passed, then 43 bounded repetitions in one
process passed (9.322s package time).
- Existing CI profile plus local focused profile, matched by unchanged
source-block coordinates: 488/679 (71.87%) -> 540/679 (79.53%), adding
52 covered blocks. This is a local/historical-CI union estimate, not a
fresh CI result. Coverage threshold and filters are unchanged.
- Incremental vet/lint for the changed test packages and final GPT-6
medium review.

The latest repair changes only three test files, with no production
hot-path, runner, timeout or coverage-exclusion changes. Fresh CI is
intentionally not awaited or claimed as passed.

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/test-ci size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants