Skip to content

Test the Logger's promises: throwing, reporting, silent after close - #13

Merged
dmccoystephenson merged 2 commits into
mainfrom
feature/logger-promise-tests
Oct 21, 2026
Merged

dmccoystephenson merged 2 commits into
mainfrom
feature/logger-promise-tests

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Stage B — unit-test expansion (the Logger's promises).

Summary

  • The README promise table and the header comments make three claims about the optional Logger that no test checked. This PR adds tests for them; production code is unchanged:
    • aLoggerThatThrowsDoesNotStopTheSendingThread: with every report answered 500, a logger that throws on each call still sees all three reports delivered and logged (Shared::log's catch (...)).
    • aLoggerMayItselfReport: a report issued from inside the logger, which runs on the sending thread, is queued and sent like any other and does not deadlock (the logMutex comment in Shared).
    • theLoggerIsNeverCalledOnceCloseReturns: when close(0.5) gives up on an in-flight request, the sending thread is left to finish on its own, and the logger hears nothing more once close() has returned (README: "Once close() returns, the Logger is never called again").
  • All three are registered in main()'s tests[] table. <stdexcept> was added to the test's includes for std::runtime_error.

Test plan

  • make test (g++, C++11): 53 tests, 0 failed checks (up from 50), run twice.
  • make test STD=c++17: 53 tests, 0 failed checks.
  • Mutation check: with shared->forgetLogger() removed from close(), theLoggerIsNeverCalledOnceCloseReturns fails (expected [0] got [1]).
  • Mutation check: with Shared::log's catch (...) narrowed to catch (int), the suite aborts in aLoggerThatThrowsDoesNotStopTheSendingThread (terminate called after throwing an instance of 'std::runtime_error').
  • CI: linux, linux-libcurl, linux-sanitizers (thread; address,undefined), macos, windows. The sandbox did not allow sanitizer builds locally, so the TSan/ASan coverage of the new threaded tests comes from CI alone.

No tracking issue: the gap was found during triage, by checking each README promise against test/test_trace_client.cpp.

Deferred

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

Three behaviours the header promises about the Logger had no test: a
logger that throws does not stop the sending thread, a logger may itself
call report(), and once close() returns the logger is never called
again, even by a sending thread close() gave up on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ThreadSanitizer found that a report() from inside the logger races with
close() on TraceClient::shared_ (#14). The test now hands control back
to the main thread before closing, so it checks only that a logger may
report, and leaves the race to its own issue.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric (head 2nd commit, CI run 39592754832):

  • Scope: PASS. Only test/test_trace_client.cpp changed (+68, 0 deletions). That covers three tests, their tests[] rows and #include <stdexcept>.
  • Tests-new: PASS (N/A). No new public method or function was added.
  • Tests-fix: N/A. This is not a bug fix. The tests were still mutation-checked against production code: removing forgetLogger() from close() makes theLoggerIsNeverCalledOnceCloseReturns fail, and narrowing Shared::log's catch (...) aborts the suite in aLoggerThatThrowsDoesNotStopTheSendingThread.
  • Sibling structure: PASS. These are static void sentence-named tests using StubServer, Log and CHECK/CHECK_EQ, the same as their neighbours.
  • Sibling renames: PASS (N/A). Nothing was renamed.
  • Docs: PASS. No behaviour changed. The logMutex comment ("a logger may itself call report()") turned out to be only partly true, and that is tracked in report() from inside the Logger races with close() on TraceClient::shared_ #14 rather than edited under a test-only PR.
  • Issue resolution: PASS (N/A). This PR has no Closes.
  • CI: PASS. All 12 jobs are green on the head. The linux-sanitizers (thread) log shows 53 tests, 0 failed checks and no TSan warning.
  • Registered: PASS. Each new name appears twice: its definition and its tests[] row. The count went from 50 to 53 locally and in CI.
  • C++11: PASS. make test (-std=c++11 -Wall -Wextra -pedantic -Werror) is clean locally, and the c++11 legs are green.
  • No new dependency: PASS. The only new include is <stdexcept>, in the test file. Makefile and CMakeLists.txt are untouched.
  • Never throws / Curl argv fixed / Version triple: PASS (N/A). trace_client.hpp is untouched.
  • Sanitizers: PASS, after one fix. The first CI run went red in linux-sanitizers (thread): TSan found a real data race between a report() called from inside the logger and close() on TraceClient::shared_ (trace_client.hpp:1040 vs :1139). The address,undefined leg on that run was only cancelled by fail-fast; its test step had succeeded. The production race is filed as report() from inside the Logger races with close() on TraceClient::shared_ #14. Under the characterization-only rule, the test now waits for the logger's report() to return before close().

Judgment calls:

  • test/test_trace_client.cpp aLoggerMayItselfReport: there is no mutation evidence for this test, because no cheap production change brings back the deadlock it guards against. It locks in today's behaviour only. Its handshake also means it does not cover the report() from inside the Logger races with close() on TraceClient::shared_ #14 case, by design.
  • test/test_trace_client.cpp theLoggerIsNeverCalledOnceCloseReturns: it sleeps 500 ms after release() to give the abandoned thread time to try logging. If the machine is slow, the test could pass without exercising that path. The mutation check shows it does exercise it on a normal runner.
  • The PR body's checklist leaves CI unticked because it was written before CI ran. CI has since gone green, as recorded above.

Verdict: ready to merge. This PR touches tests only and matches no do-not-auto-merge path.

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 a5104da into main Oct 21, 2026
11 checks passed
@dmccoystephenson
dmccoystephenson deleted the feature/logger-promise-tests branch October 21, 2026 11:34
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