Repository navigation
test: reduce CPU UT fixture duplication - #29141
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
Merge Queue Status
This pull request spent 21 seconds in the queue, including 1 second running CI. Required conditions to merge
|
## 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>
What type of PR is this?
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.
No case is moved to regression, skipped, or removed for coverage reasons.
Validation
mainat56f7d1eae..agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=600s -run '^TestDataBranchDiffAsFile$' -json ./pkg/tests/dmlpassed..agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=600s -run '^TestDataBranchPick$' -json ./pkg/tests/dmlpassed..agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=600s -run '^TestPartitionUniqueIndex$' -json ./pkg/tests/partitionpassed.-count=2special-column and partition runs passed.go vet -mod=readonly ./pkg/tests/dml ./pkg/tests/partition,gofmt, andgit diff --checkpassed.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.