Skip to content

tests: tighten coverage by retiring unreachable defensive code (wave 2)#2

Merged
TeoSlayer merged 1 commit into
mainfrom
coverage-housekeeping-wave2
May 28, 2026
Merged

tests: tighten coverage by retiring unreachable defensive code (wave 2)#2
TeoSlayer merged 1 commit into
mainfrom
coverage-housekeeping-wave2

Conversation

@TeoSlayer
Copy link
Copy Markdown
Contributor

Summary

  • Drop the http.NewRequestWithContext error branch in fetchOnce — method ("GET") and URL (compile-time constant) cannot produce an error.
  • Expose initialJitterMax and httpClientForRun as package vars so tests can deterministically drive Run through the timer-fired + fetch-fail path without network dependencies.
  • Add TestRun_TimerFires covering the full loop cycle.

Coverage

  • Before: 90.9%
  • After: 94.8%
  • Run: 66.7% → 100%
  • fetchOnce: 94.7% → 100%

Remaining gap: embedded-JSON-malformed init() fallback (4 stmts) and crypto/rand.Int failure in jitter — both real defensive paths.

Test plan

  • go test -race -count=1 -timeout 120s ./... passes
  • Coverage moved measurably without gold-plating

fetchOnce: http.NewRequestWithContext only fails on invalid method/URL,
both compile-time constants here — drop the error branch with a comment
so future readers don't add the check back.

Add two test seams:
  - initialJitterMax (var, was const-arg) — lets tests shrink the
    first-fetch jitter to 0 so timer.C fires immediately.
  - httpClientForRun (var, was inline literal) — lets tests inject a
    failing http.Client so the slog.Warn-on-fetch-fail branch is also
    exercised.

New test TestRun_TimerFires drives the full Run loop through one
timer.C → fetchOnce → slog.Warn → timer.Reset cycle deterministically,
without depending on the real network.

Coverage: 90.9% → 94.8%. Run climbs from 66.7% → 100%, fetchOnce from
94.7% → 100%. The remaining gap is the embedded-JSON-malformed init()
fallback and rand.Int failure in jitter — both real defensive paths.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@TeoSlayer TeoSlayer merged commit 3500175 into main May 28, 2026
2 checks passed
@TeoSlayer TeoSlayer deleted the coverage-housekeeping-wave2 branch May 28, 2026 03:30
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.

2 participants