test: strengthen coverage for error handling, status codes, assertions, and metrics#351
Conversation
|
|
|
Warning Review limit reached
More reviews will be available in 27 minutes and 49 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
This PR expands and clarifies the SDK’s automated test coverage around user-facing error formatting/classification, HTTP status classification (including retry semantics), client assertion model conversion, and telemetry metric caching/delegation, while also removing misleading comments in an existing retry strategy test.
Changes:
- Added new unit tests for
FgaErrormessage formatting and helper predicates, plusHttpStatusCodeboundary/retry behavior. - Added new unit tests for
ClientAssertionconversion helpers (asAssertion,asAssertions). - Strengthened
MetricsTestassertions around instrument caching and convenience-method delegation; removed misleading comments fromRetryStrategyTest.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/test/java/dev/openfga/sdk/util/RetryStrategyTest.java | Removes misleading comments from retry-delay tests without altering behavior. |
| src/test/java/dev/openfga/sdk/telemetry/MetricsTest.java | Adds identity assertions to verify metric instrument caching and delegation behavior. |
| src/test/java/dev/openfga/sdk/errors/HttpStatusCodeTest.java | Adds parameterized boundary and retryability tests for HTTP status classification. |
| src/test/java/dev/openfga/sdk/errors/FgaErrorTest.java | Adds coverage for formatted error messages and error classification helpers. |
| src/test/java/dev/openfga/sdk/api/client/ClientAssertionTest.java | Adds conversion/round-trip tests for client assertion helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1469ad0 to
0cca4f8
Compare
- Add FgaErrorTest covering getMessage() format variants and all helper methods (isRetryable, isClientError, isServerError, etc.) - Add HttpStatusCodeTest with boundary parameterized tests for isSuccessful, isServerError, and isRetryable including 501 exclusion - Add ClientAssertionTest covering asAssertion() and asAssertions() including null and empty list cases - Upgrade MetricsTest existence assertions to verify caching and delegation (credentialsRequest, requestDuration, queryDuration) - Remove stale "Current code will FAIL" comments in RetryStrategyTest
0cca4f8 to
5f541f8
Compare
|
/easycla |
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project status has failed because the head coverage (38.69%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #351 +/- ##
============================================
+ Coverage 38.47% 38.69% +0.22%
- Complexity 1267 1289 +22
============================================
Files 198 198
Lines 7704 7704
Branches 900 900
============================================
+ Hits 2964 2981 +17
+ Misses 4591 4576 -15
+ Partials 149 147 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
This PR improves test coverage across several areas of the SDK, focusing on correctness guarantees for user-facing contracts and behavioral verification of internal routing logic.
FgaErrorTest(new)FgaError.getMessage()produces the formatted message that SDK consumers see when catching errors — e.g.[write] HTTP 400 type not found (validation_error) [request-id: abc-123]. This method has several conditional paths (missing operation name, missing error code, missing request ID) that were previously unverified. The new tests cover:isValidationError(),isUnknownError(),isRateLimitError(),isRetryable(),isClientError(),isServerError()HttpStatusCodeTest(new)HttpStatusCodedrives retry decisions and error classification throughout the SDK. Boundary conditions at 200/300/500/600 and the deliberate501 NOT_IMPLEMENTEDexclusion from retries are now explicitly tested via parameterized tests, making off-by-one regressions immediately visible.ClientAssertionTest(new)ClientAssertion.asAssertion()andasAssertions()convert client-layer models to API models used inwriteAssertions. Tests cover full field round-trip, false expectation, null input, empty list, and multi-item conversion with order preservation.MetricsTest(updated)The existing counter and histogram tests verified only that a non-null instrument was returned. They now additionally assert that:
ConcurrentHashMapis exercised)credentialsRequest(),requestDuration(),queryDuration()) delegate to the correct underlying metric, confirmed via instance identityRetryStrategyTest(updated)Removed three comments that incorrectly described the current implementation as failing its own tests. The tests themselves are correct and the code passes them — the comments were a readability hazard that could prompt unnecessary investigation or cause someone to revert correct behavior.
Test plan
./gradlew test)