Skip to content

testifylint: enable the go-require linter and fix all findings#20397

Open
arthurschreiber wants to merge 4 commits into
mainfrom
arthur/go-require
Open

testifylint: enable the go-require linter and fix all findings#20397
arthurschreiber wants to merge 4 commits into
mainfrom
arthur/go-require

Conversation

@arthurschreiber

Copy link
Copy Markdown
Member

Description

This enables testifylint's go-require checker and fixes every finding across the codebase.

go-require flags require.* calls made from a non-test goroutine. require calls t.FailNow()runtime.Goexit(), which only terminates the test correctly on the goroutine running the test function. Off that goroutine it kills just the spawned goroutine, so the test can hang on a channel that never closes, or report a false pass — a real correctness problem, not a style nit.

The PR is structured so each piece is easy to review:

  • Enable the checker in .golangci.yml with only go-require turned on (disable-all: true + enable: [go-require]). The other testifylint checkers are being adopted separately.
  • Unit-test findings (topo conformance helpers, conn_test, tm_init_test, vstreamer_test, workflow utils_test): requireassert inside the spawned goroutines, with explicit return/continue so the abort behaviour require's Goexit provided is preserved. Shared helpers used from both the test goroutine and a child goroutine (createSocketPair, grantAllPrivilegesToUser, startFullyThrottledStream) are fixed at the goroutine call site so their main-goroutine callers stay fail-fast.
  • execVtgateQuery / insertLargeTransactionForChunkTesting now return an error instead of asserting internally (the *testing.T parameter is dropped); ~108 call sites updated to require.NoError on the test goroutine and assert.NoError in the inserter goroutines. This avoids a parallel error-returning "twin" helper.
  • endtoend findings, including making waitForWorkflowState and performVDiff2Action return errors so they are goroutine-safe (again, instead of carrying a twin). performVDiff2Action keeps waiting for the workflow internally via the now-require-free waitForWorkflowState.

go vet passes across every touched package, and golangci-lint run --max-same-issues 0 --max-issues-per-linter 0 ./go/... reports 0 go-require findings. The unit-test fixes were verified locally with go test -race; the endtoend changes rely on CI for behavioural validation.

Related Issue(s)

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Deployment Notes

None — this only touches test code and the linter config.

AI Disclosure

This PR was written primarily by Claude Code — I provided direction and reviewed the changes.

arthurschreiber and others added 4 commits June 25, 2026 11:14
Enables testifylint with only the go-require checker turned on. go-require
flags require.* calls made from a non-test goroutine: require calls
t.FailNow() -> runtime.Goexit(), which only terminates the test correctly on
the test goroutine. Off-goroutine it kills just that goroutine, so the test
can hang on a never-closed channel or report a false pass.

The remaining testifylint checkers are being adopted separately.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
The go-require checker flags require.* calls made from a non-test
goroutine. require calls t.FailNow() -> runtime.Goexit(), which only
terminates the test correctly on the main test goroutine; off-goroutine
it kills just that goroutine, so the test can hang on a channel that
never closes or report a false pass.

Fixes the 9 findings in packages that run in unit CI:

- topo/test/{shard,trylock}.go: replace require.Fail with assert.Fail +
  return in the lock-test goroutines, preserving the existing
  timeout-on-failure behavior.
- vtctl/workflow/utils_test.go: the goroutine-only update() helper now
  uses assert + return.
- mysql/conn_test.go: hoist createSocketPair (a require-using helper
  shared by 18 callers, all but one on the main goroutine) out of the
  goroutine.
- vttablet/tabletmanager/tm_init_test.go: grantAllPrivilegesToUser now
  returns an error, so the main caller requires it while the
  delayed-grant goroutine asserts, guarded by ctx.Err() to avoid
  asserting after the test completes.
- vttablet/tabletserver/vstreamer/vstreamer_test.go: hoist
  startFullyThrottledStream setup out of the goroutine.

go-require stays disabled in config until the remaining endtoend
findings are fixed in a follow-up.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
execVtgateQuery and insertLargeTransactionForChunkTesting (vreplication
endtoend test helpers) asserted internally via require, which is unsafe
when called from a goroutine: require's FailNow only terminates the test
correctly on the test goroutine. Rather than carry a parallel
error-returning "Err" twin, make the helpers themselves return an error
and have every caller require/assert on it.

- execVtgateQuery(conn, db, query) (*sqltypes.Result, error): dropped the
  *testing.T parameter; callers own the assertion.
- insertLargeTransactionForChunkTesting(conn, ks, startID) error: likewise.
- ~108 call sites updated: require.NoError on the test goroutine,
  assert.NoError in the vstream inserter goroutines (with the existing
  mutex-unlock-before-return preserved).

Pure refactor with no behavior change for existing test-goroutine callers.
Prep for enabling the testifylint go-require checker.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Fixes the remaining go-require findings across go/test/endtoend.

To make the vdiff helpers safe to call from goroutines (rather than carry an
error-returning "WithErr" twin), two shared helpers now return an error:

- waitForWorkflowState(vc, ksWorkflow, wantState, ...) error: dropped the
  *testing.T param and returns an error instead of calling require; its
  callers now wrap it in require.NoError. This keeps it require-free so it can
  run inside a goroutine.
- performVDiff2Action(...) (uuid, output string, err error): returns an error
  and waits for the workflow internally via the now-require-free
  waitForWorkflowState, so its goroutine callers can use it with assert.NoError.

Other go-require fixes:
- Goroutine-only helpers (verifyDisableEnableRedoLogs, runSingleConnection,
  runInTransaction, vtgateExec, runFuzzerThread and its compare helpers,
  populate): require -> assert with explicit return/continue to preserve the
  abort behavior require's Goexit provided.
- checkTabletType (void helper): body converted to assert, making it safe to
  call from the backup goroutines without weakening its test-goroutine callers.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Copilot AI review requested due to automatic review settings June 25, 2026 11:24

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added this to the v25.0.0 milestone Jun 25, 2026
@vitess-bot vitess-bot Bot added NeedsWebsiteDocsUpdate What it says NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Jun 25, 2026
@vitess-bot

vitess-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.33%. Comparing base (70c7a72) to head (7a3018f).
⚠️ Report is 352 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/topo/test/shard.go 0.00% 7 Missing ⚠️
go/vt/topo/test/trylock.go 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main   #20397       +/-   ##
===========================================
- Coverage   69.67%   69.33%    -0.34%     
===========================================
  Files        1614      279     -1335     
  Lines      216793    46990   -169803     
===========================================
- Hits       151044    32580   -118464     
+ Misses      65749    14410    -51339     
Flag Coverage Δ
partial 69.33% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@arthurschreiber arthurschreiber added Type: Internal Cleanup and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Jun 25, 2026
@arthurschreiber arthurschreiber marked this pull request as ready for review June 25, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants