Skip to content

Cover send() with a non-http base URL and a reply that has a body - #19

Merged
dmccoystephenson merged 1 commit into
mainfrom
feature/send-failure-path-tests
Oct 18, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
feature/send-failure-path-tests

Conversation

@dmccoystephenson

@dmccoystephenson dmccoystephenson commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Summary

Stage B (unit-test expansion) for send()'s failure paths. Only TraceClientTest.java is changed; production code is untouched.

  • report_aBaseUrlThatIsNotHttpIsLoggedFineAndNeverThrows: the comment in send() says a misconfigured URL surfaces as a RuntimeException, which is why that type is caught alongside IOException. No existing test drove that branch. Two base URLs are now pinned:

    • "not a url" leads to MalformedURLException (the IOException side);
    • "file:///trace-client-test" opens a non-HttpURLConnection, so the cast fails with ClassCastException (the RuntimeException side).

    Each case is asserted to build an enabled client without throwing, to report without throwing, and to log one FINE line starting [trace] could not deliver {... that names the exception.

  • report_drainsAResponseBodyAndKeepsSendingAfterAnError: the shared fixture server always replies with no body, so drain() had only ever seen an empty input stream; its read loop never ran over real content, and never over an error stream. A local server now answers 500 and then 201, each with a 4096-byte body (larger than drain()'s 512-byte buffer). The test checks that:

    • the second report still arrives;
    • exactly one log line is written;
    • that line is [trace] trace server answered 500 for <body>.

Test plan

  • mvn -B verify run locally on Java 21: Tests run: 78, Failures: 0, Errors: 0, Skipped: 0, with both new tests listed in the surefire report
  • CI matrix build (8), build (17), build (21) green on the PR head (Java 8 is the floor; only Java 21 was available locally)

Deferred

No tracking issue: this gap was found during triage by comparing send() against the existing tests.

This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).

🤖 Generated with Claude Code


drafted by Claude on behalf of Daniel Stephenson

send() catches RuntimeException because a misconfigured URL surfaces as
one, but no test drove that path: a file: base URL opens a connection
that is not an HttpURLConnection, and "not a url" is a
MalformedURLException. Both are now pinned as a FINE "could not deliver"
line with the client still enabled. A second test answers 500 and then
201 with bodies larger than drain()'s buffer, and checks the second
report still goes out and only the 500 is logged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric (anchored on CI run 39018406508 on the PR head):

  • Scope: PASS. git diff --name-only origin/main lists only src/test/java/software/stephenson/trace/TraceClientTest.java. No production, README or pom change.
  • Tests-new: PASS (not applicable). No new public method was added. The two new tests both appear in the surefire report (78 run, 0 failed).
  • Tests-fix: not applicable. This is a characterization-only Stage B PR with no bug fix, and both tests assert current behaviour.
  • Sibling structure: PASS. Each test follows the existing report_* conventions:
    • // Arrange / // Act / // Assert sections;
    • a loopback HttpServer on port 0 that is stop(0)-ed;
    • a uniquely named Logger with RecordingHandler;
    • latches rather than sleeps;
    • close() on every client.
  • Sibling renames: not applicable. Nothing was renamed.
  • Docs: PASS. No behaviour changed, so no row of the Phase 7 table moves. The tests pin what the send() comment already says ("a misconfigured URL surfaces as [a RuntimeException]").
  • Issue resolution: not applicable. There is no Closes, and the PR body states that no tracking issue exists.
  • CI: PASS. build (8), build (17) and build (21) are all green.
  • No dependencies / Single file / Java 8: PASS. pom.xml is untouched, src/main is untouched, and the Java 8 leg is green. The test uses only Arrays.fill, CopyOnWriteArrayList and JUnit 5's assertDoesNotThrow(ThrowingSupplier).
  • Never throws / Non-blocking / Environment seam / Version / Opt-out contract: not applicable. No production code changed.

Findings:

  • src/test/java/software/stephenson/trace/TraceClientTest.java (report_aBaseUrlThatIsNotHttpIsLoggedFineAndNeverThrows): the file: case relies on the JDK's file: handler returning a non-HttpURLConnection without doing IO at openConnection(). That holds for JDK 8, 17 and 21 (CI is green on all three), but it is JDK-internal behaviour. If a future JDK changes it, the failure will name this test rather than hide.
  • PR body wording: "the drain() loop ... was never exercised" overstates the gap slightly. On a bodiless 201, drain() is already called with an empty input stream; only a non-empty body, and an error stream that is non-null, were uncovered. The test itself is unaffected.

Summary: a test-only PR, green on the full matrix. No do-not-auto-merge path is touched. Merge is left to a human because this dispatch is not authorized to merge.

This review comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit 2a2b483 into main Oct 18, 2026
3 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