Skip to content

chore: sweep the error-event assertions onto the shared macros - #789

Merged
DavidCozens merged 2 commits into
feature/tls-reworkfrom
chore/sweep-error-assertions
Aug 22, 2026
Merged

chore: sweep the error-event assertions onto the shared macros#789
DavidCozens merged 2 commits into
feature/tls-reworkfrom
chore/sweep-error-assertions

Conversation

@DavidCozens

@DavidCozens DavidCozens commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Purpose

The follow-up agreed on #788.
CHECK_ERROR_EVENT had sat in Tests/Support/TestUtils.h since it was written
with no call sites, while 136 blocks across 47 files hand-rolled the same four
assertions. #788 gave it the severity axis and a CHECK_ERROR_REPORTED_ONCE
sibling and converted five sites; this converts the rest.

Tests only. No production source is touched.

No Closes keyword: per #782,
intermediate pull requests into feature/tls-rework carry none.

Change Description

122 blocks were mechanical. Count, severity, source, category, detail, in
that order - the same order as the macro's parameters. Converted by script, then
clang-format.

Ten file-local macros wrapped the same block with a fixed source: five copies
of CHECK_REPORTED across the lwIP tests, four of CHECK_REPORTED_ERROR across
the policy tests, and CHECK_STREAMSENDER_BAD_SETUP_ERROR. Each now delegates to
the shared macro instead of restating it, which is what
CHECK_OPEN_UNWOUND_WITH_SEVERITY already did in both stream test files. That is
the part of this worth reviewing: ten near-identical copies were the actual
duplication, not the call sites.

Two sites assert the second of two events, where pinning the count at ONCE
would be wrong. They use CHECK_ERROR_EVENT with their own
CALLED_FAKE(..., TWICE) above it - the case the two macros were split for.

Three sites asserted a subset, and were invisible to a survey anchored on the
source assertion: one without a source, two without a source or a severity. They
now assert all four axes, with the missing values read from the emit site rather
than assumed - BlockStore's WARNING, the POSIX message-queue buffer's
ERROR, and CRITICAL for the UDP sender's null-buffer check, which that file's
own sibling test already asserted. Those five new checks pass, so nothing was
drifting behind the gap.

One assertion stays hand-rolled: SolidSyslogErrorTest also checks
LastContext(), which no shared macro covers, and it sits directly after the
converted block.

It does not shrink the tests

About seventy lines longer, because a four-argument call wraps where five short
assertions did not. What it buys is one assertion shape, a severity axis asserted
everywhere rather than in most places, and one place to change if the event ever
gains a field. Worth saying plainly, since "DRY sweep" implies a smaller diff than
this produces.

Test Evidence

SolidSyslogTests: OK (1496 tests, 1496 ran, 3589 checks, 0 ignored)
ctest:            100% tests passed, 0 tests failed out of 22

3589 checks against 3584 before: the five extra are the axes the three partial
sites had never asserted. The 22 includes both integration suites against the real
libraries, and the lwIP, FreeRTOS, FatFs and PlusFAT suites that the debug
preset in the gcc image does not build - the ten delegated local macros live
mostly in those, so they would otherwise have gone unverified locally.

Whole-tree clang-format --dry-run --Werror clean. No MISRA step: no production
source changed, so no suppression line moved.

Areas Affected

47 files under Tests/, all test-tier. Tests/Support/TestUtils.h is unchanged -
#788 already put both macros there.

Windows test files are converted but not exercised locally; build-windows-msvc
covers them.

Summary by CodeRabbit

  • Tests
    • Standardised error-report verification across platform, networking, storage, security, and messaging test coverage.
    • Continued validating complete error details, including severity, source, category, and diagnostic information.
    • Preserved coverage for pool exhaustion, invalid or stale handle destruction, configuration failures, delivery events, and lifecycle errors.
    • Improved consistency and readability of error-handling checks without changing expected outcomes.
    • Simplified stream reconfiguration scenarios while preserving existing assertions and coverage.

Second commit: one recreate idiom in the OpenSSL stream tests

Added after review discussion. That file carried two ways to swap the config and
rebuild the stream - seven tests hand-rolled Destroy + Create, their
neighbours called ReCreateStreamWithUpdatedConfig() - and the two are not
equivalent, since the helper also rebuilds the transport fake and reinstalls the
error handler. Nothing said which to reach for. The seven now call the helper.

The Destroy calls that remain in test bodies are the seven lifecycle tests where
Destroy is the action under test, plus one that re-creates afterwards so
teardown targets a live slot rather than a stale handle.

Deliberately not extended tree-wide. The hand-rolled form appears in 36 other
test files and is used consistently within each, so those files are already
internally consistent; converting them would need a recreate helper per fixture.
More to the point, seven sites across the tree - in UdpSenderTest,
BlockStoreTest, StreamSenderTest, LwipRawTcpStreamTest and SenderFakeTest -
arrange fake state before recreating. Pointed at a helper that resets on
recreate, those would not fail; they would pass while no longer testing what they
were written to test. That is the reason this stops at the one file that had both
idioms.

CHECK_ERROR_EVENT has been in Tests/Support/TestUtils.h since it was written and
had no call sites, while 136 blocks across 47 files hand-rolled the same four
assertions. #788 gave it the severity axis and a CHECK_ERROR_REPORTED_ONCE
sibling and converted five sites; this converts the rest.

122 blocks were the identical shape - count, severity, source, category, detail,
in that order - and became CHECK_ERROR_REPORTED_ONCE mechanically.

Ten file-local macros wrapped the same block with a fixed source: five copies of
CHECK_REPORTED in the lwIP tests, four of CHECK_REPORTED_ERROR in the policy
tests, and CHECK_STREAMSENDER_BAD_SETUP_ERROR. Each now delegates to the shared
macro rather than restating it, as CHECK_OPEN_UNWOUND_WITH_SEVERITY already does
in both stream test files.

Two sites assert the second of two events, where pinning the count at ONCE would
be wrong. They use CHECK_ERROR_EVENT with their own CALLED_FAKE(..., TWICE) left
above it, which is what the two macros were split for.

Three sites asserted a subset - one without a source, two without a source or a
severity - and were invisible to a survey anchored on the source assertion. They
now assert all four axes, with the missing values read from the emit site rather
than assumed: BlockStore's WARNING, the POSIX message-queue buffer's ERROR, and
CRITICAL for the UDP sender's null-buffer argument check, which its own sibling
test already asserted. Those five new checks pass, so no drift was hiding there.

One assertion is deliberately left hand-rolled: SolidSyslogErrorTest also checks
LastContext(), which no shared macro covers, and it sits after the converted
block.

The sweep does not shrink the test code - it adds about seventy lines, because a
four-argument call wraps where five short assertions did not. What it buys is one
assertion shape, a severity axis asserted everywhere rather than in most places,
and one place to change if the event gains a field.

Tests only; no production source is touched. 1496 unit tests, 3589 checks - five
more than before, being the axes the three partial sites had never asserted - and
22 of 22 suites including both integration lanes.
@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9dc0b694-02bf-4b97-90e6-d156aed1f91b

📥 Commits

Reviewing files that changed from the base of the PR and between a66028e and d1900c4.

📒 Files selected for processing (1)
  • Tests/SolidSyslogOpenSslStreamTest.cpp

Included review availability: 0 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.


Walkthrough

The change replaces repeated ErrorHandlerFake assertions with shared CHECK_ERROR_REPORTED_ONCE, CHECK_ERROR_EVENT, and wrapper macros. OpenSSL stream tests also use a shared recreation helper. Expected error metadata and test coverage remain unchanged.

Changes

Error assertion migration

