tests: tighten coverage by retiring unreachable defensive code (wave 2)#2
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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
http.NewRequestWithContexterror branch infetchOnce— method ("GET") and URL (compile-time constant) cannot produce an error.initialJitterMaxandhttpClientForRunas package vars so tests can deterministically driveRunthrough the timer-fired + fetch-fail path without network dependencies.TestRun_TimerFirescovering the full loop cycle.Coverage
Run: 66.7% → 100%fetchOnce: 94.7% → 100%Remaining gap: embedded-JSON-malformed init() fallback (4 stmts) and
crypto/rand.Intfailure in jitter — both real defensive paths.Test plan
go test -race -count=1 -timeout 120s ./...passes