Skip to content

More integration tests#29

Merged
jgeudens merged 4 commits intomasterfrom
dev/tests
Apr 14, 2026
Merged

More integration tests#29
jgeudens merged 4 commits intomasterfrom
dev/tests

Conversation

@jgeudens
Copy link
Copy Markdown
Member

@jgeudens jgeudens commented Apr 14, 2026

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Enhanced error handling for data point validation requests to treat certain errors as non-fatal, allowing sessions to remain active rather than failing at the session level.
  • Tests

    • Added comprehensive integration test coverage for data point features, including validation of required fields, data structure verification, and testing of valid and invalid expressions.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

Warning

Rate limit exceeded

@jgeudens has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 30 minutes and 42 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 30 minutes and 42 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: afe48f7b-509e-4095-8f37-77e35981cb6f

📥 Commits

Reviewing files that changed from the base of the PR and between 840c663 and f0db2fc.

⛔ Files ignored due to path filters (2)
  • adapters/dummymodbusadapter.exe is excluded by !**/*.exe
  • adapters/modbusadapter.exe is excluded by !**/*.exe
📒 Files selected for processing (7)
  • adapters/describe.json
  • adapters/dummymodbusadapter
  • adapters/json-rpc-spec.md
  • adapters/modbusadapter
  • src/ProtocolAdapter/adapterclient.cpp
  • tests/integration/tst_dummyadapter.cpp
  • tests/integration/tst_dummyadapter.h

Walkthrough

AdapterClient error handling updated to treat adapter.validateDataPoint JSON-RPC errors as non-fatal when the request ID matches a pending validation request. Integration tests refactored to use a shared client instance with new test methods covering data-point schema and validation functionality.

Changes

Cohort / File(s) Summary
Error Handling Enhancement
src/ProtocolAdapter/adapterclient.cpp
Modified onErrorReceived to handle adapter.validateDataPoint JSON-RPC errors as auxiliary-request results rather than session-level failures when in AWAITING_CONFIG or ACTIVE states and request ID matches. Removes Q_UNUSED(id) to enable ID verification.
Integration Test Infrastructure
tests/integration/tst_dummyadapter.h, tests/integration/tst_dummyadapter.cpp
Refactored TestDummyAdapter to use a shared _pClient member managed via init()/cleanup() lifecycle methods. Updated all test methods to use _pClient and replaced string literals with QStringLiteral. Renamed describeReturnsRequiredFields() to describeResultHasRequiredFields(). Added four new data-point tests: dataPointSchemaReturnsRequiredFields(), describeDataPointReturnsStructuredFields(), validateDataPointReturnsTrueForValidExpression(), and validateDataPointReturnsFalseForInvalidExpression(). Updated DUMMY_IP to constexpr const char* const.

Possibly related PRs

  • PR #5: Introduces initial error-handling modifications to AdapterClient::onErrorReceived that this PR extends with validateDataPoint-specific logic.
  • PR #26: Adds adapter.validateDataPoint request handling and auxiliary-request ID tracking in AdapterClient, which this PR leverages for error checking.
🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'More integration tests' is vague and generic, providing minimal insight into the specific changes made beyond adding tests. Consider a more descriptive title such as 'Add data point validation integration tests' or 'Add integration tests for data point schema and validation' to better convey the specific purpose of the changes.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev/tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@jgeudens
Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/ProtocolAdapter/adapterclient.cpp`:
- Around line 212-220: The JSON-RPC error handling must ignore stale errors for
overlapping validateDataPoint calls: in the error branch for method ==
"adapter.validateDataPoint" (in adapterclient.cpp) only treat the error as a
validation result when _pendingAuxRequests.value(method, -1) == id (and _state
is AWAITING_CONFIG or ACTIVE); if the stored request id does not match the
incoming id, simply drop/return so the stale error does not fall through to the
session-fatal path. Ensure you remove the pending entry and emit
validateDataPointResult(false, errorMsg) only when the id matches; otherwise do
nothing (mirroring how handleLifecycleResponse ignores late replies).

In `@tests/integration/tst_dummyadapter.cpp`:
- Around line 258-273: The test
TestDummyAdapter::validateDataPointReturnsFalseForInvalidExpression must assert
the session remains non-fatal: after waiting for spyResult, add an assertion
that spyError.count() == 0 to ensure no sessionError was emitted, then send an
additional auxiliary request (e.g., call _pClient->describeAdapter or another
_pClient->validateDataPoint with a valid expression) and wait for its
corresponding QSignalSpy to verify the client stays in AWAITING_CONFIG and
responds normally; reference spies spyError and spyResult and the _pClient
methods to locate where to add these post-response checks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 72a03234-26ea-4027-94c8-bfc17121ed08

📥 Commits

Reviewing files that changed from the base of the PR and between b91feed and 840c663.

⛔ Files ignored due to path filters (2)
  • adapters/dummymodbusadapter.exe is excluded by !**/*.exe
  • adapters/modbusadapter.exe is excluded by !**/*.exe
📒 Files selected for processing (5)
  • adapters/dummymodbusadapter
  • adapters/modbusadapter
  • src/ProtocolAdapter/adapterclient.cpp
  • tests/integration/tst_dummyadapter.cpp
  • tests/integration/tst_dummyadapter.h

Comment on lines +212 to +220
/* For auxiliary requests, a JSON-RPC error is a non-fatal validation result rather
than a session-level failure. Translate to the corresponding result signal. */
if (method == QStringLiteral("adapter.validateDataPoint") &&
(_state == State::AWAITING_CONFIG || _state == State::ACTIVE) && _pendingAuxRequests.value(method, -1) == id)
{
_pendingAuxRequests.remove(method);
emit validateDataPointResult(false, errorMsg);
return;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Ignore stale adapter.validateDataPoint errors instead of escalating them.

If validateDataPoint() is called again before the first reply arrives, the second call overwrites _pendingAuxRequests["adapter.validateDataPoint"]. A late JSON-RPC error from the older request then misses this branch and falls through to the session-fatal path, even though late success responses are already ignored in handleLifecycleResponse(). That makes overlapping validations capable of dropping an otherwise healthy session.

Suggested fix
-    if (method == QStringLiteral("adapter.validateDataPoint") &&
-        (_state == State::AWAITING_CONFIG || _state == State::ACTIVE) && _pendingAuxRequests.value(method, -1) == id)
+    if (method == QStringLiteral("adapter.validateDataPoint") &&
+        (_state == State::AWAITING_CONFIG || _state == State::ACTIVE))
     {
+        if (_pendingAuxRequests.value(method, -1) != id)
+        {
+            qCWarning(scopeComm) << "AdapterClient: ignoring stale error for" << method;
+            return;
+        }
         _pendingAuxRequests.remove(method);
         emit validateDataPointResult(false, errorMsg);
         return;
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/ProtocolAdapter/adapterclient.cpp` around lines 212 - 220, The JSON-RPC
error handling must ignore stale errors for overlapping validateDataPoint calls:
in the error branch for method == "adapter.validateDataPoint" (in
adapterclient.cpp) only treat the error as a validation result when
_pendingAuxRequests.value(method, -1) == id (and _state is AWAITING_CONFIG or
ACTIVE); if the stored request id does not match the incoming id, simply
drop/return so the stale error does not fall through to the session-fatal path.
Ensure you remove the pending entry and emit validateDataPointResult(false,
errorMsg) only when the id matches; otherwise do nothing (mirroring how
handleLifecycleResponse ignores late replies).

jgeudens and others added 4 commits April 14, 2026 21:30
Split the ID-match guard in onErrorReceived so a validateDataPoint error
in the correct state always returns early: emit validateDataPointResult
only when the pending request ID matches, otherwise silently drop the
stale error rather than falling through to the session-fatal path.

Extend the validateDataPointReturnsFalseForInvalidExpression test to
assert spyError stays empty and that a follow-up auxiliary request
succeeds, confirming the client remains operational after a validation
failure.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jgeudens jgeudens merged commit a809af7 into master Apr 14, 2026
10 checks passed
@jgeudens jgeudens deleted the dev/tests branch April 14, 2026 19:49
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