Skip to content

test(bodies): cover the remaining typed JSON Lines branches - #2339

Merged
glennawatson merged 3 commits into
mainfrom
test/json-lines-coverage
Sep 26, 2026
Merged

glennawatson merged 3 commits into
mainfrom
test/json-lines-coverage

Conversation

@glennawatson

Copy link
Copy Markdown
Contributor

Summary

The typed JSON Lines code from #2338 is fully covered, and its flush wait no longer needs a catch block.

  • JsonLinesContent<T> waits on the flush and the producer's pending step together with Task.WhenAll, so a failed flush still lets the producer's step finish before the exception propagates and the enumerator is disposed. Behaviour is unchanged; the unreachable catch-block exit is gone.
  • New tests cover a class implementing IAsyncEnumerable<T> and a type implementing two of them in the reflection builder's element lookup, a flush that fails while the producer's step is pending, and the token-less serialize override that .NET Framework calls.

Why

#2338 merged below the repository's 100% patch coverage target. These commits landed on its branch after the merge.

Breaking changes

None.

How this was verified

Tests cover every new line of JsonLinesContent<T> and the reflection builder's JSON Lines lookup on .NET 8 and later.

Notes for the reviewer

The only production change is JsonLinesContent<T>.MoveNextAsync and its small FlushAsync helper; the rest is tests.

  • FlushAsync is awaited on purpose so a synchronous throw from Stream.FlushAsync becomes a faulted task that Task.WhenAll observes.
  • The token-less override test reaches the protected member through reflection, because HttpContent on .NET 8 and later always calls the cancellable overload.

Checklist

  • I have read the Contribute guide
  • The PR title follows Conventional Commits
  • Tests cover this change, or the summary says why they do not
  • New or changed public API has XML documentation

Adds reflection request-builder and JsonLinesContent<T> tests to close the
Codecov patch-coverage gaps on PR #2338:

- FindAsyncJsonLinesElementType: a class implementing IAsyncEnumerable<T> is
  found through GetInterfaces (rather than being that interface itself), and
  a type implementing two distinct IAsyncEnumerable<> interfaces is treated
  as ambiguous and returns null.
- JsonLinesContent<T>.MoveNextAsync: a stream whose FlushAsync throws while
  the producer's next step is still pending propagates the failure only
  after that step completes, so the enumerator is never disposed while it
  is in flight.

Two lines remain uncovered and are genuinely unreachable, not contorted
around:
- JsonLinesContent<T>'s 2-arg SerializeToStreamAsync override: on
  NET8_0_OR_GREATER, HttpContent's internal plumbing always invokes the
  3-arg CancellationToken overload (verified empirically), so the 2-arg
  override is dead code once both are overridden; it only matters on the
  netfx targets that lack the 3-arg overload.
- The closing brace of the catch block in MoveNextAsync: that catch always
  ends with 'throw;', so the sequence point for falling through the catch
  normally can never fire.
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Sep 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.97%. Comparing base (0418743) to head (bb44b10).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2339      +/-   ##
==========================================
+ Coverage   99.93%   99.97%   +0.03%     
==========================================
  Files         217      217              
  Lines       11531    11528       -3     
  Branches     2223     2221       -2     
==========================================
+ Hits        11524    11525       +1     
+ Misses          7        3       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@glennawatson
glennawatson merged commit a463e8a into main Sep 26, 2026
21 checks passed
@glennawatson
glennawatson deleted the test/json-lines-coverage branch September 26, 2026 02:41
@github-actions

Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

⌂ 换网址