Repository navigation
refactor: adopt modern Go idioms in tests and examples - #184
Merged
Merged
Conversation
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 patternsgo fixdoes not rewrite. No library/production code changes. Only tests, benchmarks, and_exampleprograms are touched.testing_b_loop: replaceb.Nloops (and the now-redundantb.ResetTimer()) withfor b.Loop()injob/benchmark_test.go,BenchmarkQueueTask,BenchmarkQueue,BenchmarkRingWithTask, theresize operationssub-benchmark,BenchmarkHandleRetry, andBenchmarkRingBoundary.atomic_types:thread_test.gousesatomic.Int32instead ofatomic.AddInt32/LoadInt32. The failure message also reads the counter throughLoad()instead of reading the raw value.range_over_int(viago fix):_example/example01andexample02usefor i := range taskN.loopvar_capture: drop the redundantgo func(i int) { ... }(i)parameter in the examples, because each iteration has its ownisince Go 1.22.BenchmarkNewRing/testQueueandbenchmarkQueueCompletiondepend onb.Nfor queue sizing and batching, so they keep theb.Nloop.go fixalso proposed adding//go:fix inlinetojob.Int64/Float64/Time/Bool. Those helpers are explicitly marked//nolint:modernize // pointer-returning helper kept intentionally, so that change was skipped.Related issues
AI authorship
_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.goChange classification
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
refactor/modern-go-idioms@fde8f0b, repository rootgo version)go mod downloadAutomated checks
go vet ./...make lint0 issues.go test -race ./...ok github.com/golang-queue/queue,ok github.com/golang-queue/queue/jobgo test -run '^$' -bench . -benchtime 200x ./...okfor both packagescd _example/example01 && go vet ./...(and example02)Behavioral scenarios
Tests and benchmarks unchanged in behavior
-race; every converted benchmark still runs.go test -race -run TestRoutineGroupRun -v .PASSwith no race reportgo test -run '^$' -bench . -benchtime 200x ./...okforqueueandqueue/jobcd _example/example01 && go run .message: Hi Gopher, handle the job: NNlines with distinct NNgo vetonly)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 oldb.Nloop because setup is now excluded automatically.Security check
Risk and rollback
Reviewer guide
thread_test.go(atomic type change),benchmark_test.go(confirmb.N-sized benchmarks were left alone).for i := range n/go func()rewrites in_example/.🤖 Generated with Claude Code