Skip to content

refactor: adopt modern Go idioms in tests and examples - #184

Merged
appleboy merged 1 commit into
masterfrom
refactor/modern-go-idioms
Nov 5, 2026
Merged

appleboy merged 1 commit into
masterfrom
refactor/modern-go-idioms

Conversation

@appleboy

@appleboy appleboy commented Nov 5, 2026

Copy link
Copy Markdown
Member

Summary

Apply idioms from the Modern Go Guidelines for this module's Go version (go 1.26.10). Detection: go fix -diff ./... on every module plus a manual scan for patterns go fix does not rewrite. No library/production code changes. Only tests, benchmarks, and _example programs are touched.

  • testing_b_loop: replace b.N loops (and the now-redundant b.ResetTimer()) with for b.Loop() in job/benchmark_test.go, BenchmarkQueueTask, BenchmarkQueue, BenchmarkRingWithTask, the resize operations sub-benchmark, BenchmarkHandleRetry, and BenchmarkRingBoundary.
  • atomic_types: thread_test.go uses atomic.Int32 instead of atomic.AddInt32 / LoadInt32. The failure message also reads the counter through Load() instead of reading the raw value.
  • range_over_int (via go fix): _example/example01 and example02 use for i := range taskN.
  • loopvar_capture: drop the redundant go func(i int) { ... }(i) parameter in the examples, because each iteration has its own i since Go 1.22.
  • Intentionally not changed:
    • BenchmarkNewRing / testQueue and benchmarkQueueCompletion depend on b.N for queue sizing and batching, so they keep the b.N loop.
    • go fix also proposed adding //go:fix inline to job.Int64/Float64/Time/Bool. Those helpers are explicitly marked //nolint:modernize // pointer-returning helper kept intentionally, so that change was skipped.

Related issues

  • Jira: N/A
  • GitHub: N/A

AI authorship

  • No AI was used
  • AI was used
    • Tool / model: Claude Code (Claude Opus 5.5)
    • AI-authored files: _example/example01/main.go, _example/example02/main.go, benchmark_test.go, handle_performance_test.go, job/benchmark_test.go, ring_performance_test.go, ring_test.go, thread_test.go
    • Human line-by-line reviewed: None — not yet reviewed by a human.

Change classification

  • Leaf change: tests, benchmarks, and examples only; no exported API or runtime behavior changes
  • Core change

Plan reference

Goal: run the Modern Go Guidelines (list --go-version 1.26) across every Go module in the golang-queue org workspace and apply the guidelines that fit without changing behavior. Companion PRs were opened in the sibling repos (queue, benchmark, nats, nsq, rabbitmq, redisdb, redisdb-stream).

Verification

Setup

  • Checkout target / working directory: branch refactor/modern-go-idioms @ fde8f0b, repository root
  • Prerequisites: Go 1.26.10 (go version)
  • Prepare and start: go mod download

Automated checks

Command (with working directory) Behavior covered / expected success Status Observed result / reason not run
go vet ./... Static analysis Passed No output
make lint golangci-lint (repo config) Passed 0 issues.
go test -race ./... Unit tests incl. goleak Passed ok github.com/golang-queue/queue, ok github.com/golang-queue/queue/job
go test -run '^$' -bench . -benchtime 200x ./... All benchmarks still execute Passed ok for both packages
cd _example/example01 && go vet ./... (and example02) Examples compile Passed No output

Behavioral scenarios

Tests and benchmarks unchanged in behavior

  • Acceptance condition: no library code changes; tests pass under -race; every converted benchmark still runs.
  • Starting state: Go 1.26.10, repository root.
Step Action Expected observable result
1 go test -race -run TestRoutineGroupRun -v . Both subtests PASS with no race report
2 go test -run '^$' -bench . -benchtime 200x ./... All benchmarks print results; ok for queue and queue/job
3 cd _example/example01 && go run . Prints 30 message: Hi Gopher, handle the job: NN lines with distinct NN
  • Execution status: Steps 1–2 Passed; step 3 Not run (examples verified by go vet only)
  • Observed result: see Automated checks.
  • Cleanup: N/A — read-only.

Evidence

Web screenshots

N/A — no UI.

Performance report

N/A — benchmark harness modernization only; no performance claim is made. Absolute numbers from b.Loop() may differ slightly from the old b.N loop because setup is now excluded automatically.

Security check

  • No secrets in the diff
  • N/A - no external or security-sensitive interface changed

Risk and rollback

  • Risk: Low. Only tests, benchmarks, and examples change.
  • Rollback: revert this single commit.

Reviewer guide

  • Read carefully: thread_test.go (atomic type change), benchmark_test.go (confirm b.N-sized benchmarks were left alone).
  • Spot-check: mechanical for i := range n / go func() rewrites in _example/.
  • Evidence not captured: N/A

🤖 Generated with Claude Code

- Replace b.N loops and ResetTimer with b.Loop where setup is independent of b.N
- Use typed atomic.Int32 instead of atomic.AddInt32 and LoadInt32
- Use range-over-int loops in examples
- Drop redundant goroutine loop-variable parameters in examples

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@appleboy
appleboy merged commit 3942198 into master Nov 5, 2026
6 checks passed
@appleboy
appleboy deleted the refactor/modern-go-idioms branch November 5, 2026 06:06
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