Skip to content

test: reduce CPU UT fixture duplication - #29141

Merged
mergify[bot] merged 1 commit into
matrixorigin:mainfrom
Lundomn:codex/ut-fixture-coverage-preserving
Sep 20, 2026
Merged

mergify[bot] merged 1 commit into
matrixorigin:mainfrom
Lundomn:codex/ut-fixture-coverage-preserving

Conversation

@Lundomn

@Lundomn Lundomn commented Sep 20, 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 #28849 (CPU/general UT portion)

What this PR does / why we need it:

This PR reduces repeated fixture construction in the CPU and general UT paths while preserving the existing scenarios, error histories, named subtests, and result oracles.

  • Reuses the immutable ancestor and sibling branches in the Data Branch conflict matrix while retaining all 12 PICK leaves, four conflict shapes, and skip/accept/fail behavior.
  • Shares identical DDL and seed data across the special-column Data Branch merge/pick pairs. All six outer scenarios and 17 logical leaves remain present and independently filterable.
  • Combines the partition unique-index checks under one shared cluster fixture. The physical index-count checks and four point queries still run, while unique-conflict checks keep an independent one-row table and verify the final row state.
  • Removes one duplicate Arrow invalid-container assertion and folds the HNSW metadata relkind checks into the existing upgrade lifecycle, retaining the original upgrade and visibility oracles.

No case is moved to regression, skipped, or removed for coverage reasons.

Validation

  • Rebased onto main at 56f7d1eae.
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=600s -run '^TestDataBranchDiffAsFile$' -json ./pkg/tests/dml passed.
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=600s -run '^TestDataBranchPick$' -json ./pkg/tests/dml passed.
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=600s -run '^TestPartitionUniqueIndex$' -json ./pkg/tests/partition passed.
  • Focused filtered leaves for generated-PK, enum conflict/error, and partition unique conflicts passed from fresh processes.
  • -count=2 special-column and partition runs passed.
  • go vet -mod=readonly ./pkg/tests/dml ./pkg/tests/partition, gofmt, and git diff --check passed.
  • Astra Medium design and final review approved the complete diff with no P0-P2 findings.

Local fixture timing is noisy: the special-column parent was 2.52s before and 2.01-2.05s in repeated post-change runs, while the partition focused parent was 11.54s before and 11.52s after. CI timing should be used for the authoritative stage-level result; no GPU result is claimed here.

@Lundomn
Lundomn requested a review from XuPeng-SH as a code owner September 20, 2026 04:27
@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

Choose a reason for hiding this comment

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

APPROVE — reviewed exact head ff581ff. The fixture deduplication retains all distinct PICK conflict and special-column oracles, preserves partition/index coverage, and keeps the Arrow and upgrade assertions covered. Exact-head race CI passed; no actionable P0–P2 findings. Remaining gaps are focused repeated partition evidence and independently measured CI performance.

@mergify mergify Bot added the queued label Sep 20, 2026
@mergify

mergify Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-20 06:39 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-09-20 06:39 UTC · at 534e2f5335dae83e8ea45454e53bd038a9afe94a · squash

This pull request spent 21 seconds in the queue, including 1 second running CI.

Required conditions to merge

@mergify
mergify Bot merged commit 534e2f5 into matrixorigin:main Sep 20, 2026
22 of 23 checks passed
@mergify mergify Bot removed the queued label Sep 20, 2026
XuPeng-SH added a commit that referenced this pull request Sep 20, 2026
## What type of PR is this?

- [x] Improvement
- [x] Test and CI

## Which issue(s) this PR relates to

Related to #28419 (UT producer cost). This does **not** claim to resolve
that whole-job timeout.

## Systematic analysis and scope

