Skip to content

Improve test coverage to 100% functions / 88% lines; automate Windows coverage via OpenCppCoverage - #5

Merged
amoldhamale1105 merged 6 commits into
amoldhamale1105:masterfrom
VipinKum4r:master
Oct 14, 2026
Merged

amoldhamale1105 merged 6 commits into
amoldhamale1105:masterfrom
VipinKum4r:master

Conversation

@VipinKum4r

Copy link
Copy Markdown
Contributor

Improve coverage to 100% functions / ~89% lines and automate Windows coverage report

What this PR does

Builds on the test foundation from #4 to push coverage as high as the library's design permits, and adds automated coverage report generation on Windows via OpenCppCoverage.


Coverage results

Metric Before (#4) After (this PR)
Line coverage 67.5% (154 / 228) 88.6% (202 / 228)
Function coverage 84.8% (39 / 46) 100% (46 / 46) ✅

These are defensive/safety net code paths — their presence is valuable for production robustness even if they cannot be exercised by unit tests.


build.sh changes

The -t flag (test + coverage) now auto-detects the platform:

  • Linux / macOS — existing lcov + genhtml flow (unchanged)
  • Windows (MINGW / MSYS / Cygwin) — uses OpenCppCoverage, producing both an HTML report and a Cobertura XML report suitable for CI

If OpenCppCoverage is not on PATH, the script prints a clear install instruction (winget install OpenCppCoverage) and exits gracefully instead of failing the build.


.gitignore update

Added CoverageReport-*/ to ignore the timestamped report folders OpenCppCoverage generates in the working directory.

Comment thread tests/EventLoopBasicTest.cpp Resolved
Comment thread tests/EventLoopBasicTest.cpp Resolved
Comment thread tests/EventLoopBasicTest.cpp Resolved
Comment thread tests/EventLoopBasicTest.cpp Resolved
Comment thread tests/EventLoopBasicTest.cpp Resolved
Comment thread tests/EventLoopBasicTest.cpp Resolved
Comment thread tests/EventLoopBasicTest.cpp Resolved
Comment thread tests/EventLoopBasicTest.cpp Resolved
Comment thread tests/EventLoopBasicTest.cpp Resolved
Comment thread tests/EventLoopBasicTest.cpp Resolved
VipinKum4r and others added 3 commits October 7, 2026 21:56
Broke the two giant TEST() blocks into individual TEST/TEST_F cases
with proper <func>_test_scenario names. Moved event setup/teardown
into fixtures (SetUp/TearDown, SetUpTestSuite for the shared loop)
instead of building everything inline in one function.

Also added a real assertion that halt happens within its scheduled
delay instead of just waiting up to 300ms and hoping, and made the
DataEvent test actually check the handler fired.

While adding a BLOCK-mode test I hit a real bug: start() would call
std::thread(...) on top of a thread that was still joinable from a
previous run, since Halt() signals shutdown but never joins. Fixed
by joining m_mainLoop/m_scheduler at the top of start() if needed.

Cleaned up the coverage-percentage comments in the test file and
build.sh since that stuff belongs in the coverage report, not code.

Not doing in this PR: the dead-code cleanup in eventLoop() (will be
its own PR) or mocking thread-creation failures for the catch blocks
(needs a factory seam in EventManager, also separate).
OpenCppCoverage rejects forward-slash paths when run from Git Bash. Convert all path arguments with cygpath -w.

Also add the library directory to PATH for the coverage run, since the test exe cannot find EventLoop.dll when run outside ctest (0xC0000135), and exit with an error if coverage generation fails instead of reporting success unconditionally.

@amoldhamale1105 amoldhamale1105 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed commits to fix TSan failures with the new tests and to fix issues related to running tests and generating coverage report on Windows.

@anderewrey Thanks to your TSan CI setup, we were able to catch and fix more race conditions in the implementation. Check my recent commits in this PR.

@amoldhamale1105
amoldhamale1105 merged commit ce1c71e into amoldhamale1105:master Oct 14, 2026
3 checks passed
anderewrey pushed a commit to anderewrey/grpc_reactor_routeguide that referenced this pull request Oct 22, 2026
TSan, against a fully instrumented stack, reported a data race in every
ClientReactorIntegrationTest: EventManager::processEvent() pushed onto
the event queue and notified without holding m_mutex, while eventLoop()
reads and pops that queue under it. A standalone reproducer using only
EventLoop's public API, without gRPC, lost 433 to 553 wakeups per
20 000 events and segfaulted in 5 of 5 plain -O2 runs. The reactors call
TriggerEvent() from gRPC's threads, so the application is exposed too,
not only the tests.

Upstream fixed it in amoldhamale1105/EventLoop#7: processEvent() and
scheduleEvent() push under their loop's mutex, eventLoop() releases it
while handlers run, so a handler calling TriggerEvent() cannot deadlock,
and the shutdown flags are atomic and set under the mutexes.
amoldhamale1105/EventLoop#5 then guarded the receivers' callback map,
another race, and fixed restarting after Halt() and the destructor
order. Pin ce1c71e, which carries both.

The port also declared EventLoop MIT, but its LICENSE and source headers
are LGPL 2.1 or later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019GqSK7yLMgqFy6jBsgiNqG
anderewrey pushed a commit to anderewrey/grpc_reactor_routeguide that referenced this pull request Oct 23, 2026
TSan, against a fully instrumented stack, reported a data race in every
ClientReactorIntegrationTest: EventManager::processEvent() pushed onto
the event queue and notified without holding m_mutex, while eventLoop()
reads and pops that queue under it. A standalone reproducer using only
EventLoop's public API, without gRPC, lost 433 to 553 wakeups per
20 000 events and segfaulted in 5 of 5 plain -O2 runs. The reactors call
TriggerEvent() from gRPC's threads, so the application is exposed too,
not only the tests.

Upstream fixed it in amoldhamale1105/EventLoop#7: processEvent() and
scheduleEvent() push under their loop's mutex, eventLoop() releases it
while handlers run, so a handler calling TriggerEvent() cannot deadlock,
and the shutdown flags are atomic and set under the mutexes.
amoldhamale1105/EventLoop#5 then guarded the receivers' callback map,
another race, and fixed restarting after Halt() and the destructor
order. Pin ce1c71e, which carries both.

The port also declared EventLoop MIT, but its LICENSE and source headers
are LGPL 2.1 or later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019GqSK7yLMgqFy6jBsgiNqG
anderewrey pushed a commit to anderewrey/grpc_reactor_routeguide that referenced this pull request Oct 23, 2026
TSan, against a fully instrumented stack, reported a data race in every
ClientReactorIntegrationTest: EventManager::processEvent() pushed onto
the event queue and notified without holding m_mutex, while eventLoop()
reads and pops that queue under it. A standalone reproducer using only
EventLoop's public API, without gRPC, lost 433 to 553 wakeups per 20 000
events and segfaulted in 5 of 5 plain -O2 runs. The reactors call
TriggerEvent() from gRPC's threads, so the application is exposed too,
not only the tests.

Upstream fixed it in amoldhamale1105/EventLoop#7: processEvent() and
scheduleEvent() push under their loop's mutex, eventLoop() releases it
while handlers run, so a handler calling TriggerEvent() cannot deadlock,
and the shutdown flags are atomic and set under the mutexes.
amoldhamale1105/EventLoop#5 then guarded the receivers' callback map,
another race, and fixed restarting after Halt() and the destructor
order. Pin ce1c71e, which carries both.

The port also declared EventLoop MIT, but its LICENSE and source headers
are LGPL 2.1 or later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019GqSK7yLMgqFy6jBsgiNqG
anderewrey pushed a commit to anderewrey/grpc_reactor_routeguide that referenced this pull request Oct 23, 2026
TSan, against a fully instrumented stack, reported a data race in every
ClientReactorIntegrationTest: EventManager::processEvent() pushed onto
the event queue and notified without holding m_mutex, while eventLoop()
reads and pops that queue under it. A standalone reproducer using only
EventLoop's public API, without gRPC, lost 433 to 553 wakeups per 20 000
events and segfaulted in 5 of 5 plain -O2 runs. The reactors call
TriggerEvent() from gRPC's threads, so the application is exposed too,
not only the tests.

Upstream fixed it in amoldhamale1105/EventLoop#7: processEvent() and
scheduleEvent() push under their loop's mutex, eventLoop() releases it
while handlers run, so a handler calling TriggerEvent() cannot deadlock,
and the shutdown flags are atomic and set under the mutexes.
amoldhamale1105/EventLoop#5 then guarded the receivers' callback map,
another race, and fixed restarting after Halt() and the destructor
order. Pin ce1c71e, which carries both.

The port also declared EventLoop MIT, but its LICENSE and source headers
are LGPL 2.1 or later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019GqSK7yLMgqFy6jBsgiNqG
anderewrey pushed a commit to anderewrey/grpc_reactor_routeguide that referenced this pull request Oct 23, 2026
TSan, against a fully instrumented stack, reported a data race in every
ClientReactorIntegrationTest: EventManager::processEvent() pushed onto
the event queue and notified without holding m_mutex, while eventLoop()
reads and pops that queue under it. A standalone reproducer using only
EventLoop's public API, without gRPC, lost 433 to 553 wakeups per 20 000
events and segfaulted in 5 of 5 plain -O2 runs. The reactors call
TriggerEvent() from gRPC's threads, so the application is exposed too,
not only the tests.

Upstream fixed it in amoldhamale1105/EventLoop#7: processEvent() and
scheduleEvent() push under their loop's mutex, eventLoop() releases it
while handlers run, so a handler calling TriggerEvent() cannot deadlock,
and the shutdown flags are atomic and set under the mutexes.
amoldhamale1105/EventLoop#5 then guarded the receivers' callback map,
another race, and fixed restarting after Halt() and the destructor
order. Pin ce1c71e, which carries both.

The port also declared EventLoop MIT, but its LICENSE and source headers
are LGPL 2.1 or later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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