Skip to content

Comments

test: standardize errors with ewrap; add constants; parallelize timers#18

Merged
hyp3rd merged 2 commits intomainfrom
feat/improvements
Jan 20, 2026
Merged

test: standardize errors with ewrap; add constants; parallelize timers#18
hyp3rd merged 2 commits intomainfrom
feat/improvements

Conversation

@hyp3rd
Copy link
Owner

@hyp3rd hyp3rd commented Jan 20, 2026

  • tests/retrier_test.go, tests/registry_test.go:
    • Replace errors.New with ewrap.New and introduce shared errTemporary.
    • Add test-only constants (e.g., errFailedToCreateRetrier) and update assertions/initializers for consistent temporary/non-temporary errors.
  • tests/timer_test.go: mark timer pool tests with t.Parallel for concurrency.
  • ci(golangci-lint): disable the testpackage linter in .golangci.yaml.
  • docs(README): update example to use ewrap.New("temporary error") and tidy formatting.

Why: unify test error semantics, improve maintainability and test performance,
and catch test package issues earlier via linting. No production code changes.

  - tests/retrier_test.go, tests/registry_test.go:
    - Replace errors.New with ewrap.New and introduce shared errTemporary.
    - Add test-only constants (e.g., errFailedToCreateRetrier) and update
      assertions/initializers for consistent temporary/non-temporary errors.
  - tests/timer_test.go: mark timer pool tests with t.Parallel for concurrency.
  - ci(golangci-lint): enable the testpackage linter in .golangci.yaml.
  - docs(README): update example to use ewrap.New("temporary error") and tidy
    formatting.

  Why: unify test error semantics, improve maintainability and test performance,
  and catch test package issues earlier via linting. No production code changes.
Copilot AI review requested due to automatic review settings January 20, 2026 18:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR standardizes error handling in test files by replacing errors.New with ewrap.New, introduces shared test constants for better maintainability, and parallelizes timer tests for improved test performance. It also attempts to enable the testpackage linter in golangci-lint configuration and updates the README example.

Changes:

  • Replaced errors.New with ewrap.New for consistent error wrapping in tests
  • Added test constants (errTemporary, errRetryCountMismatch, errNonTemporary, errFailedToCreateRetrier) to reduce duplication
  • Added t.Parallel() to all test functions in timer_test.go, retrier_test.go, and registry_test.go for concurrent execution
  • Updated README.md example to use ewrap.New
  • Modified .golangci.yaml linter configuration

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/timer_test.go Added t.Parallel() to all three timer pool tests for concurrent execution
tests/retrier_test.go Standardized errors with ewrap.New, introduced constants, renamed variables (rretrier), improved error handling, and added t.Parallel() to all tests
tests/registry_test.go Replaced errors.New with ewrap.New, added errFailedToCreateRetrier constant, renamed variable (rregistry), and added t.Parallel() to tests
.golangci.yaml Added testpackage to the linter disable list
README.md Updated example code to use ewrap.New("temporary error") and added trailing newline

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +20
errRetryCountMismatch = "retry did not retry the function the expected number of times. Got: %d, Expecting: %d"
errNonTemporary = "non-temporary error"
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant errFailedToCreateRetrier is used throughout this file (lines 197, 217, 228, 251, 269, 310, 342, 408, 437, 469, 506, 572, 611, 642) but is not defined here. It's only defined in registry_test.go. This will cause compilation errors. Add the constant definition to this file's const block.

Suggested change
errRetryCountMismatch = "retry did not retry the function the expected number of times. Got: %d, Expecting: %d"
errNonTemporary = "non-temporary error"
errRetryCountMismatch = "retry did not retry the function the expected number of times. Got: %d, Expecting: %d"
errNonTemporary = "non-temporary error"
errFailedToCreateRetrier = "failed to create new Retrier: %v"

Copilot uses AI. Check for mistakes.

// Register a temporary error.
tempErr := errors.New("temporary error")
tempErr := ewrap.New("temporary error")
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code example uses ewrap.New("temporary error") but the import section doesn't include the ewrap package. Either add the ewrap import (e.g., "github.com/hyp3rd/ewrap") or replace ewrap.New with errors.New to match the existing imports.

Suggested change
tempErr := ewrap.New("temporary error")
tempErr := errors.New("temporary error")

Copilot uses AI. Check for mistakes.
- recvcheck
- tagliatelle
- tagalign
- testpackage
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description states "enable the testpackage linter" but this change adds testpackage to the disable list, which means it will remain disabled. To enable the linter, it should be removed from the disable list or added to the enable list (if the default is not 'all').

Suggested change
- testpackage

Copilot uses AI. Check for mistakes.
- Initialize options earlier in constructor so defaults/overrides are applied before use.
- Ensure retry error aggregation initializes Attempts before append; lazily init errors pool.
- Guard debug logging with Logger.Enabled(ctx, slog.LevelDebug) to avoid unnecessary work.
- Make handleAttemptError robust to nil Attempts and safely append entries.
- tests: refresh benchmarks in tests/retrier_test.go to reflect current retry behavior and reset state per iteration.
- docs(README): update example paths and benchmark outputs.
- ci(golangci-lint): raise cyclop max-complexity to 15.
- examples: move examples/* to __examples/* to keep them out of package discovery/build.

Why: prevent nil dereferences in error tracking, reduce logging overhead when debug is off, and align docs/benchmarks with current behavior while keeping examples from polluting the module graph.

BREAKING CHANGE: none
@hyp3rd hyp3rd merged commit 6cbb7aa into main Jan 20, 2026
10 checks passed
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