Skip to content

CRE-4040: stabilize TestCompute_SpendValueRelativeToComputeTime#22341

Open
aareet wants to merge 2 commits intodevelopfrom
fix/flaky-CRE-4040-2026-05-07
Open

CRE-4040: stabilize TestCompute_SpendValueRelativeToComputeTime#22341
aareet wants to merge 2 commits intodevelopfrom
fix/flaky-CRE-4040-2026-05-07

Conversation

@aareet
Copy link
Copy Markdown
Contributor

@aareet aareet commented May 7, 2026

Summary

Fixes flake in TestCompute_SpendValueRelativeToComputeTime (subtest /2s reported by Trunk).

  • Replace per-row expectedUpperLimit with an overhead-bounded assertion: (measured - mocked_delay_ms) < meteringOverheadBudgetMs (1500ms). Decouples tolerance from case duration and tests a single invariant — metering overhead is bounded.
  • Drop the inner t.Parallel() on the 5 subtests to reduce timer-heap and CPU contention. Outer t.Parallel() is preserved.
  • No production-code changes (root cause is real-time clock usage in compute.go:executeWithModule; flagged for follow-up but out of scope here).

Why the previous bound was flaky

Each table row had a fixed 400ms upper buffer over its mocked delay. Production executeWithModule measures elapsed time with raw time.Now()/time.Since() (no mockable clock), so any CI scheduling jitter or wasm-module setup overhead falls into the assertion window. Trunk recorded a failing run with 438ms of overhead on the 2s case (measured 2438 > expected 2400). The 2.5s and 3s rows have identical 400ms buffers and were waiting to flake the same way.

Flaky test fixes

Issue Test Trunk
CRE-4040 TestCompute_SpendValueRelativeToComputeTime/2s Trunk test case

Test plan

  • go test -race -shuffle=on -run '^TestCompute_SpendValueRelativeToComputeTime$' ./core/capabilities/compute/... — 10/10 consecutive runs PASS locally
  • CI passes, including any quarantined-test runs

🤖 Generated with Claude Code

Replace per-row expectedUpperLimit with an overhead-bounded assertion that
caps measured-minus-mocked-delay at a single budget (1500ms). The previous
400ms upper buffer was too tight for wall-clock measurement in compute.go
under CI load — observed 438ms overhead broke the 2s case and the 2.5s/3s
rows had identical 400ms buffers waiting to flake.

Also drop the inner t.Parallel() on the subtests to reduce timer-heap and
CPU contention across the 5 wasm-module subtests; outer t.Parallel() is
preserved.

Verified: 10/10 passes with -race -shuffle=on.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

✅ No conflicts with other open PRs targeting develop

@trunk-io
Copy link
Copy Markdown

trunk-io Bot commented May 7, 2026

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

Restructure the upper-bound assertion to stay in uint64 space: keep
meteringOverheadBudgetMs as uint64 and compare measured value against a
precomputed upperBound (mocked delay ms + budget) instead of subtracting
across signed/unsigned types. The remaining int64→uint64 cast on
test.time.Milliseconds() is annotated with //nolint:gosec since the
duration is a positive constant.

Re-verified: 10/10 passes with -race -shuffle=on.
@cl-sonarqube-production
Copy link
Copy Markdown

@aareet aareet marked this pull request as ready for review May 7, 2026 19:27
@aareet aareet requested review from a team as code owners May 7, 2026 19:27
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