Layer / File(s) Summary
Assertion macro wrappers
Tests/Lwip/*, Tests/MbedTls/*PolicyTest.cpp, Tests/MbedTls/SolidSyslogMbedTlsStreamTest.cpp, Tests/SolidSyslogOpenSsl*PolicyTest.cpp, Tests/SolidSyslogStreamSenderTest.cpp
Test helper macros now delegate error verification to shared assertion macros.
Pool and handle error tests
Tests/FatFs/*, Tests/FreeRtos/*PoolTest.cpp, Tests/PlusFat/*, Tests/MbedTls/*PoolTest.cpp, Tests/SolidSyslog*PoolTest.cpp, Tests/SolidSyslogPosix*Test.cpp, Tests/SolidSyslogWindows*Test.cpp, Tests/SolidSyslogWinsock*Test.cpp
Pool exhaustion and unknown or stale handle tests now use consolidated error-report assertions.
Core component error tests
Tests/SolidSyslogBlockStoreTest.cpp, Tests/SolidSyslogCircularBufferTest.cpp, Tests/SolidSyslogErrorTest.cpp, Tests/SolidSyslogMetaSdTest.cpp, Tests/SolidSyslogPassthroughBufferTest.cpp, Tests/SolidSyslogTest.cpp, Tests/SolidSyslogTimeQualitySdTest.cpp, Tests/SolidSyslogStreamSenderTest.cpp, Tests/SolidSyslogSwitchingSenderTest.cpp
Core component tests now use structured assertions for configuration, lifecycle, pool, and delivery errors.
Transport and sender error tests
Tests/SolidSyslogPosixMessageQueueBufferTest.cpp, Tests/SolidSyslogUdpSenderTest.cpp
Message-queue and UDP sender tests now use consolidated report and event assertions.
OpenSSL stream recreation
Tests/SolidSyslogOpenSslStreamTest.cpp
Configuration-change tests now use ReCreateStreamWithUpdatedConfig() instead of repeated manual recreation.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to d1900

This PR refactors test assertions and test-local setup helpers without changing production behavior; the supplied tests and formatting checks pass, and no actionable merge-blocking risk remains beyond normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.58% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 189 functions across 48 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change and follows the required Conventional Commits format.
Description check ✅ Passed The description covers purpose, changes, test evidence, affected areas, issue references, and scope limitations.
Linked Issues check ✅ Passed The description references issues #788 and #782 and explains why no closing keyword is used.
Out of Scope Changes check ✅ Passed The changes match the stated test-only scope, with no production source or public declarations modified.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/sweep-error-assertions

Comment @coderabbitai help to get the list of available commands.

The file carried two ways to swap the config and rebuild the stream: seven tests
hand-rolled Destroy + Create, while their neighbours called
ReCreateStreamWithUpdatedConfig. The two are not equivalent - the helper also
rebuilds the transport fake and reinstalls the error handler, so counts start from
the recreate - and nothing in the file said which to reach for. The seven now call
the helper.

All seven were the same arrange shape: destroy, set one config field, create. None
arranged fake state before recreating, which is what would have changed meaning
rather than failing; CipherListFailureFreesCtx forces its fake after the create,
which is the order the helper requires and already had.

The remaining Destroy calls in test bodies stay. In all seven of those, Destroy is
the action under test - freeing the SSL, the BIO method, the context, closing a
still-open transport - and one re-creates afterwards so teardown targets a live
slot rather than a stale handle.

This is scoped to the one file that had both idioms. The hand-rolled form is used
in 36 other test files, consistently within each, and converting those would need
a helper per fixture and individual judgement at the seven sites tree-wide that do
arrange fakes first.

1496 unit tests, 3589 checks, 22 of 22 suites.
@github-actions

Copy link
Copy Markdown
Contributor

☀️   Quality Summary

   JUnit   build-linux-gcc (Whole Project): ✅ successful — 1530 passed
   JUnit   build-freertos-host-tdd-plustcp (Whole Project): ✅ successful — 1885 passed
   JUnit   build-linux-clang (Whole Project): ✅ successful — 1461 passed
   JUnit   sanitize-linux-gcc (Whole Project): ✅ successful — 1461 passed
   JUnit   integration-linux-openssl (Whole Project): ✅ successful — 16 passed
   JUnit   integration-linux-mbedtls (Whole Project): ✅ successful — 14 passed
   JUnit   integration-windows-openssl (Whole Project): ✅ successful — 16 passed
   JUnit   bdd-linux-syslog-ng (Whole Project): ✅ successful — 49 passed, 3 skipped
   JUnit   bdd-windows-otel (Whole Project): ✅ successful — 46 passed, 6 skipped
   JUnit   bdd-freertos-qemu-plustcp (Whole Project): ✅ successful — 45 passed, 7 skipped
   JUnit   bdd-freertos-qemu-lwip (Whole Project): ✅ successful — 45 passed, 7 skipped
   JUnit   build-windows-msvc (Whole Project): ✅ successful — 1303 passed
   JUnit   build-linux-tunable-override (Whole Project): ✅ successful — 1461 passed
   ⚠️   Clang-Tidy (Whole Project): No warnings
   ⚠️   CPPCheck (Whole Project): No warnings


Created by Quality Monitor v4.15.0 (#82d77af). More details are shown in the GitHub Checks Result.

@DavidCozens
DavidCozens merged commit 21cb9ab into feature/tls-rework Aug 22, 2026
37 checks passed
@DavidCozens
DavidCozens deleted the chore/sweep-error-assertions branch August 22, 2026 21:58
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