The successful race job [35491083784 /
106026038604](https://github.com/matrixorigin/matrixone/actions/runs/35491083784/job/106026038604)
spent 68m27s inside the UT script: light 16m38s, HNSW 38s, exclusive
issues 11m04s, embedded 27m16s, engine 4m47s, and the overlapping
heavy/plan tail about 7m36s, plus preparation. These are stage wall
times, including build/link, not pure test-body times. Package/test
elapsed values must not be summed: embedded cluster admission is
runner-wide and wait time is included in test elapsed.

Local isolated race controls reinforce the need to separate attribution:
`TestHashBuildSharedBudgetRecoverySQL` passed in 14.11s (11.90s service
startup), and `TestSpeedupAbortAllTxn` in 15.37s (14.93s startup),
versus CI elapsed 400.65s and 135.39s. This is a different platform/load
and does **not** establish how much of the CI delta is queueing,
startup, or resource contention. I did not shrink the spill fixture,
remove restarts, raise concurrency, or reduce hang guards based on those
totals.

This PR removes proven sources of repeated work and oversized
packet-fixture allocations inside tests. It does not change production
code, test selection, race flags, coverage configuration, cache seeding,
or scheduling defaults, and does not duplicate #29113's
package-serialization change. Existing fixture reductions in #29141
remain intact.

## Changes and retained contracts

| Case | Previous work | New functional work | Retained/strengthened
oracle |
| --- | --- | --- | --- |
| `TestConcurrent` | 64 workers × 20,000 identical searches = 1,280,000
searches | 64 × 2 same-query searches + 64 × 100 varying-query searches
= 6,528 | Same 100-vector native index, 64 search slots/workers;
shared-query contention and context reuse; every worker visits all
vectors; error, both result lengths, nearest key and zero distance
checked |
| `TestPartitionState_CollectObjectsBetweenInProgress` | 100,000 random
draws from only 20 distinct timestamp windows | All 21 ordered windows,
including the previously unreachable `(t6,t6]` | Original explicit
boundary checks retained; expected complete inserted/deleted sets now
detect missing/duplicate results, not only invalid returned objects |

Native search workers start behind a readiness barrier and are all
joined before index destruction. Worker failures use `Errorf` + return
instead of `FailNow` from a worker. Cleanup is registered immediately
after successful native allocation. The barrier establishes ready
contenders, not a claim of deterministic simultaneous execution inside
native code. Native C++ internals are not instrumented by Go's race
detector.

The long same-query workload remains available as
`BenchmarkConcurrentSearch`: one operation is 64 searches;
`-benchtime=20000x` retains the original 1,280,000 searches. Result
diagnostics are constructed only on failure, instead of reflection-based
assertions on every successful search. The UT is not a soak test;
long-run interleaving/throughput coverage is explicitly moved to the
benchmark rather than claimed equivalent to fewer iterations.

## Measured focused effect

Same local checkout/toolchain/native dependencies, Darwin arm64 (Apple
M4), Go 1.26.4, `-race -short -count=1`; test elapsed excludes
compilation/linking and the package-level race exit delay:

| Test | Base `c2a1d63ee08` | Candidate |
| --- | ---: | ---: |
| `TestConcurrent` | 8.02s | 0.01s |
| `TestPartitionState_CollectObjectsBetweenInProgress` | 0.95s | 0.01s |

Counts are deterministic: 99.49% fewer native searches in ordinary UT,
and 99.979% fewer window queries with exhaustive rather than random
coverage. Timings are single local observations, rounded by Go, not a
statistical speedup guarantee. No whole-CI speedup or Linux runner
before/after result is claimed for these two loop reductions. These two
local reductions alone do **not** prove a large reduction in the
68-minute full suite.

The retained race benchmark also passed at 20,000 operations × 64
searches: 67,139 ns/batch and 1,049 ns/search locally. Benchmark timing
is not directly substituted for test-body timing.

## Validation

All commands use `.agents/skills/mo-dev/scripts/mo-cgo-test` so CGo
links against this worktree's built native dependencies:

- `-race -short -count=1 -json -timeout=2m -run '^TestConcurrent$'
./pkg/vectorindex`: PASS; both named subtests selected.
- `-race -short -count=100 -timeout=120s -run '^TestConcurrent$'
./pkg/vectorindex`: PASS, 2.151s package elapsed. Adaptive repetition
cap 100, based on the 0.01s focused duration.
- `-race -short -count=1 -timeout=3m -v -run
'^TestPartitionState_CollectObjectsBetweenInProgress$'
./pkg/vm/engine/disttae/logtailreplay`: PASS; all 21 named windows
selected.
- `-race -run '^$' -bench '^BenchmarkConcurrentSearch$'
-benchtime=20000x -count=1 -timeout=3m ./pkg/vectorindex`: PASS.
- `-count=1 -timeout=8m ./pkg/vectorindex
./pkg/vm/engine/disttae/logtailreplay`: both full owning packages PASS,
without `-short`.
- `-race -count=1 -timeout=5m ./pkg/vectorindex
./pkg/vm/engine/disttae/logtailreplay`: both full owning packages PASS,
without `-short`.
- `gofmt`, `git diff --check`: PASS. `go test` includes its default vet
checks.

One initial replay timing command used a non-existent exact test name
and selected zero tests; it is excluded from evidence and was replaced
by the exact named run above.

## Review and boundaries

Focused test-only maintenance: no production architecture/design gate
triggered; no SQL/BVT change because neither production behavior nor a
public SQL oracle changes. Resource review: one cleanup owner for the
native index, release of the start barrier by the parent, worker joins
before cleanup, fixed worker/fixture cardinalities; no new scheduler or
long-lived global state.

Independent GPT-6 medium review of the original two-file diff:
**APPROVE, no concrete blockers**. It explicitly verified the
shared-query scenario, benchmark batch normalization, native cleanup
ordering, and exhaustive timestamp-window oracles. CI is not being
waited on as requested.

## Follow-up: reduce frontend packet fixture memory traffic

A read-only sample of race job [35496528538 /
106040456596](https://github.com/matrixorigin/matrixone/actions/runs/35496528538/job/106040456596),
head `af8e0fe2a45009d4867db7e7456b4b9b2fdaa480`, found frontend.test at
4,233,448 KiB RSS on an 8-CPU/16-GiB runner. This is a hotspot
observation, not attribution of the entire process footprint to these
tests.

Changes in `pkg/frontend/mysql_buffer_test.go`:

- Read fixtures borrow immutable payloads through separate
header/payload readers rather than repeatedly concatenating fake wire
and expected output. ReadErr retains original payload sizes, both
rounds, allocation-error/panic injection, and result/leak assertions.
- Bad-network tests now fragment actual **reads** (1, 2, 3, 32-KiB
limits). Previously fragmented writes were concatenated before reading
and did not test short reads. Unfragmented reads still coalesce across
packet boundaries.
- Explicit matrix retains fixed-buffer boundaries, repeated logical
packets, real 16-MiB continuation boundaries, short tails, and empty
terminating packets. Five redundant 5-MiB packets become five
fixed-buffer-plus-one packets; actual multi-16-MiB continuation cases
remain.
- Writer fixture wire is preallocated at its known size. Immutable row
sources replace per-field/random/expected concatenation allocations;
position markers distinguish aligned fields/blocks. Seven writer cases
retain multirow batching, many-column and oversized-field paths,
exact-max rows/fields, independent packet decoder, exact bytes, sequence
and trailing-byte assertions.
- Explicit per-test allocators and immediate Conn cleanup release owned
buffers and assert allocator balance. No new parallelism, goroutine,
production change, or protocol limit reduction.

### Focused resource evidence

Same local Darwin arm64 / Go 1.26.4 native build, race binaries compiled
through mo-cgo-test with `-race -tags matrixone_test`; baseline af8e0fe
versus final frontend diff. Sequential runs, no other test/build running
during measurement; five parents: TestMySQLProtocolRead,
TestMySQLProtocolReadInBadNetwork, TestMySQLProtocolWriteRows,
TestConn_ReadErr, TestConn_ReadOnePayload. Both PASS, `-test.count=1
-test.timeout=5m`, same memory-profile flags.

| Metric | Before | After |
| --- | ---: | ---: |
| Sampled cumulative allocation (MiB) | 4,629.27 | 1,601.65 (-65.4%) |
| Process peak RSS (bytes) | 1,604,616,192 | 1,372,192,768 (-14.5%) |
| Process user + system CPU | 3.45s | 1.87s (-45.8%) |
| Sum of five reported parent test durations | 3.11s | 1.55s |
| End-to-end binary wall time, including initialization/profile/exit |
4.78s | 5.03s |

These are single local observations with sampling/runtime variance.
**Process wall time did not improve in this pair.** The established gain
is markedly less fixture allocation and CPU work, not a demonstrated
whole-CI speedup or a guarantee of shorter Linux stage time. Lower
memory traffic/headroom pressure may help shared-runner contention, but
that remains an inference, not measured CI savings.

### Follow-up validation and review

- Full frontend normal package, without -short: PASS, 24.805s, via
mo-cgo-test with `-count=1 -tags matrixone_test -timeout=8m -json
./pkg/frontend`.
- Full frontend race package, without -short: PASS, terminal exit 0,
using the wrapper-built final race binary with `-test.v -test.count=1
-test.timeout=8m` from pkg/frontend.
- Incremental golangci-lint against af8e0fe for frontend: PASS, 0
issues; gofmt/diff-check PASS.
- Focused changed frontend parents with race and count=2: PASS, terminal
exit 0; fixture reentry/cleanup verified.
- Independent GPT-6 medium follow-up: APPROVE, no remaining code
blockers. Its P2 about periodic payloads hiding aligned field
duplication was fixed with seed/absolute-position markers and
re-reviewed. ReadErr error/panic/cleanup coverage was explicitly
checked.
- Design exemption: focused test-fixture maintenance only. No production
SQL/BVT semantics change; no new concurrent lifecycle requiring stress
scheduling. Original vector/replay validations above remain applicable
to unchanged files. No merge or wait for CI.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

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.

3 participants